Changeset 7014 for trunk/psastro/src/psastroWCS.c
- Timestamp:
- Apr 30, 2006, 12:15:03 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroWCS.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroWCS.c
r6176 r7014 2 2 3 3 // 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) 5 bool pmAstromReadWCS (psProjection **toSkyOut, psPlaneDistort **toTPAout, psPlaneTransform **toFPAout, psMetadata *header, double plateScale) { 5 6 6 7 psPlaneTransform *toFPA; 8 psPlaneDistort *toTPA; 7 9 psProjection *toSky; 8 10 psProjectionType type; … … 19 21 20 22 // determine projection type 23 // XXX add the Elixir DIS / WRP two-layer projection here 21 24 type = PS_PROJ_NTYPE; 22 25 if (!strcmp (&ctype[4], "-SIN")) type = PS_PROJ_SIN; … … 72 75 73 76 // renormalize to cdelt1, cdelt2, etc 74 floatscale = hypot (pc1_1, pc1_2);77 double scale = hypot (pc1_1, pc1_2); 75 78 cdelt1 = cdelt2 = scale; 76 79 pc1_1 /= scale; … … 89 92 // scale = scale(i)/scale(0) (i == chip #) 90 93 // 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_b294 94 toFPA = psPlaneTransformAlloc (1, 1); 95 95 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); 99 103 toFPA->x->mask[1][1] = 1; 100 104 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); 104 108 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 } 112 134 return true; 113 135 } … … 115 137 116 138 // 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) 140 bool pmAstromWriteWCS (psPlaneTransform *toFPA, psProjection *toSky, psMetadata *header, double plateScale) { 118 141 119 142 switch (toSky->type) { 120 143 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"); 123 146 break; 124 147 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"); 127 150 break; 128 151 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"); 131 154 break; 132 155 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"); 135 158 break; 136 159 default: … … 139 162 } 140 163 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]); 152 178 153 179 // alternative representations use … … 157 183 return true; 158 184 } 185 186 psPlaneDistort *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.
