Changeset 6124
- Timestamp:
- Jan 21, 2006, 12:23:58 AM (21 years ago)
- Location:
- branches/eam_rel9_p0/psModules/src/astrom
- Files:
-
- 7 edited
-
pmChipMosaic.c (modified) (4 diffs)
-
pmConcepts.c (modified) (2 diffs)
-
pmConceptsRead.c (modified) (4 diffs)
-
pmConceptsStandard.c (modified) (2 diffs)
-
pmConceptsWrite.c (modified) (5 diffs)
-
pmFPARead.c (modified) (3 diffs)
-
pmFPAWrite.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_rel9_p0/psModules/src/astrom/pmChipMosaic.c
r6113 r6124 131 131 } 132 132 133 134 // Set the concepts in the new cell, based on the values in the old one 135 static bool cellConcepts(pmCell *target,// Target cell 136 psArray *sources, // Source cells 137 int xBin, int yBin // Binning 138 ) 139 { 140 bool success = true; // Result of setting everything 141 float gain = 0.0; // Gain 142 float readnoise = 0.0; // Read noise 143 float saturation = 0.0; // Saturation level 144 float bad = 0.0; // Bad level 145 float exposure = 0.0; // Exposure time 146 float darktime = 0.0; // Dark time 147 double time = 0.0; // Time of observation 148 psTimeType timeSys = 0; // Time system 149 150 int nCells = 0; // Number of cells; 151 for (int i = 0; i < sources->n; i++) { 152 pmCell *cell = sources->data[i];// The cell of interest 153 if (!cell) { 154 continue; 155 } 156 nCells++; 157 gain += psMetadataLookupF32(NULL, cell->concepts, "CELL.GAIN"); 158 readnoise += psMetadataLookupF32(NULL, cell->concepts, "CELL.READNOISE"); 159 saturation += psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION"); 160 bad += psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD"); 161 exposure += psMetadataLookupF32(NULL, cell->concepts, "CELL.EXPOSURE"); 162 darktime += psMetadataLookupF32(NULL, cell->concepts, "CELL.DARKTIME"); 163 time += psTimeToMJD(psMetadataLookupPtr(NULL, cell->concepts, "CELL.TIME")); 164 if (i == 0) { 165 timeSys = psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS"); 166 } else if (timeSys != psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS")) { 167 psLogMsg(__func__, PS_LOG_ERROR, "Differing time systems in use: %d vs %d\n", timeSys, 168 psMetadataLookupS32(NULL, cell->concepts, "CELL.TIMESYS")); 169 success = false; 170 } 171 } 172 gain /= (float)nCells; 173 readnoise /= (float)nCells; 174 saturation /= (float)nCells; 175 bad /= (float)nCells; 176 exposure /= (float)nCells; 177 darktime /= (float)nCells; 178 psTime *timePtr = psTimeFromMJD(time/(double)nCells); 179 timePtr = psTimeConvert(timePtr, timeSys); 180 181 // XXX *REALLY* need a generic "concept update" function that handles the type and comments transparently. 182 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.GAIN", PS_META_REPLACE, "Gain (e/ADU)", gain); 183 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.READNOISE", PS_META_REPLACE, "Read noise (e)", readnoise); 184 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.SATURATION", PS_META_REPLACE, "Saturation level (ADU)", saturation); 185 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.BAD", PS_META_REPLACE, "Bad level (ADU)", bad); 186 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.EXPOSURE", PS_META_REPLACE, "Exposure time (sec)", exposure); 187 psMetadataAddF32(target->concepts, PS_LIST_TAIL, "CELL.DARKTIME", PS_META_REPLACE, "Time since last CCD flush (sec)", darktime); 188 psMetadataAddPtr(target->concepts, PS_LIST_TAIL, "CELL.TIME", PS_DATA_TIME | PS_META_REPLACE, "Time of observation", timePtr); 189 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.TIMESYS", PS_META_REPLACE, "Time system", timeSys); 190 psFree(timePtr); 191 192 // Now fill in the ones I know by other means 193 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.X0", PS_META_REPLACE, "Position of (0,0) on the chip", 0); 194 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.Y0", PS_META_REPLACE, "Position of (0,0) on the chip", 0); 195 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.XPARITY", PS_META_REPLACE, "Orientation in x compared to the rest of the FPA", 1); 196 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.YPARITY", PS_META_REPLACE, "Orientation in x compared to the rest of the FPA", 1); 197 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.XBIN", PS_META_REPLACE, "Binning in x", xBin); 198 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.YBIN", PS_META_REPLACE, "Binning in x", yBin); 199 psMetadataAddS32(target->concepts, PS_LIST_TAIL, "CELL.READDIR", PS_META_REPLACE, "Read direction (faked)", 1); 200 psRegion *trimsec = psMetadataLookupPtr(NULL, target->concepts, "CELL.TRIMSEC"); 201 trimsec->x0 = trimsec->x1 = trimsec->y0 = trimsec->y1 = 0.0; 202 203 return success; 204 } 205 206 207 133 208 // Mosaic a chip together into a single image 134 209 int pmChipMosaic(pmChip *chip,// Chip to mosaic … … 152 227 for (int i = 0; i < cells->n; i++) { 153 228 pmCell *cell = cells->data[i]; // The cell of interest 229 if (!cell) { 230 continue; 231 } 154 232 x0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.X0"); 155 233 y0->data.S32[i] = psMetadataLookupS32(NULL, cell->concepts, "CELL.Y0"); … … 206 284 psFree(masks); 207 285 int nCells = cells->n; 286 287 // Modify the "original" pixels 288 if (chip->parent->hdu) { 289 psLogMsg(__func__, PS_LOG_WARN, "The original format has the entire FPA in a single extension. " 290 "The FPA hierarchy may be invalid following the pmChipMosaic.\n"); 291 } else { 292 if (! chip->hdu) { 293 psString chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); 294 chip->hdu = p_pmHDUAlloc(chipName); 295 } 296 p_pmHDU *hdu = chip->hdu; 297 psArrayElementsFree(hdu->images); 298 psArrayElementsFree(hdu->weights); 299 psArrayElementsFree(hdu->masks); 300 hdu->images = psArrayAlloc(1); 301 hdu->weights = psArrayAlloc(1); 302 hdu->masks = psArrayAlloc(1); 303 hdu->images->data[0] = image; 304 hdu->weights->data[0] = weight; 305 hdu->masks->data[0] = mask; 306 psMetadataAddS32(hdu->header, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "Number of columns", image->numCols); 307 psMetadataAddS32(hdu->header, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "Number of rows", image->numRows); 308 } 309 310 // Chop off all the component cells, and put in a new one 311 chip->cells = psArrayAlloc(0); 312 pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell 313 cellConcepts(cell, cells, xBinChip, yBinChip); 208 314 psFree(cells); 209 210 // Chop off all the component cells, and put in a new one211 315 212 316 #if 1 … … 214 318 // the double free is coming from. I'm going to drop the pointers on the array and create a memory 215 319 // leak. We can clean this up later, when we're not under as much pressure. 216 chip->cells = psArrayAlloc(0);217 320 #else 218 321 219 322 psArrayElementsFree(chip->cells); 220 chip->cells = psArrayRealloc(chip->cells, 0);221 323 chip->cells->n = 0; 222 324 #endif 223 325 224 pmCell *cell = pmCellAlloc(chip, NULL, __func__); // New cell225 326 cell->exists = true; 226 327 cell->process = true; 227 328 pmReadout *readout = pmReadoutAlloc(cell); // New readout 228 readout->image = image; 229 readout->weight = weight; 230 readout->mask = mask; 231 //psFree(readout); 329 psRegion entire = {0.0, 0.0, 0.0, 0.0}; 330 // Want the readouts to contain a subimage, but that subimage is the whole image. 331 // This preserves the relationship there was before, where freeing the parent frees the child. 332 readout->image = psImageSubset(image, entire); 333 readout->weight = psImageSubset(weight, entire); 334 readout->mask = psImageSubset(mask, entire); 335 psFree(readout); 336 337 // Well, we've stuffed around with the camera configuration, so it's no longer valid... 338 #if 0 339 340 psFree(chip->parent->camera); 341 chip->parent->camera = NULL; 342 #endif 232 343 233 344 return nCells; -
branches/eam_rel9_p0/psModules/src/astrom/pmConcepts.c
r6080 r6124 1 // XXX *REALLY* need generic "concept update" and "concept read" functions that handles the type transparently 2 1 3 #include <stdio.h> 2 4 #include <assert.h> … … 156 158 { 157 159 pmConceptsInit(); 160 if (! fpa->camera) { 161 return false; 162 } 158 163 psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL); // Iterator on concepts 159 164 psMetadataItem *item = NULL; // Item from the concepts -
branches/eam_rel9_p0/psModules/src/astrom/pmConceptsRead.c
r6062 r6124 275 275 "undefined.\n", name, item->comment, item->type); 276 276 } 277 psTrace(__func__, 7, "Adding %s (%s): %f\n", name, item->comment, value); 277 278 } else { 278 279 psError(PS_ERR_IO, true, "Concept %s is not defined.\n", name); 279 280 } 280 psTrace(__func__, 7, "Adding %s (%s): %f\n", name, item->comment, value);281 281 282 282 return value; … … 309 309 "--- treating as undefined.\n", name, item->comment, item->type); 310 310 } 311 psTrace(__func__, 7, "Adding %s (%s): %f\n", name, item->comment, value); 311 312 } else { 312 313 psError(PS_ERR_IO, true, "Concept %s is not defined.\n", name); 313 314 } 314 psTrace(__func__, 7, "Adding %s (%s): %f\n", name, item->comment, value);315 315 316 316 return value; … … 345 345 "undefined.\n", name, item->comment, item->type); 346 346 } 347 psTrace(__func__, 7, "Read concept %s (%s): %d\n", name, item->comment, value); 347 348 } else { 348 349 psError(PS_ERR_IO, true, "Concept %s is not defined.\n", name); 349 350 } 350 psTrace(__func__, 7, "Read concept %s (%s): %d\n", name, item->comment, value);351 351 352 352 return value; … … 377 377 "undefined.\n", name, item->comment, item->type); 378 378 } 379 psTrace(__func__, 7, "Read concept %s (%s): %s\n", name, item->comment, value); 379 380 } else { 380 381 psError(PS_ERR_IO, true, "Concept %s is not defined.\n", name); 381 382 value = psStringCopy(""); 382 383 } 383 psTrace(__func__, 7, "Read concept %s (%s): %s\n", name, item->comment, value);384 384 385 385 return value; -
branches/eam_rel9_p0/psModules/src/astrom/pmConceptsStandard.c
r6080 r6124 321 321 { 322 322 psList *biassecs = psListAlloc(NULL); // List of bias sections 323 psMetadataItem *item = psMetadataItemAlloc("CELL.BIASSEC", PS_DATA_LIST, "Bias sections", biassecs); 324 psFree(biassecs); // Drop reference 323 325 324 326 psMetadataItem *secItem = pmConceptRead(fpa, chip, cell, db, "CELL.BIASSEC"); 325 327 if (! secItem) { 326 328 psError(PS_ERR_IO, false, "Couldn't find CELL.BIASSEC.\n"); 327 } else if (secItem->type != PS_DATA_STRING) { 329 return item; 330 } 331 if (secItem->type != PS_DATA_STRING) { 328 332 psError(PS_ERR_IO, true, "CELL.BIASSEC is not of type STR (%x)\n", secItem->type); 329 } else { 330 psString sections = secItem->data.V; // The section string 331 332 psMetadataItem *sourceItem = pmConceptRead(fpa, chip, cell, db, "CELL.BIASSEC.SOURCE"); 333 if (! sourceItem) { 334 psError(PS_ERR_IO, false, "Couldn't find CELL.BIASSEC.SOURCE.\n"); 335 } else if (sourceItem->type != PS_DATA_STRING) { 336 psError(PS_ERR_IO, true, "CELL.BIASSEC.SOURCE is not of type STR (%x)\n", sourceItem->type); 333 return item; 334 } 335 336 psString sections = secItem->data.V; // The section string 337 338 psMetadataItem *sourceItem = pmConceptRead(fpa, chip, cell, db, "CELL.BIASSEC.SOURCE"); 339 if (! sourceItem) { 340 psError(PS_ERR_IO, false, "Couldn't find CELL.BIASSEC.SOURCE.\n"); 341 return item; 342 } else if (sourceItem->type != PS_DATA_STRING) { 343 psError(PS_ERR_IO, true, "CELL.BIASSEC.SOURCE is not of type STR (%x)\n", sourceItem->type); 344 return item; 345 } 346 347 psString source = sourceItem->data.V; // The source string 348 349 if (! strcasecmp(source, "NONE")) { 350 return item; // There is no biassec 351 } 352 353 psList *secList = psStringSplit(sections, " ;"); // List of sections 354 psListIterator *secIter = psListIteratorAlloc(secList, PS_LIST_HEAD, false); // Iterator over 355 // sections 356 psString aSection = NULL; // A section from the list 357 while ((aSection = psListGetAndIncrement(secIter))) { 358 psRegion *region = psAlloc(sizeof(psRegion)); // Make space for a psRegion (usually passed by 359 // value) 360 361 if (strcasecmp(source, "VALUE") == 0) { 362 *region = psRegionFromString(aSection); 363 } else if (strcasecmp(source, "HEADER") == 0) { 364 psMetadata *header = NULL; // The FITS header 365 if (cell->hdu) { 366 header = cell->hdu->header; 367 } else if (chip->hdu) { 368 header = chip->hdu->header; 369 } else if (fpa->hdu) { 370 header = fpa->hdu->header; 371 } 372 if (! header) { 373 psError(PS_ERR_IO, true, "Unable to find FITS header!\n"); 374 *region = psRegionSet(0.0,0.0,0.0,0.0); 375 } else { 376 bool mdok = true; // Status of MD lookup 377 psString secValue = psMetadataLookupStr(&mdok, header, aSection); 378 if (! mdok || ! secValue) { 379 psError(PS_ERR_IO, false, "Unable to locate header %s\n", aSection); 380 *region = psRegionSet(0.0,0.0,0.0,0.0); 381 } else { 382 *region = psRegionFromString(secValue); 383 } 384 } 337 385 } else { 338 psString source = sourceItem->data.V; // The source string 339 340 psList *secList = psStringSplit(sections, " ;"); // List of sections 341 psListIterator *secIter = psListIteratorAlloc(secList, PS_LIST_HEAD, false); // Iterator over 342 // sections 343 psString aSection = NULL; // A section from the list 344 while ((aSection = psListGetAndIncrement(secIter))) { 345 psRegion *region = psAlloc(sizeof(psRegion)); // Make space for a psRegion (usually passed 346 // by value) 347 348 if (strcasecmp(source, "VALUE") == 0) { 349 *region = psRegionFromString(aSection); 350 } else if (strcasecmp(source, "HEADER") == 0) { 351 psMetadata *header = NULL; // The FITS header 352 if (cell->hdu) { 353 header = cell->hdu->header; 354 } else if (chip->hdu) { 355 header = chip->hdu->header; 356 } else if (fpa->hdu) { 357 header = fpa->hdu->header; 358 } 359 if (! header) { 360 psError(PS_ERR_IO, true, "Unable to find FITS header!\n"); 361 *region = psRegionSet(0.0,0.0,0.0,0.0); 362 } else { 363 bool mdok = true; // Status of MD lookup 364 psString secValue = psMetadataLookupStr(&mdok, header, aSection); 365 if (! mdok || ! secValue) { 366 psError(PS_ERR_IO, false, "Unable to locate header %s\n", aSection); 367 *region = psRegionSet(0.0,0.0,0.0,0.0); 368 } else { 369 *region = psRegionFromString(secValue); 370 } 371 } 372 } else { 373 psError(PS_ERR_IO, true, "CELL.BIASSEC.SOURCE (%s) is not HEADER or VALUE --- trying " 374 "VALUE.\n", source); 375 *region = psRegionFromString(aSection); 376 } // Value of CELL.BIASSEC.SOURCE 377 378 psListAdd(biassecs, PS_LIST_TAIL, region); 379 psFree(region); 380 } // Iterating over multiple sections 381 psFree(secIter); 382 psFree(secList); 383 } // Looking up CELL.BIASSEC.SOURCE 384 } // Looking up CELL.BIASSEC 385 386 psMetadataItem *item = psMetadataItemAlloc("CELL.BIASSEC", PS_DATA_LIST, "Bias sections", biassecs); 387 psFree(biassecs); 386 psError(PS_ERR_IO, true, "CELL.BIASSEC.SOURCE (%s) is not HEADER or VALUE --- trying " 387 "VALUE.\n", source); 388 *region = psRegionFromString(aSection); 389 } // Value of CELL.BIASSEC.SOURCE 390 391 psListAdd(biassecs, PS_LIST_TAIL, region); 392 psFree(region); 393 } // Iterating over multiple sections 394 psFree(secIter); 395 psFree(secList); 396 388 397 return item; 389 398 } … … 689 698 psMetadataItem *biassecItem = psMetadataLookup(cell->concepts, "CELL.BIASSEC"); 690 699 psList *biassecs = biassecItem->data.V; // The biassecs region list 700 701 if (biassecs->n == 0) { 702 psMetadataItem *noneItem = psMetadataItemAllocStr("CELL.BIASSEC", "Bias section", "NONE"); 703 pmConceptWriteItem(fpa, chip, cell, db, noneItem); 704 return true; 705 } 706 691 707 psString source = pmConceptReadString(fpa, chip, cell, db, "CELL.TRIMSEC.SOURCE"); // The source string 692 708 -
branches/eam_rel9_p0/psModules/src/astrom/pmConceptsWrite.c
r6062 r6124 73 73 ) 74 74 { 75 if (! cell->camera) { 76 return false; 77 } 75 78 if (cell) { 76 79 psMetadataItem *item = psMetadataLookup(cell->camera, concept->name); // Info we want … … 90 93 bool mdok = true; // Status of MD lookup 91 94 bool status = false; // Status of setting header 95 if (! fpa->camera) { 96 return false; 97 } 92 98 psMetadata *translation = psMetadataLookupMD(&mdok, fpa->camera, "TRANSLATION"); // FITS translation 93 99 if (! mdok) { … … 158 164 { 159 165 bool mdOK = true; // Status of MD lookup 166 if (! fpa->camera) { 167 return false; 168 } 160 169 psMetadata *defaults = psMetadataLookupMD(&mdOK, fpa->camera, "DEFAULTS"); 161 170 if (! mdOK || ! defaults) { … … 224 233 225 234 bool mdStatus = true; // Status of MD lookup 235 if (! fpa->camera) { 236 return false; 237 } 226 238 psMetadata *database = psMetadataLookupMD(&mdStatus, fpa->camera, "DATABASE"); 227 239 if (! mdStatus) { … … 319 331 ) 320 332 { 333 if (! fpa->camera) { 334 return false; 335 } 336 321 337 // Try headers, database, defaults in order 322 338 psTrace(__func__, 3, "Trying to set concept %s...\n", concept->name); -
branches/eam_rel9_p0/psModules/src/astrom/pmFPARead.c
r6080 r6124 161 161 162 162 // Read in.... 163 psTrace(__func__, 1, " Working onFPA...\n");163 psTrace(__func__, 1, "Reading FPA...\n"); 164 164 if (fpa->hdu) { 165 165 hdu = fpa->hdu; … … 217 217 } 218 218 } 219 psTrace(__func__, 5, "Reading concepts for cell %d...\n", j); 219 220 pmConceptsReadCell(cell, db); 220 221 221 psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n", 222 i, j); 222 psTrace(__func__, 5, "Allocating readouts for chip %d cell %d...\n", i, j); 223 223 generateReadouts(cell, hdu); 224 224 … … 227 227 chip->exists = true; 228 228 } 229 230 psTrace(__func__, 1, "Done reading FPA...\n"); 229 231 230 232 return true; -
branches/eam_rel9_p0/psModules/src/astrom/pmFPAWrite.c
r6062 r6124 27 27 { 28 28 bool status = true; // Status of writing, to return 29 30 psTrace(__func__, 1, "Writing FPA...\n"); 29 31 30 32 psTrace(__func__, 7, "Outgesting FPA concepts...\n"); … … 70 72 } 71 73 72 74 psTrace(__func__, 1, "Done writing FPA...\n"); 73 75 74 76 return status;
Note:
See TracChangeset
for help on using the changeset viewer.
