Changeset 4694
- Timestamp:
- Aug 1, 2005, 2:21:14 PM (21 years ago)
- Location:
- trunk/archive/scripts/src
- Files:
-
- 2 added
- 10 edited
-
Makefile (modified) (1 diff)
-
megacam_raw.config (modified) (1 diff)
-
megacam_splice.config (modified) (1 diff)
-
papFocalPlane.c (modified) (14 diffs)
-
papFocalPlane.h (modified) (5 diffs)
-
papmodule.h (modified) (1 diff)
-
pmFPAConstruct.c (modified) (17 diffs)
-
pmFPAMorph.c (added)
-
pmFPAMorph.h (added)
-
pmFPARead.c (modified) (9 diffs)
-
pmFPARead.h (modified) (1 diff)
-
test_pmFPARead.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/Makefile
r4309 r4694 8 8 BUILD_TARGET = test_pmFPAfromHeader 9 9 10 READ_OBJS = test_pmFPARead.o pmCameraFromHeader.o pmFPARead.o papFocalPlane.o psAdditionals.o papStuff.o 10 READ_OBJS = test_pmFPARead.o pmCameraFromHeader.o pmFPARead.o papFocalPlane.o psAdditionals.o papStuff.o \ 11 pmFPAConstruct.o pmFPAMorph.o pmFPAWrite.o 11 12 READ_TARGET = test_pmFPARead 12 13 -
trunk/archive/scripts/src/megacam_raw.config
r4395 r4694 125 125 # Default PS concepts that may be specified by value 126 126 DEFAULTS METADATA 127 CELL.READDIR S32 1 # Cell is read in x direction 127 128 CELL.BAD S32 0 129 # CELL.YPARITY S32 1 130 # This doesn't work, yet. 128 131 CELL.YPARITY_DEPEND STR CHIP.NAME 129 132 CELL.YPARITY METADATA -
trunk/archive/scripts/src/megacam_splice.config
r4395 r4694 88 88 # Default PS concepts that may be specified by value 89 89 DEFAULTS METADATA 90 CELL.READDIR S32 1 # Cell is read in x direction 90 91 CELL.BAD S32 0 91 92 CELL.XPARITY S32 1 -
trunk/archive/scripts/src/papFocalPlane.c
r4386 r4694 254 254 } 255 255 256 psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell 257 const char *chipName, // The name of the chip 258 const char *cellName, // The name of the cell 256 psMetadataItem *psCellGetValue(papCell *cell, // The cell 259 257 const char *valueName // Name of value 260 258 ) 261 259 { 262 psTrace(__func__, 3, "Trying to retrieve %s for %s:%s...\n", valueName, chipName, cellName); 263 264 bool mdStatus = true; // Status of MD lookup 265 papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip 266 if (!mdStatus) { 267 psError(PS_ERR_IO, false, "Unable to find chip named %s\n", chipName); 268 return NULL; 269 } 270 papCell *cell = psMetadataLookupCell(&mdStatus, chip->cells, cellName); // The cell 271 if (!mdStatus) { 272 psError(PS_ERR_IO, false, "Unable to find cell named %s in chip %s\n", cellName, chipName); 273 return NULL; 274 } 260 psTrace(__func__, 3, "Trying to retrieve %s...\n", valueName); 261 262 papChip *chip = cell->parent; // The chip 263 papFPA *fpa = chip->parent; // The FPA 275 264 276 265 // Try cache, headers, database, defaults in order … … 293 282 } 294 283 295 float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell 296 const char *chipName, // The name of the chip 297 const char *cellName, // The name of the cell 284 float psCellGetValueF32(papCell *cell, // The cell 298 285 const char *valueName // Name of value 299 286 ) 300 287 { 301 288 float value = NAN; // Result 302 psMetadataItem *item = psCellGetValue( fpa, chipName, cellName, valueName); // The item303 if (! item) { 304 psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);289 psMetadataItem *item = psCellGetValue(cell, valueName); // The item 290 if (! item) { 291 psError(PS_ERR_IO, true, "Unable to find value %s in cell.\n", valueName); 305 292 } else if (item->type != PS_META_F32) { 306 psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not F32.\n", valueName, chipName, 307 cellName); 293 psError(PS_ERR_IO, true, "Metadata item type for %s is not F32.\n", valueName); 308 294 } else { 309 295 value = item->data.F32; … … 313 299 } 314 300 315 int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell 316 const char *chipName, // The name of the chip 317 const char *cellName, // The name of the cell 301 int psCellGetValueS32(papCell *cell, // The cell 318 302 const char *valueName // Name of value 319 303 ) 320 304 { 321 305 int value = 0; // Result 322 psMetadataItem *item = psCellGetValue( fpa, chipName, cellName, valueName); // The item323 if (! item) { 324 psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);306 psMetadataItem *item = psCellGetValue(cell, valueName); // The item 307 if (! item) { 308 psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName); 325 309 } else if (item->type != PS_META_S32) { 326 psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not S32.\n", valueName, chipName, 327 cellName); 310 psError(PS_ERR_IO, true, "Metadata item type for %s is not S32.\n", valueName); 328 311 } else { 329 312 value = item->data.S32; … … 334 317 335 318 336 double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell 337 const char *chipName, // The name of the chip 338 const char *cellName, // The name of the cell 319 double psCellGetValueF64(papCell *cell, // The cell 339 320 const char *valueName // Name of value 340 321 ) 341 322 { 342 323 double value = NAN; // Result 343 psMetadataItem *item = psCellGetValue( fpa, chipName, cellName, valueName); // The item344 if (! item) { 345 psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);324 psMetadataItem *item = psCellGetValue(cell, valueName); // The item 325 if (! item) { 326 psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName); 346 327 } else if (item->type != PS_META_F64) { 347 psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not F64.\n", valueName, chipName, 348 cellName); 328 psError(PS_ERR_IO, true, "Metadata item type for %s is not F64.\n", valueName); 349 329 } else { 350 330 value = item->data.F64; … … 355 335 356 336 357 psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell 358 const char *chipName, // The name of the chip 359 const char *cellName, // The name of the cell 337 psString psCellGetValueString(papCell *cell, // The cell 360 338 const char *valueName // Name of value 361 339 ) 362 340 { 363 341 psString value = NULL; // Result 364 psMetadataItem *item = psCellGetValue( fpa, chipName, cellName, valueName); // The item365 if (! item) { 366 psError(PS_ERR_IO, true, "Unable to find value %s in %s:%s.\n", valueName, chipName, cellName);342 psMetadataItem *item = psCellGetValue(cell, valueName); // The item 343 if (! item) { 344 psError(PS_ERR_IO, true, "Unable to find value %s.\n", valueName); 367 345 } else if (item->type != PS_META_STR) { 368 psError(PS_ERR_IO, true, "Metadata item type for %s (%s:%s) is not STR.\n", valueName, chipName, 369 cellName); 346 psError(PS_ERR_IO, true, "Metadata item type for %s is not STR.\n", valueName); 370 347 } else { 371 348 value = item->data.V; … … 394 371 fpa->camera = psMemIncrRefCounter((psPtr)camera); 395 372 fpa->db = db; 396 fpa->chips = psMetadataAlloc(); 397 373 fpa->chips = psArrayAlloc(0); 374 375 fpa->extname = NULL; 398 376 fpa->pixels = NULL; 399 377 fpa->header = NULL; … … 418 396 419 397 papChip *papChipAlloc(papFPA *fpa, // FPA to which the chip belongs 420 const char *name // Name of the chip398 psString name // Chip name 421 399 ) 422 400 { … … 424 402 psMemSetDeallocator(chip, (psFreeFcn)p_papChipFree); 425 403 426 // Push onto the FPA427 psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Chip added on allocation", chip);404 // Push onto the array of chips 405 fpa->chips = psArrayAdd(fpa->chips, 0, chip); 428 406 429 407 // Fill in the components … … 435 413 436 414 chip->values = psMetadataAlloc(); 437 chip->cells = psMetadataAlloc(); 438 415 chip->parent = psMemIncrRefCounter(fpa); 416 chip->cells = psArrayAlloc(0); 417 418 chip->extname = NULL; 439 419 chip->pixels = NULL; 440 420 chip->header = NULL; 441 421 442 psMetadataAdd(chip->values, PS_LIST_TAIL, "CHIP.NAME", PS_META_STR, "Name of the chip", 443 psStringCopy(name)); 422 psMetadataAddStr(chip->values, PS_LIST_HEAD, "CHIP.NAME", "Chip name added at papChipAlloc", name); 444 423 445 424 return chip; … … 453 432 psFree(chip->values); 454 433 psFree(chip->cells); 434 psFree(chip->parent); 455 435 456 436 psFree(chip->pixels); … … 459 439 460 440 papCell *papCellAlloc(papChip *chip, // Chip to which the cell belongs 461 const char *name, // Name of the cell 462 int nReadouts // Number of readouts contained 441 psString name // Name of cell 463 442 ) 464 443 { … … 466 445 psMemSetDeallocator(cell, (psFreeFcn)p_papCellFree); 467 446 468 // Push onto the chip469 psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Cell added on allocation", cell);447 // Push onto the array of chips 448 chip->cells = psArrayAdd(chip->cells, 0, cell); 470 449 471 450 // Fill in components … … 480 459 481 460 cell->values = psMetadataAlloc(); 482 cell->readouts = psArrayAlloc(nReadouts); 483 461 cell->readouts = psArrayAlloc(0); 462 cell->parent = psMemIncrRefCounter(chip); 463 464 cell->extname = NULL; 484 465 cell->pixels = NULL; 485 466 cell->header = NULL; 486 467 487 psMetadataAdd(cell->values, PS_LIST_TAIL, "CELL.NAME", PS_META_STR, "Name of the cell", 488 psStringCopy(name)); 468 psMetadataAddStr(cell->values, PS_LIST_HEAD, "CELL.NAME", "Cell name added at papCellAlloc", name); 489 469 490 470 return cell; … … 501 481 psFree(cell->values); 502 482 psFree(cell->readouts); 483 psFree(cell->parent); 503 484 504 485 psFree(cell->pixels); -
trunk/archive/scripts/src/papFocalPlane.h
r4386 r4694 18 18 const psMetadata *camera; // Camera configuration 19 19 psDB *db; // Database 20 ps Metadata *chips; // The chips (referred to by name)20 psArray *chips; // The chips 21 21 // FITS data 22 const char *extname; // Extension name, if it corresponds to this level 22 23 psArray *pixels; // The pixel data, if it corresponds to this level 23 24 psMetadata *header; // The FITS header, if it corresponds to this level … … 33 34 // Information 34 35 psMetadata *values; // Important values (cached) 35 psMetadata *cells; // The cells (referred to by name) 36 psArray *cells; // The cells (referred to by name) 37 papFPA *parent; // Parent FPA 36 38 // FITS data 39 const char *extname; // Extension name, if it corresponds to this level 37 40 psArray *pixels; // The pixel data, if it corresponds to this level 38 41 psMetadata *header; // The FITS header, if it corresponds to this level … … 52 55 psMetadata *values; // Important values (cached) 53 56 psArray *readouts; // The readouts (referred to by number) 57 papChip *parent; // Parent chip 54 58 // FITS data 59 const char *extname; // Extension name, if it corresponds to this level 55 60 psArray *pixels; // The pixel data, if it corresponds to this level 56 61 psMetadata *header; // The FITS header, if it corresponds to this level … … 74 79 75 80 // Look for a particular value for a given cell (referred to by FPA+chip+cell) 76 psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell 77 const char *chipName, // The name of the chip 78 const char *cellName, // The name of the cell 81 psMetadataItem *psCellGetValue(papCell *cell, // The cell 79 82 const char *valueName // Name of value 80 83 ); 81 84 82 85 // Type-specific functions provided as a convenience to the user 83 float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell 84 const char *chipName, // The name of the chip 85 const char *cellName, // The name of the cell 86 float psCellGetValueF32(papCell *cell, // The cell 86 87 const char *valueName // Name of value 87 88 ); 88 int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell 89 const char *chipName, // The name of the chip 90 const char *cellName, // The name of the cell 89 int psCellGetValueS32(papCell *cell, // The cell 91 90 const char *valueName // Name of value 92 91 ); 93 double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell 94 const char *chipName, // The name of the chip 95 const char *cellName, // The name of the cell 92 double psCellGetValueF64(papCell *cell, // The cell 96 93 const char *valueName // Name of value 97 94 ); 98 psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell 99 const char *chipName, // The name of the chip 100 const char *cellName, // The name of the cell 95 psString psCellGetValueString(papCell *cell, // The cell 101 96 const char *valueName // Name of value 102 97 ); … … 110 105 111 106 papChip *papChipAlloc(papFPA *fpa, // FPA to which the chip belongs 112 const char *name // Name of thechip107 psString name // Name of chip 113 108 ); 114 109 void p_papChipFree(papChip *chip); 115 110 116 111 papCell *papCellAlloc(papChip *chip, // Chip to which the cell belongs 117 const char *name, // Name of the cell 118 int nReadouts // Number of readouts contained 112 psString name // Name of cell 119 113 ); 120 114 void p_papCellFree(papCell *cell); -
trunk/archive/scripts/src/papmodule.h
r4386 r4694 2 2 3 3 #include "pmCameraFromHeader.h" 4 #include "pmFPAConstruct.h" 4 5 #include "pmFPARead.h" 5 6 #include "papStuff.h" 6 7 #include "psAdditionals.h" 7 8 #include "papFocalPlane.h" 9 #include "pmFPAMorph.h" 10 #include "pmFPAWrite.h" -
trunk/archive/scripts/src/pmFPAConstruct.c
r4594 r4694 81 81 // Extensions are chips; Content contains a list of cells 82 82 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 83 const char *extName = contentItem->name; // The name of the extension84 papChip *chip = papChipAlloc(fpa ); // The chip83 psString extName = contentItem->name; // The name of the extension 84 papChip *chip = papChipAlloc(fpa, extName); // The chip 85 85 chip->extname = extName;// Mark chip to receive FITS data 86 86 if (contentItem->type != PS_META_STR) { … … 97 97 while (cellName = psListGetAndIncrement(cellNamesIter)) { 98 98 // Get the cell data 99 papCell *cell = papCellAlloc(chip ); // The cell99 papCell *cell = papCellAlloc(chip, cellName); // The cell 100 100 psMetadata *cellData = getCellData(camera, cellName); 101 101 metadataCopy(cell->values, cellData); … … 109 109 psMetadata *chips = psMetadataAlloc(); // Given a chip name, holds the chip number 110 110 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 111 const char *extName = contentItem->name; // The name of the extension111 psString extName = contentItem->name; // The name of the extension 112 112 psTrace(__func__, 1, "Getting %s....\n", extName); 113 113 … … 122 122 psLogMsg(__func__, PS_LOG_WARN, "Unable to read contents of %s: ignored.\n", extName); 123 123 } else { 124 const char *chipName = psListGet(contents, 0); // The name of the chip125 const char *cellType = psListGet(contents, 1); // The type of cell124 psString chipName = psListGet(contents, 0); // The name of the chip 125 psString cellType = psListGet(contents, 1); // The type of cell 126 126 psTrace(__func__, 7, "Extension is cell of type %s, from chip %s\n", cellType, 127 127 chipName); … … 129 129 papChip *chip = psMetadataLookupChip(&mdStatus, chips, chipName); // The chip 130 130 if (! mdStatus && ! chip) { 131 chip = papChipAlloc(fpa );131 chip = papChipAlloc(fpa, chipName); 132 132 psMetadataAdd(chips, PS_LIST_TAIL, chipName, PS_META_CHIP, "", chip); 133 133 } … … 135 135 psArray *images = NULL; 136 136 psMetadata *header = NULL; 137 papCell *cell = papCellAlloc(chip ); // The cell137 papCell *cell = papCellAlloc(chip, extName); // The cell 138 138 cell->extname = extName; // Mark cell to receive FITS data 139 139 psMetadata *cellData = getCellData(camera, cellType); … … 147 147 fpa->extname = "PHU"; 148 148 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 149 const char *chipName = contentItem->name; // The name of the chip149 psString chipName = contentItem->name; // The name of the chip 150 150 151 151 if (contentItem->type != PS_META_STR) { … … 154 154 continue; 155 155 } 156 const char *content = contentItem->data.V; // The content of the extension156 psString content = contentItem->data.V; // The content of the extension 157 157 psTrace(__func__, 5, "Component cells are: %s\n", content); 158 papChip *chip = papChipAlloc(fpa ); // The chip158 papChip *chip = papChipAlloc(fpa, chipName); // The chip 159 159 psList *cellNames = papSplit(content, ", "); // Split the list of cells 160 160 psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); … … 162 162 while (cellName = psListGetAndIncrement(cellNamesIter)) { 163 163 psTrace(__func__, 7, "Processing cell %s....\n", cellName); 164 papCell *cell = papCellAlloc(chip ); // The cell164 papCell *cell = papCellAlloc(chip, cellName); // The cell 165 165 psMetadata *cellData = getCellData(camera, cellName); 166 166 metadataCopy(cell->values, cellData); … … 179 179 } else if (strncmp(phuType, "CHIP", 4) == 0) { 180 180 // The FITS file contains a single chip only 181 papChip *chip = papChipAlloc(fpa); // The chip 181 psString chipName = psStringCopy("CHIP"); // Name for chip 182 papChip *chip = papChipAlloc(fpa, chipName); // The chip 182 183 183 184 if (strncmp(extType, "NONE", 4) == 0) { … … 193 194 psList *cellNames = papSplit(contents, " ,"); // Names of cells 194 195 psListIterator *cellIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); // Iterator 195 const char *cellName = NULL;196 psString cellName = NULL; 196 197 while (cellName = psListGetAndIncrement(cellIter)) { 197 papCell *cell = papCellAlloc(chip ); // The cell198 papCell *cell = papCellAlloc(chip, cellName); // The cell 198 199 psMetadata *cellData = getCellData(camera, cellName); 199 200 metadataCopy(cell->values, cellData); … … 219 220 psMetadataItem *contentItem = NULL; // Item from metadata 220 221 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 221 const char *extName = contentItem->name; // The name of the extension 222 223 psMemCheckCorruption(true); 224 225 psTrace(__func__, 1, "Getting %s....\n", extName); 226 222 psString extName = contentItem->name; // The name of the extension 227 223 // Content is a cell type 228 224 if (contentItem->type != PS_META_STR) { … … 233 229 } 234 230 const char *cellType = contentItem->data.V; // The type of cell 235 psTrace(__func__, 2, "Cell type is %s\n", cellType);231 psTrace(__func__, 5, "Cell type is %s\n", cellType); 236 232 psArray *images = NULL; 237 233 psMetadata *header = NULL; 238 papCell *cell = papCellAlloc(chip ); // The cell234 papCell *cell = papCellAlloc(chip, extName); // The cell 239 235 cell->extname = extName; // Mark cell to receive FITS data 240 236 psMetadata *cellData = getCellData(camera, cellType); … … 266 262 { 267 263 psTrace(__func__, 0, "FPA:\n"); 268 if (fpa->pixels) { 269 psTrace(__func__, 1, "---> FPA contains pixels.\n"); 264 if (fpa->extname) { 265 psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->extname); 266 if (! fpa->pixels) { 267 psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->extname); 268 } 270 269 } 271 270 … … 275 274 psTrace(__func__, 1, "Chip: %d\n", i); 276 275 papChip *chip = chips->data[i]; // The chip 277 if (chip->pixels) { 278 psTrace(__func__, 2, "---> Chip contains pixels.\n"); 276 if (chip->extname) { 277 psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->extname); 278 if (! chip->pixels) { 279 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->extname); 280 } 279 281 } 280 282 // Iterate over the chip … … 283 285 psTrace(__func__, 2, "Cell: %d\n", j); 284 286 papCell *cell = cells->data[j]; // The cell 285 if (cell->pixels) { 286 psTrace(__func__, 3, "---> Cell contains pixels.\n"); 287 if (cell->extname) { 288 psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->extname); 289 if (! cell->pixels) { 290 psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->extname); 291 } 287 292 } 288 293 psMetadataPrint(cell->values, 3); … … 292 297 papReadout *readout = readouts->data[k]; // The readout 293 298 psImage *image = readout->image; // The image 294 psTrace(__func__, 4, "Image: [%d:%d,%d:%d]\n", image->col0, image->col0 + 295 image->numCols, image->row0, image->row0 + image->numRows); 299 psTrace(__func__, 4, "Image: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 + 300 image->numCols, image->row0, image->row0 + image->numRows, image->numCols, 301 image->numRows); 296 302 psList *overscans = readout->overscans; // The list of overscans 297 303 psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false); 298 304 while (image = psListGetAndIncrement(overscansIter)) { 299 psTrace(__func__, 4, "Overscan: [%d:%d,%d:%d]\n", image->col0, image->col0 + 300 image->numCols, image->row0, image->row0 + image->numRows); 305 psTrace(__func__, 4, "Overscan: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 + 306 image->numCols, image->row0, image->row0 + image->numRows, image->numCols, 307 image->numRows); 301 308 } 302 309 psFree(overscansIter); -
trunk/archive/scripts/src/pmFPARead.c
r4386 r4694 5 5 #include "papStuff.h" 6 6 #include "papFocalPlane.h" 7 #include "pmFPARead.h" 7 8 8 9 // NOTE: Need to deal with header inheritance … … 11 12 // File-static functions 12 13 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 13 14 // Copy metadata elements into another metadata15 static void metadataCopy(psMetadata *to, // Metadata to which to copy16 psMetadata *from // Metdata from which to copy17 )18 {19 psMetadataIterator *mdIter = psMetadataIteratorAlloc(from, PS_LIST_HEAD, NULL); // Iterator for the MD20 psMetadataItem *item = NULL; // Item from the metadata21 while (item = psMetadataGetAndIncrement(mdIter)) {22 psTrace(__func__, 9, "Adding %s to metadata...\n", item->name);23 if (! psMetadataAddItem(to, item, PS_LIST_TAIL, PS_META_REPLACE)) {24 psLogMsg(__func__, PS_LOG_WARN, "Unable to add item (%s: %s) to metadata: ignored\n", item->name,25 item->comment);26 }27 }28 psFree(mdIter);29 }30 31 // Read data for a particular cell from the camera configuration32 static psMetadata *getCellData(const psMetadata *camera, // The camera configuration33 const char *cellName // The name of the cell34 )35 {36 bool status = true; // Result of MD lookup37 psMetadata *cells = psMetadataLookupMD(&status, camera, "CELLS"); // The CELLS38 if (! status) {39 psError(PS_ERR_IO, false, "Unable to determine CELLS of camera.\n");40 return NULL;41 }42 43 psMetadata *cellData = psMetadataLookupMD(&status, cells, cellName); // The data for the particular cell44 if (! status) {45 psError(PS_ERR_IO, false, "Unable to find specs for cell %s: ignored\n", cellName);46 return NULL;47 } else {48 return cellData;49 }50 }51 14 52 15 // Read a FITS extension into a chip … … 57 20 ) 58 21 { 22 psTrace(__func__, 7, "Moving to extension %s...\n", extName); 59 23 if (strncmp(extName, "PHU", 3) == 0) { 60 24 if (!psFitsMoveExtNum(fits, 0, false)) { … … 66 30 return false; 67 31 } 32 psTrace(__func__, 7, "Reading header....\n"); 68 33 *header = psFitsReadHeader(*header, fits); 34 if (! *header) { 35 psError(PS_ERR_IO, false, "Unable to read FITS header!\n"); 36 return false; 37 } 38 39 psTrace(__func__, 7, "Checking NAXIS....\n"); 69 40 bool mdStatus = false; 70 41 int nAxis = psMetadataLookupS32(&mdStatus, *header, "NAXIS"); … … 77 48 "anyway.\n"); 78 49 } 50 psTrace(__func__, 9, "NAXIS = %d\n", nAxis); 79 51 80 52 int numPlanes = 1; // Number of planes … … 89 61 90 62 // Read each plane into the array 63 psTrace(__func__, 7, "Reading %d planes into array....\n", numPlanes); 91 64 *images = psArrayAlloc(numPlanes); // Array of images 92 65 for (int i = 0; i < numPlanes; i++) { 93 (*images)->data[i] = psFitsReadImage((*images)->data[i], fits, region, 0); 66 psTrace(__func__, 9, "Reading plane %d\n", i); 67 psMemCheckCorruption(true); 68 (*images)->data[i] = psFitsReadImage(NULL, fits, region, i); 69 psTrace(__func__, 10, "Done\n"); 94 70 if (! (*images)->data[i]) { 95 71 psError(PS_ERR_IO, false, "Unable to read image for extension %s, plane %d\n", extName, i); … … 119 95 region.y1); 120 96 numFound++; 97 // Convert from FITS standard to PS standard 98 region.x0 -= 1; 99 region.y0 -= 1; 100 // We don't touch the x1 and y1 values because they aren't included by psImageSubset. 121 101 psImage *subImage = psImageSubset(image, region); 122 102 psListAdd(list, PS_LIST_TAIL, subImage); … … 166 146 // We have the region: [x0:x1,y0:y1] 167 147 psRegion region = psRegionFromString(regionString); 148 // Convert from FITS standard to PS standard 149 region.x0 -= 1; 150 region.y0 -= 1; 151 // We don't touch the x1 and y1 values because they aren't included by psImageSubset. 168 152 psImage *subImage = psImageSubset(image, region); 169 153 psListAdd(subImages, PS_LIST_TAIL, subImage); … … 251 235 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 252 236 253 papFPA *pmFPARead(psFits *fits, // A FITS file 254 const psMetadata *camera, // The camera configuration 255 psDB *db // Database 256 ) 257 { 258 papFPA *fpa = papFPAAlloc(camera, db); // The FPA to fill out 259 bool mdStatus = true; // Status from metadata lookups 260 const char *phuType = psMetadataLookupString(&mdStatus, camera, "PHU"); // What is the PHU? 261 const char *extType = psMetadataLookupString(&mdStatus, camera, "EXTENSIONS"); // What's in the extensions? 262 if (strncmp(phuType, "FPA", 3) == 0) { 263 // The FITS file contains an entire FPA 264 265 psMetadata *contents = psMetadataLookupMD(&mdStatus, camera, "CONTENTS"); // The CONTENTS 266 if (! mdStatus) { 267 psError(PS_ERR_IO, false, "Unable to determine CONTENTS of camera.\n"); 268 psFree(fpa); 269 return NULL; 270 } 271 272 // Set up iteration over the contents 273 psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL); 274 psMetadataItem *contentItem = NULL; // Item from the metadata 275 276 if (strncmp(extType, "CHIP", 4) == 0) { 277 // Extensions are chips; Content contains a list of cells 278 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 279 const char *extName = contentItem->name; // The name of the extension 280 papChip *chip = papChipAlloc(fpa, extName); // The chip 281 readExtension(&(chip->pixels), &(chip->header), fits, extName); 282 if (contentItem->type != PS_META_STR) { 283 psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n", 284 contentItem->type); 285 } else { 286 const char *content = contentItem->data.V; // The content of the extension 287 psTrace(__func__, 7, "Content of %s is: %s\n", extName, content); 288 psList *cellNames = papSplit(content, " ,"); // A list of the component cells 289 psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, NULL); 290 char *cellName = NULL; // The name of a cell 291 while (cellName = psListGetAndIncrement(cellNamesIter)) { 292 // Get the cell data 293 papCell *cell = papCellAlloc(chip, cellName, ((psArray*)chip->pixels)->n); // The cell 294 psMetadata *cellData = getCellData(camera, cellName); 295 metadataCopy(cell->values, cellData); 296 portionCell(cell, chip->pixels, chip->header); 297 } 298 psFree(cellNamesIter); 299 psFree(cellNames); 237 bool pmFPARead(papFPA *fpa, // FPA to read into 238 psFits *fits // FITS file from which to read 239 ) 240 { 241 psArray *pixels = NULL; // Current pixels from FITS file (array of images) 242 psMetadata *header = NULL; // Current header from FITS file 243 244 psTrace(__func__, 1, "Working on FPA...\n"); 245 if (fpa->extname) { 246 psTrace(__func__, 3, "Reading pixels from extension %s into FPA.\n", fpa->extname); 247 if (! readExtension(&fpa->pixels, &fpa->header, fits, fpa->extname)) { 248 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", fpa->extname); 249 return false; 250 } 251 pixels = fpa->pixels; 252 header = fpa->header; 253 } 254 255 psArray *chips = fpa->chips; // Array of chips 256 // Iterate over the FPA 257 for (int i = 0; i < chips->n; i++) { 258 papChip *chip = chips->data[i]; // The chip 259 psTrace(__func__, 2, "Working on chip %d...\n", i); 260 if (chip->extname) { 261 psTrace(__func__, 3, "Reading pixels from extension %s into chip %d.\n", chip->extname, i); 262 if (! readExtension(&chip->pixels, &chip->header, fits, chip->extname)) { 263 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", chip->extname); 264 return false; 265 } 266 pixels = chip->pixels; 267 header = chip->header; 268 } 269 // Iterate over the chip 270 psArray *cells = chip->cells; // Array of cells 271 for (int j = 0; j < cells->n; j++) { 272 papCell *cell = cells->data[j]; // The cell 273 psTrace(__func__, 3, "Working on cell %d...\n", j); 274 if (cell->extname) { 275 psTrace(__func__, 5, "Reading pixels from extension %s into cell %d.\n", cell->extname, j); 276 if (! readExtension(&cell->pixels, &cell->header, fits, cell->extname)) { 277 psError(PS_ERR_IO, false, "Unable to read pixels from extension %s\n", cell->extname); 278 return false; 300 279 } 301 } 302 303 } else if (strncmp(extType, "CELL", 4) == 0) { 304 // Extensions are cells; Content contains a chip name and cell type 305 psMetadata *chipNumbers = psMetadataAlloc(); // Given a chip name, holds the chip number 306 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 307 const char *extName = contentItem->name; // The name of the extension 308 psTrace(__func__, 1, "Getting %s....\n", extName); 309 310 if (contentItem->type != PS_META_STR) { 311 psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n", 312 contentItem->type); 313 } else { 314 const char *content = contentItem->data.V; // The content of the extension 315 psList *contents = papSplit(content, ": "); // Split the name from the type 316 if (contents->size != 2) { 317 psLogMsg(__func__, PS_LOG_WARN, "Unable to read contents of %s: ignored.\n", extName); 318 } else { 319 const char *chipName = psListGet(contents, 0); // The name of the chip 320 const char *cellType = psListGet(contents, 1); // The type of cell 321 psTrace(__func__, 7, "Extension is cell of type %s, from chip %s\n", cellType, 322 chipName); 323 324 papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip 325 if (! mdStatus && ! chip) { 326 chip = papChipAlloc(fpa, chipName); 327 } 328 // The cell 329 psArray *images = NULL; 330 psMetadata *header = NULL; 331 psTrace(__func__, 7, "Reading extension %s\n", extName); 332 readExtension(&images, &header, fits, extName); 333 psTrace(__func__, 7, "Allocating cell %s\n", cellType); 334 papCell *cell = papCellAlloc(chip, cellType, images->n); // The cell 335 cell->pixels = images; 336 cell->header = header; 337 psMetadata *cellData = getCellData(camera, cellType); 338 metadataCopy(cell->values, cellData); 339 psTrace(__func__, 7, "Portioning cell....\n"); 340 portionCell(cell, cell->pixels, cell->header); 341 psTrace(__func__, 7, "Done.\n"); 342 } 343 } 344 } 345 346 } else if (strncmp(extType, "NONE", 4) == 0) { 347 // No extensions; Content contains metadata, each entry is a chip with its component cells 348 readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU"); 349 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 350 const char *chipName = contentItem->name; // The name of the chip 351 352 if (contentItem->type != PS_META_STR) { 353 psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n", 354 contentItem->type); 355 } else { 356 const char *content = contentItem->data.V; // The content of the extension 357 papChip *chip = papChipAlloc(fpa, content); // The chip 358 psList *cellNames = papSplit(content, ", "); // Split the list of cells 359 psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); 360 char *cellName = NULL; // Name of the cell 361 while (cellName = psListGetAndIncrement(cellNamesIter)) { 362 papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell 363 psMetadata *cellData = getCellData(camera, cellName); 364 metadataCopy(cell->values, cellData); 365 portionCell(cell, fpa->pixels, fpa->header); 366 } 367 psFree(cellNamesIter); 368 } 369 } 370 371 } else { 372 psError(PS_ERR_IO, false, "EXTENSIONS in camera definition is not CHIP, CELL or NONE.\n"); 373 psFree(fpa); 374 return NULL; 375 } // Type of extension 376 377 psFree(contentsIter); 378 379 } else if (strncmp(phuType, "CHIP", 4) == 0) { 380 // The FITS file contains a single chip only 381 papChip *chip = papChipAlloc(fpa, "CHIP"); // The chip 382 383 if (strncmp(extType, "NONE", 4) == 0) { 384 // There are no extensions --- only the PHU 385 readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU"); 386 387 const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS"); 388 if (! mdStatus) { 389 psError(PS_ERR_IO, false, "Unable to determine CONTENTS of camera.\n"); 390 psFree(fpa); 391 return NULL; 392 } 393 psList *cellNames = papSplit(contents, " ,"); // Names of cells 394 psListIterator *cellIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); // Iterator 395 const char *cellName = NULL; 396 while (cellName = psListGetAndIncrement(cellIter)) { 397 papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell 398 psMetadata *cellData = getCellData(camera, cellName); 399 metadataCopy(cell->values, cellData); 400 portionCell(cell, fpa->pixels, fpa->header); 401 } 402 psFree(cellIter); 403 } else if (strncmp(extType, "CELL", 4) == 0) { 404 // Extensions are cells 405 psMetadata *contents = psMetadataLookupMD(&mdStatus, camera, "CONTENTS"); // The CONTENTS 406 if (! mdStatus) { 407 psError(PS_ERR_IO, false, "Unable to determine CONTENTS of camera.\n"); 408 psFree(fpa); 409 return NULL; 410 } 411 412 if (strncmp(extType, "CELL", 4) != 0) { 413 psLogMsg(__func__, PS_LOG_WARN, "EXTENSIONS in camera definition is %s, but PHU is CHIP.\n" 414 "EXTENSIONS assumed to be CELL.\n", extType); 415 } 416 417 // Iterate through the contents 418 psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL); 419 psMetadataItem *contentItem = NULL; // Item from metadata 420 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 421 const char *extName = contentItem->name; // The name of the extension 422 423 psMemCheckCorruption(true); 424 425 psTrace(__func__, 1, "Getting %s....\n", extName); 426 427 // Content is a cell type 428 if (contentItem->type != PS_META_STR) { 429 psLogMsg(__func__, PS_LOG_WARN, 430 "CONTENT metadata for extension %s is not of type string, but %x --- ignored\n", 431 extName, contentItem->type); 432 } else { 433 const char *cellType = contentItem->data.V; // The type of cell 434 psTrace(__func__, 2, "Cell type is %s\n", cellType); 435 psArray *images = NULL; 436 psMetadata *header = NULL; 437 readExtension(&images, &header, fits, extName); 438 papCell *cell = papCellAlloc(chip, extName, images->n); // The cell 439 cell->pixels = images; 440 cell->header = header; 441 psMetadata *cellData = getCellData(camera, cellType); 442 metadataCopy(cell->values, cellData); 443 portionCell(cell, cell->pixels, cell->header); 444 } 445 } // Iterating through contents 446 psFree(contentsIter); 447 448 } else { 449 psError(PS_ERR_IO, false, "EXTENSIONS in camera definition is neither CELL or NONE.\n"); 450 psFree(fpa); 451 return NULL; 452 } 453 454 } else { 455 psError(PS_ERR_IO, true, 456 "The PHU type specified in the camera configuration (%s) is not FPA or CHIP.\n", 457 phuType); 458 psFree(fpa); 459 return NULL; 460 } 461 462 return fpa; 463 } 464 465 void pmFPAPrint(papFPA *fpa // FPA to print 466 ) 467 { 468 // Print out the focal plane 469 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa->chips, PS_LIST_HEAD, NULL); // Iterator for FPA 470 psMetadataItem *fpaItem = NULL; // Item from metadata 471 psTrace("pmFPARead", 0, "FPA:\n"); 472 if (fpa->pixels) { 473 psTrace("pmFPARead", 1, "---> FPA contains pixels.\n"); 474 } 475 while (fpaItem = psMetadataGetAndIncrement(fpaIter)) { 476 if (fpaItem->type != PS_META_CHIP) { 477 psError(PS_ERR_IO, false, "FPA content is not a chip.\n"); 478 } else { 479 psTrace("pmFPARead", 1, "Chip: %s\n", fpaItem->name); 480 papChip *chip = fpaItem->data.V; // The chip 481 if (chip->pixels) { 482 psTrace("pmFPARead", 2, "---> Chip contains pixels.\n"); 483 } 484 // Iterator for chip 485 psMetadataIterator *chipIter = psMetadataIteratorAlloc(chip->cells, PS_LIST_HEAD, NULL); 486 psMetadataItem *chipItem = NULL; // Item from metadata 487 while (chipItem = psMetadataGetAndIncrement(chipIter)) { 488 if (chipItem->type != PS_META_CELL) { 489 psError(PS_ERR_IO, false, "Chip content is not a cell.\n"); 490 } else { 491 psTrace("pmFPARead", 2, "Cell: %s\n", chipItem->name); 492 papCell *cell = chipItem->data.V; // The cell 493 if (cell->pixels) { 494 psTrace("pmFPARead", 3, "---> Cell contains pixels.\n"); 495 } 496 // Iterator for cell values 497 psMetadataIterator *cellIter = psMetadataIteratorAlloc(cell->values, PS_LIST_HEAD, NULL); 498 psMetadataItem *cellItem = NULL; // Item from metadata 499 while (cellItem = psMetadataGetAndIncrement(cellIter)) { 500 switch(cellItem->type) { 501 case PS_META_STR: 502 psTrace("pmFPARead", 3, "%s: %s\n", cellItem->name, cellItem->data.V); 503 break; 504 case PS_META_F32: 505 psTrace("pmFPARead", 3, "%s: %f\n", cellItem->name, cellItem->data.F32); 506 break; 507 case PS_META_S32: 508 psTrace("pmFPARead", 3, "%s: %d\n", cellItem->name, cellItem->data.S32); 509 break; 510 case PS_META_META: 511 psTrace("pmFPARead", 3, "%s:\n", cellItem->name); 512 psMetadataPrint(cellItem->data.V, 4); 513 break; 514 default: 515 psError(PS_ERR_IO, false, "Unknown type for cell (%x).\n", cellItem->type); 516 } 517 } // Iterating through cell 518 psFree(cellIter); 519 520 // Iterator for cell 521 psTrace("pmFPARead", 3, "Readouts:\n"); 522 psArray *readouts = cell->readouts; // The readouts 523 for (int i = 0; i < readouts->n; i++) { 524 papReadout *readout = readouts->data[i]; // The readout 525 psImage *image = readout->image; // The image 526 psTrace("pmFPARead", 4, "Image: [%d:%d,%d:%d]\n", image->col0, image->col0 + 527 image->numCols, image->row0, image->row0 + image->numRows); 528 psList *overscans = readout->overscans; // The list of overscans 529 psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false); 530 while (image = psListGetAndIncrement(overscansIter)) { 531 psTrace("pmFPARead", 4, "Overscan: [%d:%d,%d:%d]\n", image->col0, image->col0 + 532 image->numCols, image->row0, image->row0 + image->numRows); 533 } 534 psFree(overscansIter); 535 } 536 } 537 } // Iterating through chip 538 psFree(chipIter); 539 } 540 } // Iterating through FPA 541 psFree(fpaIter); 542 } 280 pixels = cell->pixels; 281 header = cell->header; 282 } 283 284 psTrace(__func__, 5, "Allocating readouts and extracting overscans etc for chip %d cell %d...\n", 285 i, j); 286 portionCell(cell, pixels, header); 287 } 288 } 289 290 return true; 291 } -
trunk/archive/scripts/src/pmFPARead.h
r4386 r4694 4 4 #include "papFocalPlane.h" 5 5 6 // Read the contents of a FITS file (format specified by the camera configuration) into memory 7 papFPA *pmFPARead(psFits *fits, // A FITS file 8 const psMetadata *camera, // The camera configuration 9 psDB *db // Database handle 10 ); 11 12 // Print out the FPA 13 void pmFPAPrint(papFPA *fpa // FPA to print 14 ); 6 bool pmFPARead(papFPA *fpa, // FPA to read into 7 psFits *fits // FITS file from which to read 8 ); 15 9 16 10 #endif -
trunk/archive/scripts/src/test_pmFPARead.c
r4395 r4694 26 26 27 27 (void)psTraceSetLevel(".", 0); 28 (void)psTraceSetLevel("readExtension", 10); 28 29 (void)psTraceSetLevel("readMultipleRegions", 0); 29 30 (void)psTraceSetLevel("portions", 0); 30 (void)psTraceSetLevel("pmFPA Read", 10);31 (void)psTraceSetLevel("pmFPAPrint", 10); 31 32 (void)psTraceSetLevel("pmFPAfromHeader", 10); 32 33 (void)psTraceSetLevel("pmCameraFromHeader", 10); 33 34 (void)psTraceSetLevel("pmFPAMorph", 10); 35 (void)psTraceSetLevel("spliceCells", 10); 34 36 35 37 … … 53 55 psMetadata *camera = pmCameraFromHeader(header, ipprc); 54 56 55 papFPA *fpa = pmFPARead(fits, camera, NULL); 57 papFPA *fpa = pmFPAConstruct(camera, NULL); 58 59 // Cut off a lot of the chips so I can fit things in memory 60 { 61 psArray *chips = fpa->chips; 62 papChip *chip = chips->data[0]; 63 psFree(chips); 64 chips = psArrayAlloc(1); 65 chips->data[0] = chip; 66 } 67 68 (void)pmFPARead(fpa, fits); 56 69 (void)pmFPAPrint(fpa); 57 70 58 printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.XPARITY"), 59 psCellGetValueS32(fpa, "ccd15", "right", "CELL.XPARITY")); 60 printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.YPARITY"), 61 psCellGetValueS32(fpa, "ccd15", "right", "CELL.YPARITY")); 62 printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.YPARITY"), 63 psCellGetValueS32(fpa, "ccd15", "right", "CELL.YPARITY")); 71 // Morph to a splice image 72 psMetadata *newCamera = psMetadataConfigParse(NULL, &badLines, "megacam_splice.config", true); 73 papFPA *newfpa = pmFPAConstruct(newCamera, NULL); 74 75 // Cut off a lot of the chips so I can fit things in memory 76 { 77 psArray *chips = newfpa->chips; 78 papChip *chip = chips->data[0]; 79 psFree(chips); 80 chips = psArrayAlloc(1); 81 chips->data[0] = chip; 82 } 83 84 pmFPAPrint(newfpa); 85 pmFPAMorph(newfpa, fpa, 0, 0); 86 pmFPAPrint(newfpa); 87 88 #if 0 89 // Write out 90 psFits *newfits = psFitsAlloc("test.fits"); 91 pmFPAWrite(fits, newfpa); 92 psFree(newfits); 93 #endif 94 95 #if 1 96 psArray *chips = newfpa->chips; 97 for (int i = 0; i < chips->n; i++) { 98 papChip *chip = chips->data[i]; // Chip of interest 99 psArray *cells = chip->cells; // Array of cells 100 101 if (chip->extname) { 102 psFits *fp = psFitsAlloc(chip->extname); 103 psFitsWriteImage(fp, chip->header, chip->pixels->data[i], i); 104 psFree(fp); 105 } 106 107 for (int j = 0; j < cells->n; j++) { 108 papCell *cell = cells->data[j]; // Cell of interest 109 110 if (cell->extname) { 111 psFits *fp = psFitsAlloc(cell->extname); 112 psFitsWriteImage(fp, cell->header, cell->pixels->data[i], i); 113 psFree(fp); 114 } 115 } 116 } 117 #endif 118 119 psFree(newfpa); 120 psFree(newCamera); 64 121 65 122 // Tidy up
Note:
See TracChangeset
for help on using the changeset viewer.
