IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 30, 2006, 12:15:03 PM (20 years ago)
Author:
eugene
Message:

first complete working version (chip only)

File:
1 edited

Legend:

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

    r6176 r7014  
    22
    33// interpret header WCS (only handles traditional WCS for the moment)
    4 bool pmAstromReadWCS (psPlaneTransform **toFPAOut, psProjection **toSkyOut, psMetadata *header) {
     4// plateScale is nominal physical scale on tangent plane (microns / arcsecond)
     5bool pmAstromReadWCS (psProjection **toSkyOut, psPlaneDistort **toTPAout, psPlaneTransform **toFPAout, psMetadata *header, double plateScale) {
    56
    67    psPlaneTransform *toFPA;
     8    psPlaneDistort *toTPA;
    79    psProjection *toSky;
    810    psProjectionType type;
     
    1921
    2022    // determine projection type
     23    // XXX add the Elixir DIS / WRP two-layer projection here
    2124    type = PS_PROJ_NTYPE;
    2225    if (!strcmp (&ctype[4], "-SIN")) type = PS_PROJ_SIN;
     
    7275       
    7376        // renormalize to cdelt1, cdelt2, etc
    74         float scale = hypot (pc1_1, pc1_2);
     77        double scale = hypot (pc1_1, pc1_2);
    7578        cdelt1 = cdelt2 = scale;
    7679        pc1_1 /= scale;
     
    8992    //           scale = scale(i)/scale(0) (i == chip #)
    9093    //           project crval1(0),crval2(0 using projection
    91 
    92     // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581)
    93     // XXX EAM : I've fixed this in pslib eam_rel8_b2
    9494    toFPA = psPlaneTransformAlloc (1, 1);
    9595   
    96     toFPA->x->coeff[0][0] = crpix1;
    97     toFPA->x->coeff[1][0] = pc1_1;
    98     toFPA->x->coeff[0][1] = pc1_2;
     96    double cdelt = hypot (cdelt1, cdelt2) / plateScale;  // degrees / micron (eg, in fact, whatever unit user chooses for focal plane)
     97    cdelt1 /= cdelt;
     98    cdelt2 /= cdelt;
     99
     100    toFPA->x->coeff[0][0] = -(pc1_1*cdelt1*crpix1 + pc1_2*cdelt2*crpix2);
     101    toFPA->x->coeff[1][0] = +(pc1_1*cdelt1);
     102    toFPA->x->coeff[0][1] = +(pc1_2*cdelt2);
    99103    toFPA->x->mask[1][1]  = 1;
    100104
    101     toFPA->y->coeff[0][0] = crpix2;
    102     toFPA->y->coeff[1][0] = pc2_1;
    103     toFPA->y->coeff[0][1] = pc2_2;
     105    toFPA->y->coeff[0][0] = -(pc2_1*cdelt1*crpix1 + pc2_2*cdelt2*crpix2);
     106    toFPA->y->coeff[1][0] = +(pc2_1*cdelt1);
     107    toFPA->y->coeff[0][1] = +(pc2_2*cdelt2);
    104108    toFPA->y->mask[1][1]  = 1;
    105 
    106     // center of projection is (0,0) coordinate of TPA
    107     toSky = psProjectionAlloc (crval1*RAD_DEG, crval2*RAD_DEG, cdelt1*RAD_DEG, cdelt2*RAD_DEG, type);
    108 
    109     *toFPAOut = toFPA;
    110     *toSkyOut = toSky;
    111 
     109    *toFPAout = toFPA;
     110
     111    if (*toSkyOut != NULL) {
     112        if (*toTPAout == NULL) psAbort ("wcs", "projection defined, tangent-plane not defined");
     113
     114        psSphere sky;
     115        psPlane tpa;
     116
     117        sky.r = crval1*RAD_DEG;
     118        sky.d = crval2*RAD_DEG;
     119        p_psProject (&tpa, &sky, *toSkyOut);
     120       
     121        // XXX for the moment, assume toTPA is the identity transformation
     122        toFPA->x->coeff[0][0] = tpa.x;
     123        toFPA->y->coeff[0][0] = tpa.y;
     124    } else {
     125        // XXX for now, use the identity for TPA <--> FPA
     126        toTPA = psPlaneDistortIdentity ();
     127
     128        // center of projection is (0,0) coordinate of TPA
     129        toSky = psProjectionAlloc (crval1*RAD_DEG, crval2*RAD_DEG, RAD_DEG*cdelt, RAD_DEG*cdelt, type);
     130
     131        *toTPAout = toTPA;
     132        *toSkyOut = toSky;
     133    }
    112134    return true;
    113135}
     
    115137
    116138// convert toFPA / toSky components to traditional WCS
    117 bool pmAstromWriteWCS (psPlaneTransform *toFPA, psProjection *toSky, psMetadata *header) {
     139// plateScale is nominal physical scale on tangent plane (microns / arcsecond)
     140bool pmAstromWriteWCS (psPlaneTransform *toFPA, psProjection *toSky, psMetadata *header, double plateScale) {
    118141
    119142    switch (toSky->type) {
    120143      case PS_PROJ_SIN:
    121         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---SIN");
    122         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--SIN");
     144        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE1", PS_META_REPLACE, "", "RA---SIN");
     145        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE2", PS_META_REPLACE, "", "DEC--SIN");
    123146        break;
    124147      case PS_PROJ_TAN:
    125         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---TAN");
    126         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--TAN");
     148        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE1", PS_META_REPLACE, "", "RA---TAN");
     149        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE2", PS_META_REPLACE, "", "DEC--TAN");
    127150        break;
    128151      case PS_PROJ_AIT:
    129         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---AIT");
    130         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--AIT");
     152        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE1", PS_META_REPLACE, "", "RA---AIT");
     153        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE2", PS_META_REPLACE, "", "DEC--AIT");
    131154        break;
    132155      case PS_PROJ_PAR:
    133         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE1", PS_DATA_STRING | PS_META_REPLACE, "", "RA---PAR");
    134         psMetadataAdd (header, PS_LIST_TAIL, "CTYPE2", PS_DATA_STRING | PS_META_REPLACE, "", "DEC--PAR");
     156        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE1", PS_META_REPLACE, "", "RA---PAR");
     157        psMetadataAddStr (header, PS_LIST_TAIL, "CTYPE2", PS_META_REPLACE, "", "DEC--PAR");
    135158        break;
    136159      default:
     
    139162    }
    140163
    141     psMetadataAdd (header, PS_LIST_TAIL, "CRVAL1", PS_DATA_F32 | PS_META_REPLACE, "", toSky->R*DEG_RAD);
    142     psMetadataAdd (header, PS_LIST_TAIL, "CRVAL2", PS_DATA_F32 | PS_META_REPLACE, "", toSky->D*DEG_RAD);
    143     psMetadataAdd (header, PS_LIST_TAIL, "CRPIX1", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->x->coeff[0][0]);
    144     psMetadataAdd (header, PS_LIST_TAIL, "CRPIX2", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->y->coeff[0][0]);
    145     psMetadataAdd (header, PS_LIST_TAIL, "CDELT1", PS_DATA_F32 | PS_META_REPLACE, "", toSky->Xs*DEG_RAD);
    146     psMetadataAdd (header, PS_LIST_TAIL, "CDELT2", PS_DATA_F32 | PS_META_REPLACE, "", toSky->Ys*DEG_RAD);
    147 
    148     psMetadataAdd (header, PS_LIST_TAIL, "PC001001", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->x->coeff[1][0]);
    149     psMetadataAdd (header, PS_LIST_TAIL, "PC001002", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->x->coeff[0][1]);
    150     psMetadataAdd (header, PS_LIST_TAIL, "PC002001", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->y->coeff[1][0]);
    151     psMetadataAdd (header, PS_LIST_TAIL, "PC002002", PS_DATA_F32 | PS_META_REPLACE, "", toFPA->y->coeff[0][1]);
     164    // XXX not really right: needs to deal with non-identity toTP coeffs
     165    // XXX actually, totally wrong.  fix the conversions
     166    // XXX need to handle the plateScale
     167    psMetadataAddF32 (header, PS_LIST_TAIL, "CRVAL1",   PS_META_REPLACE, "", toSky->R*DEG_RAD);
     168    psMetadataAddF32 (header, PS_LIST_TAIL, "CRVAL2",   PS_META_REPLACE, "", toSky->D*DEG_RAD);
     169    psMetadataAddF32 (header, PS_LIST_TAIL, "CRPIX1",   PS_META_REPLACE, "", toFPA->x->coeff[0][0]);
     170    psMetadataAddF32 (header, PS_LIST_TAIL, "CRPIX2",   PS_META_REPLACE, "", toFPA->y->coeff[0][0]);
     171    psMetadataAddF32 (header, PS_LIST_TAIL, "CDELT1",   PS_META_REPLACE, "", toSky->Xs*DEG_RAD);
     172    psMetadataAddF32 (header, PS_LIST_TAIL, "CDELT2",   PS_META_REPLACE, "", toSky->Ys*DEG_RAD);
     173
     174    psMetadataAddF32 (header, PS_LIST_TAIL, "PC001001", PS_META_REPLACE, "", toFPA->x->coeff[1][0]);
     175    psMetadataAddF32 (header, PS_LIST_TAIL, "PC001002", PS_META_REPLACE, "", toFPA->x->coeff[0][1]);
     176    psMetadataAddF32 (header, PS_LIST_TAIL, "PC002001", PS_META_REPLACE, "", toFPA->y->coeff[1][0]);
     177    psMetadataAddF32 (header, PS_LIST_TAIL, "PC002002", PS_META_REPLACE, "", toFPA->y->coeff[0][1]);
    152178
    153179    // alternative representations use
     
    157183    return true;
    158184}
     185
     186psPlaneDistort *psPlaneDistortIdentity () {
     187
     188    psPlaneDistort *distort;
     189
     190    distort = psPlaneDistortAlloc (1, 1, 0, 0);
     191    distort->x->coeff[0][0][0][0] = 0;
     192    distort->x->coeff[1][0][0][0] = 1;
     193    distort->x->coeff[0][1][0][0] = 0;
     194    distort->x->mask [1][1][0][0] = 1;
     195
     196    distort->y->coeff[0][0][0][0] = 0;
     197    distort->y->coeff[1][0][0][0] = 0;
     198    distort->y->coeff[0][1][0][0] = 1;
     199    distort->y->mask [1][1][0][0] = 1;
     200
     201    return distort;
     202}
Note: See TracChangeset for help on using the changeset viewer.