IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 22, 2005, 10:38:21 AM (21 years ago)
Author:
eugene
Message:

fixed up WCS

File:
1 edited

Legend:

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

    r5560 r5575  
    2020    pmFPA *fpa = pmFPAAlloc (NULL, NULL);
    2121
     22    // identify matrix for fpa to tpa
     23    fpa->toTPA   = psPlaneDistortAlloc (1, 1, 0, 0);
     24    fpa->toTPA->x->coeff[1][0][0][0] = 1;
     25    fpa->toTPA->x->mask[1][1][0][0]  = 1;
     26
     27    fpa->toTPA->y->coeff[0][1][0][0] = 1;
     28    fpa->toTPA->y->mask[1][1][0][0]  = 1;
     29    fpa->fromTangentPlane = psPlaneDistortInvert (fpa->toTangentPlane);
     30
    2231    psArrayRealloc (fpa->chips, Nchips);
    2332    for (int i = 0; i < Nchips; i++) {
     
    3039            // XXX EAM : extend this function to take more than one header
    3140            cell->header = header;     
    32             pmCellInterpretWCS (cell, header);
     41            pmAstromReadWCS (&chip->toFPA, &fpa->toSky, header);
     42            chip->fromFPA = p_psPlaneTransformLinearInvert (chip->toFPA);
     43
     44            // allocate identity matrix for cell to chip
     45            cell->toChip   = psPlaneTransformAlloc (1, 1);
     46            cell->toChip->x->coeff[1][0] = 1;
     47            cell->toChip->x->mask[1][1]  = 1;
     48            cell->toChip->y->coeff[0][1] = 1;
     49            cell->toChip->y->mask[1][1]  = 1;
    3350
    3451            psArrayRealloc (cell->readouts, Nreadouts);
     
    5269}
    5370
    54 // interpret header WCS
    55 bool pmCellInterpretWCS (pmCell *cell, psMetadata *header) {
    56 
    57     pmChip *chip;
    58     pmFPA  *fpa;
     71// interpret header WCS (only handles traditional WCS for the moment)
     72bool pmAstromReadWCS (psPlaneTransform **toFPAOut, psProjection **toSkyOut, psMetadata *header) {
     73
     74    psPlaneTransform *toFPA;
     75    psProjection *toSky;
     76    psProjectionType type;
    5977    bool status;
    60     psProjectionType type;
    6178    float crval1, crval2, crpix1, crpix2, cdelt1, cdelt2;
    6279    float pc1_1, pc1_2, pc2_1, pc2_2;
     
    136153got_matrix:
    137154
    138     // XXX EAM : these must already be set
    139     chip = cell->parent;
    140     fpa  = chip->parent;
    141 
    142     // set toChip to identity as default
    143     // XXX EAM : can we actually use higher order?
    144     int nX = psMetadataLookupS32 (&status, header, "PSASTRO.CHIP.NX");
    145     if (!status) nX = 1;
    146     int nY = psMetadataLookupS32 (&status, header, "PSASTRO.CHIP.NY");
    147     if (!status) nY = 1;
    148 
    149     cell->toChip   = psPlaneTransformAlloc (1, 1);
    150     cell->toChip->x->coeff[1][0] = 1;
    151     cell->toChip->x->mask[1][1]  = 1;
    152 
    153     cell->toChip->y->coeff[0][1] = 1;
    154     cell->toChip->y->mask[1][1]  = 1;
    155 
    156155    // XXX EAM : if fpa->toSky and fpa->toTPA are already defined, then the
    157156    //           toFPA must be modified to match the crval(i), scale(i) and crpix(i)
     
    161160    // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581)
    162161    // XXX EAM : I've fixed this in pslib eam_rel8_b2
    163     chip->toFPA  = psPlaneTransformAlloc (1, 1);
     162    toFPA = psPlaneTransformAlloc (1, 1);
    164163   
    165     chip->toFPA->x->coeff[0][0] = crpix1;
    166     chip->toFPA->x->coeff[1][0] = pc1_1;
    167     chip->toFPA->x->coeff[0][1] = pc1_2;
    168     chip->toFPA->x->mask[1][1]  = 1;
    169 
    170     chip->toFPA->y->coeff[0][0] = crpix2;
    171     chip->toFPA->y->coeff[1][0] = pc2_1;
    172     chip->toFPA->y->coeff[0][1] = pc2_2;
    173     chip->toFPA->y->mask[1][1]  = 1;
    174 
    175     chip->fromFPA = p_psPlaneTransformLinearInvert (chip->toFPA);
    176 
    177     // set toTPA to identity as default
    178     // XXX EAM : psPlaneDistortAlloc uses nTerm not nOrder (bug 581)
    179     if (fpa->toTPA == NULL) {
    180         fpa->toTPA   = psPlaneDistortAlloc (1, 1, 0, 0);
    181         fpa->toTPA->x->coeff[1][0][0][0] = 1;
    182         fpa->toTPA->x->mask[1][1][0][0]  = 1;
    183 
    184         fpa->toTPA->y->coeff[0][1][0][0] = 1;
    185         fpa->toTPA->y->mask[1][1][0][0]  = 1;
    186         fpa->fromTangentPlane = psPlaneDistortInvert (fpa->toTangentPlane);
    187     } else {
    188         psLogMsg ("psastro", 2, "warning: fpa distortion already defined\n");
    189     }
     164    toFPA->x->coeff[0][0] = crpix1;
     165    toFPA->x->coeff[1][0] = pc1_1;
     166    toFPA->x->coeff[0][1] = pc1_2;
     167    toFPA->x->mask[1][1]  = 1;
     168
     169    toFPA->y->coeff[0][0] = crpix2;
     170    toFPA->y->coeff[1][0] = pc2_1;
     171    toFPA->y->coeff[0][1] = pc2_2;
     172    toFPA->y->mask[1][1]  = 1;
    190173
    191174    // center of projection is (0,0) coordinate of TPA
    192     fpa->toSky = psProjectionAlloc (crval1*RAD_DEG, crval2*RAD_DEG, cdelt1*RAD_DEG, cdelt2*RAD_DEG, type);
     175    toSky = psProjectionAlloc (crval1*RAD_DEG, crval2*RAD_DEG, cdelt1*RAD_DEG, cdelt2*RAD_DEG, type);
     176
     177    *toFPAOut = toFPA;
     178    *toSkyOut = toSky;
     179
    193180    return true;
    194181}
     182
     183
     184// convert toFPA / toSky components to traditional WCS
     185bool pmAstromWriteWCS (psPlaneTransform *toFPA, psProjection *toSky, psMetadata *header) {
     186
     187    switch (toSky->type) {
     188      case PS_PROJ_SIN:
     189        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---SIN");
     190        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--SIN");
     191        break;
     192      case PS_PROJ_TAN:
     193        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---TAN");
     194        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--TAN");
     195        break;
     196      case PS_PROJ_AIT:
     197        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---AIT");
     198        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--AIT");
     199        break;
     200      case PS_PROJ_PAR:
     201        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---PAR");
     202        psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--PAR");
     203        break;
     204      default:
     205        psLogMsg ("psastro", 2, "warning: unknown projection type %s\n", toSky->type);
     206        return false;
     207    }
     208
     209    psMetadataAdd (header, PS_LIST_TAIL, "CRVAL1", PS_DATA_F32 | PS_META_REPLACE, "", toSky->R*DEG_RAD);
     210    psMetadataAdd (header, PS_LIST_TAIL, "CRVAL2", PS_DATA_F32 | PS_META_REPLACE, "", toSky->D*DEG_RAD);
     211    psMetadataAdd (header, PS_LIST_TAIL, "CRPIX1", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->x->coeff[0][0]);
     212    psMetadataAdd (header, PS_LIST_TAIL, "CRPIX2", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->y->coeff[0][0]);
     213    psMetadataAdd (header, PS_LIST_TAIL, "CDELT1", PS_DATA_F32 | PS_META_REPLACE, "", toSky->Xs*DEG_RAD);
     214    psMetadataAdd (header, PS_LIST_TAIL, "CDELT2", PS_DATA_F32 | PS_META_REPLACE, "", toSky->Ys*DEG_RAD);
     215
     216    psMetadataAdd (header, PS_LIST_TAIL, "PC001001", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->x->coeff[1][0]);
     217    psMetadataAdd (header, PS_LIST_TAIL, "PC001002", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->x->coeff[0][1]);
     218    psMetadataAdd (header, PS_LIST_TAIL, "PC002001", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->y->coeff[1][0]);
     219    psMetadataAdd (header, PS_LIST_TAIL, "PC002002", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->y->coeff[0][1]);
     220
     221    // alternative representations use
     222    // CD1_1 = PC001001*CDELT1, etc
     223    // make these representations optional
     224
     225    return true;
     226}
Note: See TracChangeset for help on using the changeset viewer.