Changeset 15675 for trunk/psModules/src/astrom/pmAstrometryTable.c
- Timestamp:
- Nov 20, 2007, 11:59:40 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/astrom/pmAstrometryTable.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/astrom/pmAstrometryTable.c
r15665 r15675 8 8 * @author EAM, IfA 9 9 * 10 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $11 * @date $Date: 2007-11-21 0 7:02:55$10 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 11 * @date $Date: 2007-11-21 09:59:40 $ 12 12 * 13 13 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 90 90 } 91 91 92 /********************* WritePHU function *****************************/ 93 94 bool pmAstromWritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) { 95 96 // not needed if already written 97 if (file->wrote_phu) return true; 98 99 // not needed if not FPA 100 // XXX this prevents us from defining a SPLIT/MEF CMF file... 101 if (file->fileLevel != PM_FPA_LEVEL_FPA) return true; 102 103 // find the FPA phu 104 // XXX do we need to supply a header from the image? 105 pmHDU *phu = pmFPAviewThisPHU (view, file->fpa); 106 107 // if there is no PHU, this is a single header+image (extension-less) file. This could be 92 /********************* Write Data functions *****************************/ 93 94 bool pmAstromWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) { 95 96 // write the full table in one pass: require the level to be FPA 97 if (view->chip != -1) { 98 psError(PS_ERR_IO, false, "Astrometry must be written at the chip level"); 99 return false; 100 } 101 102 if (!pmAstromWriteFPA (file)) { 103 psError(PS_ERR_IO, false, "Failed to write Astrometry for fpa"); 104 return false; 105 } 106 return true; 107 } 108 109 // write out all chip-level Astrometry data for this FPA 110 bool pmAstromWriteFPA (pmFPAfile *file) { 111 112 if (!pmAstromWritePHU (file)) { 113 psError(PS_ERR_IO, false, "Failed to write PHU for Astrometry table"); 114 return false; 115 } 116 117 if (!pmAstromWriteSky (file)) { 118 psError(PS_ERR_IO, false, "Failed to write Sky for Astrometry table"); 119 return false; 120 } 121 122 if (!pmAstromWriteTP (file)) { 123 psError(PS_ERR_IO, false, "Failed to write Sky for Astrometry table"); 124 return false; 125 } 126 127 if (!pmAstromWriteFP (file)) { 128 psError(PS_ERR_IO, false, "Failed to write Sky for Astrometry table"); 129 return false; 130 } 131 132 if (!pmAstromWriteChips (file)) { 133 psError(PS_ERR_IO, false, "Failed to write Astrometry for chips"); 134 return false; 135 } 136 return true; 137 } 138 139 bool pmAstromWritePHU (pmFPAfile *file) { 140 141 // output header data 142 psMetadata *outhead = psMetadataAlloc(); 143 144 // use the FPA phu to generate the PHU header 145 pmHDU *phu = file->fpa->hdu; 146 147 // if there is no FPA PHU, this is a single header+image (extension-less) file. This could be 108 148 // the case for an input SPLIT set of files being written out as a MEF. if there is a PHU, 109 149 // write it out as a 'blank' 110 psMetadata *outhead = psMetadataAlloc();111 150 if (phu) { 112 psMetadataCopy (outhead, phu->header);151 psMetadataCopy (outhead, phu->header); 113 152 } else { 114 pmConfigConformHeader (outhead, file->format);153 pmConfigConformHeader (outhead, file->format); 115 154 116 155 // XXX probably need other info to conform the header 117 psMetadata *fileData = psMetadataLookupMetadata(NULL, file->format, "FILE"); // File information118 const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.NAME");119 if (fpaNameHdr && strlen(fpaNameHdr) > 0) {120 const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.NAME");121 psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName);122 }156 psMetadata *fileData = psMetadataLookupMetadata(NULL, file->format, "FILE"); // File information 157 const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.NAME"); 158 if (fpaNameHdr && strlen(fpaNameHdr) > 0) { 159 const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.NAME"); 160 psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName); 161 } 123 162 } 124 163 … … 133 172 } 134 173 135 /********************* Write Data functions *****************************/ 136 137 bool pmAstromWriteForView (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) { 138 139 pmFPA *fpa = file->fpa; 140 141 if (view->chip == -1) { 142 if (!pmAstromWriteFPA (fpa, view, file, config)) { 143 psError(PS_ERR_IO, false, "Failed to write Astrometry for fpa"); 144 return false; 145 } 146 return true; 147 } 148 if (view->chip >= fpa->chips->n) { 149 return false; 150 } 151 pmChip *chip = fpa->chips->data[view->chip]; 152 153 if (view->cell == -1) { 154 if (!pmAstromWriteChip (chip, view, file, config)) { 155 psError(PS_ERR_IO, false, "Failed to write Astrometry for chip"); 156 return false; 157 } 158 return true; 159 } 160 161 psError(PS_ERR_IO, false, "Astrometry must be written at the chip level"); 162 return false; 163 } 164 165 // write out all chip-level Astrometry data for this FPA 166 bool pmAstromWriteFPA (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 167 { 168 pmFPAview *thisView = pmFPAviewAlloc (view->nRows); 169 *thisView = *view; 170 171 for (int i = 0; i < fpa->chips->n; i++) { 172 pmChip *chip = fpa->chips->data[i]; 173 thisView->chip = i; 174 if (!pmAstromWriteChip (chip, thisView, file, config)) { 175 psError(PS_ERR_IO, false, "Failed to write Astrometry for %dth chip", i); 176 psFree(thisView); 177 return false; 178 } 179 } 180 psFree(thisView); 181 return true; 182 } 183 184 // write out chip-level Astrometry data for this chip 185 // XXX this function writes out astrometry elements for a chip->fpa->tp->sky layer set 186 // XXX we need to ensure the chip and fpa level data are written 187 // XXX can we write the rows one at a time (or groups at a time?) 188 // XXX allow this to be chip level, or just force to be fpa? is it valid at the chip level?? 189 bool pmAstromWriteChip (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 190 { 191 psArray *table; 192 psMetadata *row; 193 psMetadata *header; 194 195 // write out the blank PHU to start the file 196 psFitsWriteBlank (file->fits, NULL, NULL); 197 198 // first layer is the sky 199 header = psMetadataAlloc(); 174 // first layer is the sky 175 bool pmAstromWriteSky (pmFPAfile *file) { 176 177 psMetadata *header = psMetadataAlloc(); 200 178 psMetadataAddStr(header, PS_LIST_TAIL, "COORD", PS_META_REPLACE, "name of this layer", "SKY"); 201 179 psMetadataAddStr(header, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "NONE"); … … 203 181 psMetadataAddStr(header, PS_LIST_TAIL, "TRANSFRM", PS_META_REPLACE, "mapping to parent", "NONE"); 204 182 205 table = psArrayAllocEmpty (1);206 row = psMetadataAlloc ();183 psArray *table = psArrayAllocEmpty (1); 184 psMetadata *row = psMetadataAlloc (); 207 185 psMetadataAddStr(row, PS_LIST_TAIL, "SEGMENT", PS_META_REPLACE, "name of this segment", "SKY"); 208 186 psMetadataAddStr(row, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "NONE"); … … 219 197 psFree (table); 220 198 psFree (header); 221 222 // second layer is the tangent plane 223 header = psMetadataAlloc(); 199 return (true); 200 } 201 202 // second layer is the tangent plane 203 bool pmAstromWriteTP (pmFPAfile *file) { 204 205 psMetadata *header = psMetadataAlloc(); 224 206 psMetadataAddStr(header, PS_LIST_TAIL, "COORD", PS_META_REPLACE, "name of this layer", "TANGENT_PLANE"); 225 207 psMetadataAddStr(header, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "SKY"); … … 227 209 psMetadataAddStr(header, PS_LIST_TAIL, "TRANSFRM", PS_META_REPLACE, "mapping to parent", "PROJECTION"); 228 210 229 table = psArrayAllocEmpty (1);230 row = psMetadataAlloc ();211 psArray *table = psArrayAllocEmpty (1); 212 psMetadata *row = psMetadataAlloc (); 231 213 psMetadataAddStr(row, PS_LIST_TAIL, "SEGMENT", PS_META_REPLACE, "name of this segment", "TANGENT_PLANE"); 232 214 psMetadataAddStr(row, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "SKY"); … … 252 234 } 253 235 236 psFree (region); 254 237 psFree (table); 255 238 psFree (header); 256 257 // third layer is the focal plane 258 header = psMetadataAlloc(); 239 return (true); 240 } 241 242 // third layer is the focal plane 243 bool pmAstromWriteFP (pmFPAfile *file) { 244 245 psMetadata *header = psMetadataAlloc(); 259 246 psMetadataAddStr(header, PS_LIST_TAIL, "COORD", PS_META_REPLACE, "name of this layer", "FOCAL_PLANE"); 260 247 psMetadataAddStr(header, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "TANGENT_PLANE"); … … 262 249 psMetadataAddStr(header, PS_LIST_TAIL, "TRANSFRM", PS_META_REPLACE, "mapping to parent", "POLYNOMIAL"); 263 250 264 table = psArrayAllocEmpty (1);251 psArray *table = psArrayAllocEmpty (1); 265 252 266 253 // XXX is this or the tpa region correct? 267 region = pmAstromFPAExtent (file->fpa);254 psRegion *region = pmAstromFPAExtent (file->fpa); 268 255 269 256 for (int i = 0; i <= file->fpa->toTPA->x->nX; i++) { 270 257 for (int j = 0; j <= file->fpa->toTPA->x->nY; j++) { 271 row = psMetadataAlloc ();258 psMetadata *row = psMetadataAlloc (); 272 259 psMetadataAddStr(row, PS_LIST_TAIL, "SEGMENT", PS_META_REPLACE, "name of this segment", "FOCAL_PLANE"); 273 260 psMetadataAddStr(row, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "TANGENT_PLANE"); … … 297 284 psFree (table); 298 285 psFree (header); 299 300 // fourth layer holds the chips 301 header = psMetadataAlloc(); 302 psMetadataAddStr(header, PS_LIST_TAIL, "COORD", PS_META_REPLACE, "name of this layer", "FOCAL_PLANE"); 303 psMetadataAddStr(header, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "TANGENT_PLANE"); 286 return true; 287 } 288 289 // fourth layer holds the chips 290 bool pmAstromWriteChips (pmFPAfile *file) { 291 292 psMetadata *header = psMetadataAlloc(); 293 psMetadataAddStr(header, PS_LIST_TAIL, "COORD", PS_META_REPLACE, "name of this layer", "CHIPS"); 294 psMetadataAddStr(header, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "FOCAL_PLANE"); 304 295 psMetadataAddStr(header, PS_LIST_TAIL, "BOUNDARY", PS_META_REPLACE, "validity region", "RECTANGLE"); 305 296 psMetadataAddStr(header, PS_LIST_TAIL, "TRANSFRM", PS_META_REPLACE, "mapping to parent", "POLYNOMIAL"); 306 297 307 table = psArrayAllocEmpty (1);298 psArray *table = psArrayAllocEmpty (1); 308 299 309 300 pmFPAview *view = pmFPAviewAlloc (0); … … 314 305 psRegion *region = pmChipPixels (chip); 315 306 307 // set the chip name 316 308 char *chiprule = psStringCopy ("CHIP.{CHIP.NAME}"); 317 309 char *chipname = pmFPAfileNameFromRule (chiprule, file, view); … … 319 311 for (int i = 0; i <= chip->toFPA->x->nX; i++) { 320 312 for (int j = 0; j <= chip->toFPA->x->nY; j++) { 321 row = psMetadataAlloc ();322 // xXXX set chip name based on metadata313 psMetadata *row = psMetadataAlloc (); 314 323 315 psMetadataAddStr(row, PS_LIST_TAIL, "SEGMENT", PS_META_REPLACE, "name of this segment", chipname); 324 psMetadataAddStr(row, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", " TANGENT_PLANE");316 psMetadataAddStr(row, PS_LIST_TAIL, "PARENT", PS_META_REPLACE, "next layer up", "FOCAL_PLANE"); 325 317 psMetadataAddF32(row, PS_LIST_TAIL, "MINX", PS_META_REPLACE, "range", region->x0); 326 318 psMetadataAddF32(row, PS_LIST_TAIL, "MAXX", PS_META_REPLACE, "range", region->x1); … … 340 332 psFree (chiprule); 341 333 psFree (chipname); 342 } 343 psFree (view);334 psFree (region); 335 } 344 336 345 337 if (!psFitsWriteTable (file->fits, header, table, "CHIPS")) { … … 349 341 } 350 342 343 psFree (view); 351 344 psFree (table); 352 345 psFree (header); … … 412 405 413 406 // XXX finish this: uncomment when used 414 # if (0)407 # if (0) 415 408 char *extname = pmFPAfileNameFromRule (rule, file, view); 416 # endif409 # endif 417 410 418 411 // read the chip elements in the following form:
Note:
See TracChangeset
for help on using the changeset viewer.
