IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 21, 2005, 5:33:37 PM (20 years ago)
Author:
eugene
Message:

reorg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/psModUtils.c

    r5560 r5565  
    11# include "psastro.h"
    22
    3 // these functions temporarily replace existing psModules code
     3psPlane *psCoordReadoutToCell (psPlane *cellpix, psPlane *readpix, pmReadout *readout) {
    44
    5 // template sample alloc/free pair:
    6 # if (0)
    7 static void psFooFree (psFoo *foo) {
     5    if (cellpix == NULL) {
     6        cellpix = psPlaneAlloc ();
     7    }
    88
    9   if (foo == NULL) return;
    10   return;
    11 }
    12 psFoo *psFooAlloc (int i1, int i2) {
     9    cellpix->x = readpix->x*readout->colBins + readout->col0;
     10    cellpix->y = readpix->y*readout->rowBins + readout->row0;
    1311
    14   psFoo *foo = psAlloc (sizeof(psFoo));
    15   psMemSetDeallocator(foo, (psFreeFunc) psFooFree);
    16 
    17   return (foo);
    18 }
    19 # endif
    20 
    21 // pmFPA
    22 static void pmFPAFree (pmFPA *fpa) {
    23 
    24   if (fpa == NULL) return;
    25 
    26   psFree (fpa->toSky);
    27   psFree (fpa->toTPA);
    28   psFree (fpa->fromTPA);
    29   psFree (fpa->chips);
    30 
    31   return;
     12    return (cellpix);
    3213}
    3314
    34 pmFPA *pmFPAAlloc (void) {
     15psPlane *psCoordCellToReadout (psPlane *readpix, psPlane *cellpix, pmReadout *readout) {
    3516
    36   pmFPA *fpa = psAlloc (sizeof(pmFPA));
    37   psMemSetDeallocator(fpa, (psFreeFunc) pmFPAFree);
     17    if (readpix == NULL) {
     18        readpix = psPlaneAlloc ();
     19    }
    3820
    39   fpa->toSky   = NULL;
    40   fpa->toTPA   = NULL;
    41   fpa->fromTPA = NULL;
    42   fpa->chips   = NULL;
     21    readpix->x = (cellpix->x - readout->col0) / readout->colBins;
     22    readpix->y = (cellpix->y - readout->row0) / readout->rowBins;
    4323
    44   return (fpa);
     24    return (readpix);
    4525}
    4626
    47 // pmChip
    48 static void pmChipFree (pmChip *chip) {
     27psPlane* psCoordChipToCell_EAM(psPlane* cellCoord,
     28                               const psPlane* chipCoord,
     29                               const pmCell* cell)
     30{
     31    PS_ASSERT_PTR_NON_NULL(chipCoord, NULL);
     32    PS_ASSERT_PTR_NON_NULL(cell, NULL);
     33    PS_ASSERT_PTR_NON_NULL(cell->parent, NULL);
    4934
    50   if (chip == NULL) return;
    51 
    52   psFree (chip->toFPA);
    53   psFree (chip->fromFPA);
    54   psFree (chip->cells);
    55 
    56   return;
     35    // XXX EAM : why was this being done?
     36    // pmCell *tmpCell = pmCellInChip(chipCoord, cell->parent);
     37    PS_ASSERT_PTR_NON_NULL(cell->toChip, NULL);
     38    psPlaneTransform *tmpChipToCell = p_psPlaneTransformLinearInvert(cell->toChip);
     39    PS_ASSERT_PTR_NON_NULL(tmpChipToCell, NULL);
     40    cellCoord = psPlaneTransformApply(cellCoord, tmpChipToCell, chipCoord);
     41    psFree(tmpChipToCell);
     42    return(cellCoord);
    5743}
    5844
    59 pmChip *pmChipAlloc (void) {
     45bool psastroProjectFPA (pmFPA *fpa, char *starlist, bool toSky) {
    6046
    61   pmChip *chip = psAlloc (sizeof(pmChip));
    62   psMemSetDeallocator(chip, (psFreeFunc) pmChipFree);
     47    bool status;
    6348
    64   chip->toFPA   = NULL;
    65   chip->fromFPA = NULL;
    66   chip->cells   = NULL;
     49    for (int i = 0; i < fpa->chips->n; i++) {
     50        pmChip *chip = fpa->chips->data[i];
     51        for (int j = 0; j < chip->cells->n; j++) {
     52            pmCell *cell = chip->cells->data[j];
     53            for (int k = 0; k < cell->readouts->n; k++) {
     54                pmReadout *readout = cell->readouts->data[k];
     55                psArray *stars = psMetadataLookupPtr (&status, readout->analysis, starlist);
     56                if (toSky) {
     57                    psastroProjectRawstars (stars, readout);
     58                } else {
     59                    psastroProjectRefstars (stars, readout);
     60                }
     61            }
     62        }
     63    }
     64    return true;
     65}
     66 
     67bool psastroProjectRawstars (psArray *stars, pmReadout *readout) {
    6768
    68   return (chip);
     69    pmCell *cell = readout->parent;
     70    pmChip *chip = cell->parent;
     71    pmFPA  *fpa  = chip->parent;
     72
     73    for (int i = 0; i < stars->n; i++) {
     74        pmAstromObj *star = stars->data[i];
     75        psCoordReadoutToCell (&star->cell, &star->pix, readout);
     76        psCoordCellToChip (&star->chip, &star->cell, cell);
     77        psCoordChipToFPA (&star->FP, &star->chip, chip);
     78        psCoordFPAToTP (&star->TP, &star->FP, 0.0, 0.0, fpa);
     79        psCoordTPToSky (&star->sky, &star->TP, fpa->projection);
     80    }
     81    return true;
     82}
     83 
     84bool psastroProjectRefstars (psArray *stars, pmReadout *readout) {
     85
     86    pmCell *cell = readout->parent;
     87    pmChip *chip = cell->parent;
     88    pmFPA  *fpa  = chip->parent;
     89
     90    for (int i = 0; i < stars->n; i++) {
     91        pmAstromObj *star = stars->data[i];
     92        psCoordSkyToTP (&star->TP, &star->sky, fpa->projection);
     93        psCoordTPToFPA (&star->FP, &star->TP, 0.0, 0.0, fpa);
     94        psCoordFPAToChip (&star->chip, &star->FP, chip);
     95        psCoordChipToCell_EAM (&star->cell, &star->chip, cell);
     96        psCoordCellToReadout (&star->pix, &star->cell, readout);
     97    }
     98    return true;
     99}
     100 
     101pmFPA *pmFPACopyAstrom (pmFPA *inFPA) {
     102
     103    pmFPA *fpa = pmFPAAlloc (NULL, NULL);
     104
     105    // copy FPA astrometry data
     106    fpa->toSky   = psProjectionCopy (inFPA->toSky);
     107    fpa->toTPA   = psPlaneDistortCopy (inFPA->toTPA);
     108    fpa->fromTPA = psPlaneDistortCopy (inFPA->fromTPA);
     109
     110    psArrayRealloc (fpa->chips, inFPA->chips->n);
     111    for (int i = 0; i < inFPA->chips->n; i++) {
     112        pmChip *inChip = inFPA->chips->data[i];
     113        pmChip *chip = pmChipAlloc (fpa);
     114
     115        // copy Chip astrometry data
     116        chip->toFPA = psPlaneTransformCopy (inChip->toFPA);
     117        chip->fromFPA = psPlaneTransformCopy (inChip->fromFPA);
     118
     119        psArrayRealloc (chip->cells, inChip->cells->n);
     120        for (int j = 0; j < inChip->cells->n; j++) {
     121            pmCell *inCell = inChip->cells->data[j];
     122            pmCell *cell = pmCellAlloc (chip);
     123
     124            // cell.header is a view on inCell.header
     125            cell->header = psMemCopy (inCell->header);
     126
     127            // copy Cell astrometry data
     128            cell->toChip = psPlaneTransformCopy (inCell->toChip);
     129
     130            psArrayRealloc (cell->readouts, inCell->readouts->n);
     131            for (int k = 0; k < inCell->readouts->n; k++) {
     132                pmReadout *inReadout = inCell->readouts->data[k];
     133                pmReadout *readout = pmReadoutAlloc (cell);
     134
     135                // copy Readout data
     136                *readout = *inReadout;
     137
     138                cell->readouts->data[k] = readout;
     139            }
     140            chip->cells->data[j] = cell;
     141        }
     142        fpa->chips->data[i] = chip;
     143    }
     144    return (fpa);
    69145}
    70146
    71 // pmCell
    72 static void pmCellFree (pmCell *cell) {
    73 
    74   if (cell == NULL) return;
    75 
    76   psFree (cell->toChip);
    77   psFree (cell->readouts);
    78 
    79   return;
    80 }
    81 
    82 pmCell *pmCellAlloc (void) {
    83 
    84   pmCell *cell = psAlloc (sizeof(pmCell));
    85   psMemSetDeallocator(cell, (psFreeFunc) pmCellFree);
    86 
    87   cell->toChip   = NULL;
    88   cell->readouts = NULL;
    89 
    90   return (cell);
    91 }
    92 
    93 // pmReadout
    94 static void pmReadoutFree (pmReadout *readout) {
    95 
    96   if (readout == NULL) return;
    97 
    98   psFree (readout->stars);
    99 
    100   return;
    101 }
    102 
    103 pmReadout *pmReadoutAlloc (void) {
    104 
    105   pmReadout *readout = psAlloc (sizeof(pmReadout));
    106   psMemSetDeallocator(readout, (psFreeFunc) pmReadoutFree);
    107 
    108   readout->col0 = 0;
    109   readout->row0 = 0;
    110   readout->colBins = 1;
    111   readout->rowBins = 1;
    112   readout->stars = NULL;
    113 
    114   return (readout);
    115 }
    116 
Note: See TracChangeset for help on using the changeset viewer.