IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12536


Ignore:
Timestamp:
Mar 21, 2007, 9:30:37 PM (19 years ago)
Author:
eugene
Message:

update to new psAstromWCS APIs; drop old files, old functions from psastroUtils.c

Location:
trunk/psastro/src
Files:
2 deleted
4 edited

Legend:

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

    r12492 r12536  
    4747    pmFPA *fpa = input->fpa;
    4848
     49    // load mosaic-level astrometry?
     50    bool bilevelAstrometry = false;
     51    pmHDU *phu = pmFPAviewThisPHU (view, fpa);
     52    if (phu) {
     53      char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
     54      if (ctype) {
     55        bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
     56      }
     57    }
     58    if (bilevelAstrometry) {
     59      pmAstromReadBilevelMosaic (fpa, phu->header);
     60    }
     61
    4962    while ((chip = pmFPAviewNextChip (view, fpa, 1)) != NULL) {
    5063        psTrace ("psastro", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
     
    5366        // read WCS data from the corresponding header
    5467        pmHDU *hdu = pmFPAviewThisHDU (view, fpa);
     68        if (bilevelAstrometry) {
     69          pmAstromReadBilevelChip (chip, hdu->header);
     70        } else {
     71          pmAstromReadWCS (fpa, chip, hdu->header, pixelScale);
     72        }
    5573
    56         pmAstromReadWCS (fpa, chip, hdu->header, pixelScale);
    5774        if (newFPA) {
    5875            newFPA = false;
  • trunk/psastro/src/psastroLoadRefstars.c

    r12492 r12536  
    8383
    8484    unlink (tempFile);
     85
     86    if (table == NULL) {
     87        psError(PSASTRO_ERR_REFSTARS, true, "failure to load astrometric reference\n");
     88        return NULL;
     89    }
     90
    8591    psLogMsg ("psastro", 3, "read getstar output table : %f sec\n", psTimerMark ("psastro"));
    8692
  • trunk/psastro/src/psastroMosaicAstrom.c

    r12492 r12536  
    44// XXX require this fpa to have multiple chip extensions and a PHU?
    55bool psastroMosaicAstrom (pmConfig *config, psArray *refs) {
    6 
    7     bool status;
    86
    97    // select the current recipe
     
    1311        return false;
    1412    }
    15 
    16     // physical pixel scale in microns per pixel
    17     double pixelScale = psMetadataLookupF32 (&status, recipe, "PSASTRO.PIXEL.SCALE");
    18     if (!status) {
    19         psError(PS_ERR_IO, false, "Failed to lookup pixel scale");
    20         return false;
    21     }
    2213
    2314    // select the input data sources
     
    10192    if (psTraceGetLevel("psastro.dump") > 0) { psastroDumpMatches (fpa, "match.6.dat"); }
    10293
    103     // save WCS and analysis metadata in update header XXX this is still wrong: the pmFPAExtent
    104     // function returns the FP dimensions in pixel units relative to the 0,0 corner of chip
    105     // 0,0.  I need to have a function which loops over all cells, determines the pixel
    106     // dimensions for each cell, converts them to chip pixels, then uses the fpa astrometry
    107     // structures to get the total dimensions of the fpa in fpa units.  equivalent to
    108     // pmFPAExtent
    109     psRegion *region = pmFPAExtent (fpa);
    110     region->x0 *= pixelScale;
    111     region->x1 *= pixelScale;
    112     region->y0 *= pixelScale;
    113     region->y1 *= pixelScale;
    114 
    115     // XXX also need to add DATE/TIME info and NAXIS1, NAXIS2
     94    // save WCS and analysis metadata in update header.
    11695    psMetadata *updates = psMetadataAlloc();
    117     psMetadataAddS32 (updates, PS_LIST_TAIL, "NAXIS1",   PS_META_REPLACE, "fpa dimensions (mm)", region->x1 - region->x0);
    118     psMetadataAddS32 (updates, PS_LIST_TAIL, "NAXIS2",   PS_META_REPLACE, "fpa dimensions (mm)", region->y1 - region->y0);
    119     psFree (region);
    120    
    12196    if (!pmAstromWriteBilevelMosaic (updates, fpa, NONLIN_TOL)) {
    12297        psAbort ("failed to save header terms");
  • trunk/psastro/src/psastroUtils.c

    r12492 r12536  
    7979bool psastroUpdateChipToFPA (pmFPA *fpa, pmChip *chip, psArray *rawstars, psArray *refstars) {
    8080
    81     psRegion *region = pmChipExtent (chip);
    82     region->x1 -= region->x0;
    83     region->y1 -= region->y0;
    84     region->x0 = 0;
    85     region->y0 = 0;
     81    psRegion *region = pmChipPixels (chip);
     82
    8683    psFree (chip->fromFPA);
    87     chip->fromFPA = psPlaneTransformInvert (NULL, chip->toFPA, *region, 20);
     84    chip->fromFPA = psPlaneTransformInvert (NULL, chip->toFPA, *region, 50);
    8885    psFree (region);
    8986
     
    134131    }
    135132    return true;
    136 }
    137 
    138 bool psastroNormFPA (pmFPA *fpa, psMetadata *config) {
    139 
    140     // save the raw astrometry for later reference
    141     pmFPA *raw = pmFPACopyAstrom (fpa);
    142 
    143     // first pass: measure the per-chip solutions, modify the chip.toFPA terms
    144     for (int i = 0; i < fpa->chips->n; i++) {
    145         pmChip *chip = fpa->chips->data[i];
    146         psastroChipAstrom (chip, config);
    147     }
    148 
    149     // second stage: re-normalize the chip terms, passing the
    150     // average rotation and offset values to the fpa.toSky
    151     if (RENORM) {
    152 
    153         // this code is needed for the mosastro stage, with multiple chip solutions
    154 
    155         double dX, dY, dT, dN;
    156         dX = dY = dT = dN = 0;
    157 
    158         psPlane origin, P1, P2;
    159         origin.x = 0;
    160         origin.y = 0;
    161 
    162         // calculate the average rotation and boresite offset relative to raw
    163         for (int i = 0; i < fpa->chips->n; i++) {
    164             pmChip *iChip = raw->chips->data[i];
    165             pmChip *oChip = fpa->chips->data[i];
    166 
    167             // offset of chip
    168             psCoordChipToFPA (&P1, &origin, iChip);
    169             psCoordChipToFPA (&P2, &origin, oChip);
    170             dX += (P2.x - P1.x);
    171             dY += (P2.y - P1.y);
    172 
    173             // get parity-independent rotations for old and new solutions
    174             double T1 = psPlaneTransformGetRotation (iChip->toFPA);
    175             double T2 = psPlaneTransformGetRotation (oChip->toFPA);
    176             dT += T2 - T1;
    177             dN ++;
    178         }
    179 
    180         dT /= dN;
    181         dX /= dN;
    182         dY /= dN;
    183 
    184         // R(T)
    185         double PC1_1 = fpa->toTPA->x->coeff[1][0][0][0];
    186         double PC1_2 = fpa->toTPA->x->coeff[0][1][0][0];
    187         double PC2_1 = fpa->toTPA->y->coeff[1][0][0][0];
    188         double PC2_2 = fpa->toTPA->y->coeff[0][1][0][0];
    189 
    190         // R(dT)
    191         double dPC1_1 = +cos (dT);
    192         double dPC1_2 = +sin (dT);
    193         double dPC2_1 = -sin (dT);
    194         double dPC2_2 = +cos (dT);
    195 
    196         // R'(T) = R(T) * R(dT)
    197         double pc1_1 = PC1_1*dPC1_1 + PC1_2*dPC2_1;
    198         double pc1_2 = PC1_1*dPC1_2 + PC1_2*dPC2_2;
    199         double pc2_1 = PC2_1*dPC1_1 + PC2_2*dPC2_1;
    200         double pc2_2 = PC2_1*dPC1_2 + PC2_2*dPC2_2;
    201 
    202         double det = 1.0 / (pc1_1*pc2_2 - pc1_2*pc2_1);
    203 
    204         // R'(-T)  (matrix inverse, not just rotation inverse -- keeps parity)
    205         double pi1_1 = +pc2_2 * det;
    206         double pi1_2 = -pc1_2 * det;
    207         double pi2_1 = -pc2_1 * det;
    208         double pi2_2 = +pc1_1 * det;
    209 
    210         // apply the new modifcations in rotation and boresite
    211         for (int i = 0; i < fpa->chips->n; i++) {
    212             pmChip *oChip = fpa->chips->data[i];
    213 
    214             // r(T)
    215             double pr1_1 = oChip->toFPA->x->coeff[1][0];
    216             double pr1_2 = oChip->toFPA->x->coeff[0][1];
    217             double pr2_1 = oChip->toFPA->y->coeff[1][0];
    218             double pr2_2 = oChip->toFPA->y->coeff[0][1];
    219 
    220             // ri'(T) = R(T) r(t)
    221             double ri1_1 = PC1_1*pr1_1 + PC1_2*pr2_1;
    222             double ri1_2 = PC1_1*pr1_2 + PC1_2*pr2_2;
    223             double ri2_1 = PC2_1*pr1_1 + PC2_2*pr2_1;
    224             double ri2_2 = PC2_1*pr1_2 + PC2_2*pr2_2;
    225 
    226             // r'(T) = R'(-T) ri'(T)
    227             oChip->toFPA->x->coeff[1][0] = pi1_1*ri1_1 + pi1_2*ri2_1;
    228             oChip->toFPA->x->coeff[0][1] = pi1_1*ri1_2 + pi1_2*ri2_2;
    229             oChip->toFPA->y->coeff[1][0] = pi2_1*ri1_1 + pi2_2*ri2_1;
    230             oChip->toFPA->y->coeff[0][1] = pi2_1*ri1_2 + pi2_2*ri2_2;
    231 
    232             double dx = PC1_1*oChip->toFPA->x->coeff[0][0] + PC1_2*oChip->toFPA->y->coeff[0][0] + dX;
    233             double dy = PC2_1*oChip->toFPA->x->coeff[0][0] + PC2_2*oChip->toFPA->y->coeff[0][0] + dY;
    234 
    235             oChip->toFPA->x->coeff[0][0] = pi1_1*dx + pi1_2*dy;
    236             oChip->toFPA->y->coeff[0][0] = pi2_1*dx + pi2_2*dy;
    237         }
    238 
    239         fpa->toTPA->x->coeff[0][0][0][0] -= dX;
    240         fpa->toTPA->y->coeff[0][0][0][0] -= dY;
    241 
    242         fpa->toTPA->x->coeff[1][0][0][0] = pc1_1;
    243         fpa->toTPA->x->coeff[0][1][0][0] = pc1_2;
    244         fpa->toTPA->y->coeff[1][0][0][0] = pc2_1;
    245         fpa->toTPA->y->coeff[0][1][0][0] = pc2_2;
    246     }
    247     return true;
    248 }
    249 
    250 psPolynomial2D *psPolynomial2DCopy (psPolynomial2D *input) {
    251 
    252     psPolynomial2D *output = psPolynomial2DAlloc (input->nX, input->nY, input->type);
    253 
    254     for (int i = 0; i < input->nX; i++) {
    255         for (int j = 0; j < input->nY; j++) {
    256             output->mask[i][j]     = input->mask[i][j];
    257             output->coeff[i][j]    = input->coeff[i][j];
    258             output->coeffErr[i][j] = input->coeffErr[i][j];
    259         }
    260     }
    261     return (output);
    262 }
    263 
    264 psPolynomial4D *psPolynomial4DCopy (psPolynomial4D *input) {
    265 
    266     psPolynomial4D *output = psPolynomial4DAlloc (input->nX, input->nY, input->nZ, input->nT, input->type);
    267 
    268     for (int i = 0; i < input->nX; i++) {
    269         for (int j = 0; j < input->nY; j++) {
    270             for (int k = 0; k < input->nZ; k++) {
    271                 for (int m = 0; m < input->nT; m++) {
    272                     output->mask[i][j][k][m]     = input->mask[i][j][k][m];
    273                     output->coeff[i][j][k][m]    = input->coeff[i][j][k][m];
    274                     output->coeffErr[i][j][k][m] = input->coeffErr[i][j][k][m];
    275                 }
    276             }
    277         }
    278     }
    279     return (output);
    280133}
    281134
     
    328181}
    329182
    330 // very crude distortion inversion: assumes 0 order in z and t, linear in x and y:
    331 psPlaneDistort *psPlaneDistortInvert(psPlaneDistort *distort) {
    332     PS_ASSERT_PTR_NON_NULL(distort, 0);
    333     PS_ASSERT_PTR_NON_NULL(distort->x, 0);
    334     PS_ASSERT_PTR_NON_NULL(distort->y, 0);
    335 
    336     psPlaneDistort *out = psPlaneDistortAlloc(1, 1, 0, 0);
    337 
    338     /* simple matrix inversion code */
    339 
    340     psF64 r11 = distort->x->coeff[1][0][0][0];
    341     psF64 r12 = distort->x->coeff[0][1][0][0];
    342     psF64 r21 = distort->y->coeff[1][0][0][0];
    343     psF64 r22 = distort->y->coeff[0][1][0][0];
    344     psF64 xo  = distort->x->coeff[0][0][0][0];
    345     psF64 yo  = distort->y->coeff[0][0][0][0];
    346 
    347     psF64 invDet = 1.0 / (r11 * r22 - r12 * r21); // Inverse of the determinant
    348 
    349     out->x->coeff[1][0][0][0] = +invDet * r22;
    350     out->x->coeff[0][1][0][0] = -invDet * r12;
    351     out->y->coeff[1][0][0][0] = -invDet * r21;
    352     out->y->coeff[0][1][0][0] = +invDet * r11;
    353 
    354     out->x->coeff[0][0][0][0] = - invDet * (r22 * xo - r12 * yo);
    355     out->y->coeff[0][0][0][0] = - invDet * (r11 * yo - r21 * xo);
    356 
    357     return(out);
    358 }
    359 
    360183// returns the rotation term, forcing positive parity
    361184double psPlaneTransformGetRotation (psPlaneTransform *map) {
Note: See TracChangeset for help on using the changeset viewer.