Changeset 5506 for trunk/psastro/src/psastroBuildFPA.c
- Timestamp:
- Nov 11, 2005, 9:54:59 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroBuildFPA.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroBuildFPA.c
r5505 r5506 1 1 # include "psastro.h" 2 2 3 pmFPA *psastroBuildFPA (psMetadata *header, psMetadata *config) { 4 5 // this function constructs a basic template pmFPA structure based on the information in the header 6 // metadata. it converts the astrometric information in the header (WCS, etc) to the corresponding 7 // pmFPA/pmChip, etc distortion and projection elements. 8 9 // this implementation is basic, assuming a single readout,chip,cell 10 // I will not handle the datasec/biassec information to define the readout/cell 11 // these things are already handled by Paul's code. this function simple looks for the WCS information 12 // and provides those conversions. 13 14 int Nchips = 1; 15 int Ncells = 1; 16 int Nreadouts = 1; 17 18 // allocate the structures 19 20 pmFPA *fpa = pmFPAAlloc (); 21 22 fpa->chips = psArrayAlloc (Nchips); 23 for (int i = 0; i < Nchips; i++) { 24 25 pmChip *chip = pmChipAlloc (); 26 chip->fpa = fpa; // assign parent fpa (view only; don't free) 27 28 chip->cells = psArrayAlloc (Ncells); 29 for (int j = 0; j < Ncells; j++) { 30 31 pmCell *cell = pmCellAlloc (); 32 cell->chip = chip; // assign parent chip (view only; don't free) 33 cell->header = header; 34 35 pmCellInterpretWCS (cell, header); 36 37 cell->readouts = psArrayAlloc (Nreadouts); 38 for (int k = 0; k < Nreadouts; k++) { 39 40 pmReadout *readout = pmReadoutAlloc (); 41 cells->readouts->data[j] = readout; 42 } 43 chips->cells->data[j] = cell; 44 } 45 fpa->chips->data[i] = chip; 46 } 47 return (fpa); 48 } 49 50 // interpret header WCS 51 bool pmCellInterpretWCS (pmCell *cell, psMetadata *header) { 52 53 float crval1, crval2, crpix1, crpix2, cdelt1, cdelt2; 54 float pc1_1, pc1_2, pc2_1, pc2_2; 55 56 // *** interpret header data, convert to crval(i), etc 57 char *ctype = pmMetadataLookupPtr (&status, header, "CTYPE2"); 58 if (!status) { 59 psLogMsg ("psastro", 2, "warning: no WCS metadata in header\n"); 60 return false; 61 } 62 63 // determine projection type 64 type = PS_PROJ_NTYPE; 65 if (!strcmp (&ctype[4], "-SIN")) type = PS_PROJ_SIN; 66 if (!strcmp (&ctype[4], "-TAN")) type = PS_PROJ_TAN; 67 if (!strcmp (&ctype[4], "-AIT")) type = PS_PROJ_AIT; 68 if (!strcmp (&ctype[4], "-PAR")) type = PS_PROJ_PAR; 69 if (type == PS_PROJ_NTYPE) { 70 psLogMsg ("psastro", 2, "warning: unknown projection type %s\n", ctype); 71 return false; 72 } 73 74 crval1 = psMetadataLookupF32 (&status, header, "CRVAL1"); 75 crval2 = psMetadataLookupF32 (&status, header, "CRVAL2"); 76 crpix1 = psMetadataLookupF32 (&status, header, "CRPIX1"); 77 crpix2 = psMetadataLookupF32 (&status, header, "CRPIX2"); 78 79 // test the CDELTi varient 80 cdelt1 = psMetadataLookupF32 (&status, header, "CDELT1"); 81 if (status) { 82 cdelt2 = psMetadataLookupF32 (&status, header, "CDELT2"); 83 84 // test the CROTAi varient: 85 float rotate = psMetadataLookupF32 (&status, header, "CROTA2"); 86 if (status) { 87 Lambda = cdelt2 / cdelt1; 88 pc1_1 = cos(rotate*RAD_DEG); 89 pc1_2 = -sin(rotate*RAD_DEG) * Lambda; 90 pc2_1 = sin(rotate*RAD_DEG) / Lambda; 91 pc2_2 = cos(rotate*RAD_DEG); 92 goto got_matrix; 93 } 94 95 // test the PC00i00j varient: 96 pc1_1 = psMetadataLookupF32 (&status, header, "PC001001"); 97 if (status) { 98 pc1_2 = psMetadataLookupF32 (&status, header, "PC001002"); 99 pc2_1 = psMetadataLookupF32 (&status, header, "PC002001"); 100 pc2_2 = psMetadataLookupF32 (&status, header, "PC002002"); 101 102 // XXX EAM : add Elixir polynomial terms here eventually 103 goto got_matrix; 104 } 105 psLogMsg ("psastro", 2, "warning: missing rotation matrix?\n"); 106 return false; 107 } 108 109 // test the CDi_j varient 110 pc1_1 = psMetadataLookupF32 (&status, header, "CD1_1"); 111 if (status) { 112 pc1_2 = psMetadataLookupF32 (&status, header, "CD1_2"); 113 pc2_1 = psMetadataLookupF32 (&status, header, "CD2_1"); 114 pc2_2 = psMetadataLookupF32 (&status, header, "CD2_2"); 115 116 // renormalize to cdelt1, cdelt2, etc 117 float scale = hypot (pc1_1, pc1_2); 118 cdelt1 = cdelt2 = scale; 119 pc1_1 /= scale; 120 pc1_2 /= scale; 121 pc2_1 /= scale; 122 pc2_2 /= scale; 123 goto got_matrix; 124 } 125 psLogMsg ("psastro", 2, "warning: missing rotation matrix?\n"); 126 return false; 127 128 got_matrix: 129 130 // XXX EAM : these must already be set 131 chip = cell->chip; 132 fpa = chip->fpa; 133 134 // set toChip to identity as default 135 // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581) 136 cell->toChip = psPlaneTransformAlloc (2, 2); 137 cell->toChip->x->coeff[1][0] = 1; 138 cell->toChip->x->mask[1][1] = 1; 139 140 cell->toChip->y->coeff[0][1] = 1; 141 cell->toChip->y->mask[1][1] = 1; 142 143 // XXX EAM : if fpa->toSky and fpa->toTPA are already defined, then the 144 // toFPA must be modified to match the crval(i), scale(i) and crpix(i) 145 146 // XXX EAM : psPlaneTransformAlloc uses nTerm not nOrder (bug 581) 147 chip->toFPA = psPlaneTransformAlloc (2, 2); 148 149 chip->toFPA->x->coeff[0][0] = crpix1; 150 chip->toFPA->x->coeff[1][0] = pc1_1; 151 chip->toFPA->x->coeff[0][1] = pc1_2; 152 chip->toFPA->x->mask[1][1] = 1; 153 154 chip->toFPA->y->coeff[0][0] = crpix2; 155 chip->toFPA->y->coeff[1][0] = pc2_1; 156 chip->toFPA->y->coeff[0][1] = pc2_2; 157 chip->toFPA->y->mask[1][1] = 1; 158 159 // set toTPA to identity as default 160 // XXX EAM : psPlaneDistortAlloc uses nTerm not nOrder (bug 581) 161 if (fpa->toTPA == NULL) { 162 fpa->toTPA = psPlaneDistortAlloc (2, 2, 1, 1); 163 fpa->toTPA->x->coeff[1][0][0][0] = 1; 164 fpa->toTPA->x->mask[1][1][0][0] = 1; 165 166 fpa->toTPA->y->coeff[0][1][0][0] = 1; 167 fpa->toTPA->y->mask[1][1][0][0] = 1; 168 } else { 169 psLogMsg ("psastro", 2, "warning: fpa distortion already defined\n"); 170 } 171 172 // center of projection is (0,0) coordinate of TPA 173 fpa->toSky = psProjectionAlloc (crval1, crval2, cdelt1, cdelt2, type); 174 return true; 175 }
Note:
See TracChangeset
for help on using the changeset viewer.
