Changeset 5651
- Timestamp:
- Nov 30, 2005, 6:03:51 PM (20 years ago)
- Location:
- trunk/archive/scripts/src/phase2
- Files:
-
- 11 edited
-
Makefile.am (modified) (1 diff)
-
ipprc.config (modified) (2 diffs)
-
papPhase2.c (modified) (4 diffs)
-
phase2.config (modified) (1 diff)
-
pmConfig.c (modified) (1 diff)
-
pmFPA.h (modified) (1 diff)
-
pmFPAConstruct.c (modified) (1 diff)
-
pmFPAMorph.c (modified) (15 diffs)
-
pmFPAMorph.h (modified) (1 diff)
-
psAdditionals.c (modified) (1 diff)
-
psAdditionals.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/Makefile.am
r5632 r5651 12 12 pmFPAConceptsSet.c \ 13 13 pmFPAConstruct.c \ 14 pmFPAMorph.c \ 14 15 pmFPARead.c \ 15 16 pmFPAWrite.c \ -
trunk/archive/scripts/src/phase2/ipprc.config
r5621 r5651 8 8 ### Setups for each camera system 9 9 CAMERAS METADATA 10 # MEGACAM_SINGLE STR megacam_single.config11 10 MEGACAM_RAW STR megacam_raw.config 11 GPC1_RAW STR gpc1_raw.config 12 12 MEGACAM_SPLICE STR megacam_splice.config 13 GPC1_RAW STR gpc1_raw.config14 13 # LRIS_BLUE STR lris_blue.config 15 14 # LRIS_RED STR lris_red.config … … 23 22 TRACE METADATA # Trace levels 24 23 pap S32 10 24 pmFPAPrint S32 10 25 25 # pmConfigRead S32 10 26 26 # pmFPAWriteMask S32 10 -
trunk/archive/scripts/src/phase2/papPhase2.c
r5633 r5651 17 17 #include "pmSubtractBias.h" 18 18 #include "pmChipMosaic.h" 19 #include "pmFPAMorph.h" 19 20 20 21 // Phase 2 needs to: … … 287 288 } 288 289 290 pmFPAPrint(input); 291 exit(1); 292 289 293 #ifdef PRODUCTION 290 294 psFitsClose(inputFile); … … 296 300 pmFPAReadMask(input, inputFile); 297 301 pmFPAReadWeight(input, inputFile); 298 #else302 //#else 299 303 { 300 304 // Generate mask and weight frame … … 827 831 psLogMsg("phase2", PS_LOG_INFO, "Processing completed after %f sec.\n", psTimerMark("phase2")); 828 832 833 834 #if 1 835 // Testing pmFPAMorph 836 psMetadata *newCamera = psMetadataConfigParse(NULL, NULL, "megacam_splice.config", true); 837 pmFPA *newFPA = pmFPAConstruct(newCamera); 838 pmFPAMorph(newFPA, input, true, 0, 0); 839 psFits *newFile = psFitsAlloc("morph.fits"); 840 pmFPAWrite(newFile, newFPA, database); 841 psFree(newFile); 842 psFree(newFPA); 843 #endif 844 845 #if 0 829 846 // Write the output 830 847 pmFPAWrite(outputFile, input, database); 831 848 pmFPAWriteMask(input, outputFile); 832 849 pmFPAWriteWeight(input, outputFile); 850 #endif 833 851 834 852 psLogMsg("phase2", PS_LOG_INFO, "Output completed after %f sec.\n", psTimerMark("phase2")); -
trunk/archive/scripts/src/phase2/phase2.config
r5621 r5651 6 6 BIAS BOOL FALSE # Bias subtraction 7 7 DARK BOOL FALSE # Dark subtraction 8 OVERSCAN BOOL TRUE # Overscan subtraction8 OVERSCAN BOOL FALSE # Overscan subtraction 9 9 FLAT BOOL FALSE # Flat-field normalisation 10 10 FRINGE BOOL FALSE # Fringe subtraction -
trunk/archive/scripts/src/phase2/pmConfig.c
r5633 r5651 283 283 } // Done looking at all cameras 284 284 if (! winner) { 285 psError(PS_ERR_IO, true, "Unable to find a ncamera that matches input FITS header!\n");285 psError(PS_ERR_IO, true, "Unable to find a camera that matches input FITS header!\n"); 286 286 } 287 287 -
trunk/archive/scripts/src/phase2/pmFPA.h
r5564 r5651 75 75 psImage *mask; // Mask for image 76 76 psImage *weight; // Weight for image 77 #if 0 77 78 psList *bias; // List of bias section (sub-)images 79 #endif 78 80 psMetadata *analysis; // Readout-level analysis metadata 79 81 pmCell *parent; // Parent cell -
trunk/archive/scripts/src/phase2/pmFPAConstruct.c
r5633 r5651 272 272 ) 273 273 { 274 psTrace(__func__, 0, "FPA:\n");274 psTrace(__func__, 1, "FPA:\n"); 275 275 if (fpa->hdu) { 276 psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->hdu->extname);276 psTrace(__func__, 2, "---> FPA is extension %s.\n", fpa->hdu->extname); 277 277 if (! fpa->hdu->images) { 278 psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->hdu->extname); 279 } 280 } 278 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", fpa->hdu->extname); 279 } 280 } 281 psMetadataPrint(fpa->concepts, 2); 281 282 282 283 psArray *chips = fpa->chips; // Array of chips 283 284 // Iterate over the FPA 284 285 for (int i = 0; i < chips->n; i++) { 285 psTrace(__func__, 1, "Chip: %d\n", i);286 psTrace(__func__, 3, "Chip: %d\n", i); 286 287 pmChip *chip = chips->data[i]; // The chip 287 288 if (chip->hdu) { 288 psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->hdu->extname);289 psTrace(__func__, 4, "---> Chip is extension %s.\n", chip->hdu->extname); 289 290 if (! chip->hdu->images) { 290 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->hdu->extname); 291 } 292 } 291 psTrace(__func__, 4, "---> NO PIXELS for extension %s\n", chip->hdu->extname); 292 } 293 } 294 psMetadataPrint(chip->concepts, 4); 295 293 296 // Iterate over the chip 294 297 psArray *cells = chip->cells; // Array of cells 295 298 for (int j = 0; j < cells->n; j++) { 296 psTrace(__func__, 2, "Cell: %d\n", j);299 psTrace(__func__, 5, "Cell: %d\n", j); 297 300 pmCell *cell = cells->data[j]; // The cell 298 301 if (cell->hdu) { 299 psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->hdu->extname);302 psTrace(__func__, 6, "---> Cell is extension %s.\n", cell->hdu->extname); 300 303 if (! cell->hdu->images) { 301 psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->hdu->extname); 302 } 303 } 304 psMetadataPrint(cell->concepts, 3); 305 psTrace(__func__, 3, "Readouts:\n"); 304 psTrace(__func__, 6, "---> NO PIXELS for extension %s\n", cell->hdu->extname); 305 } 306 } 307 psMetadataPrint(cell->concepts, 6); 308 309 psTrace(__func__, 7, "Readouts:\n"); 306 310 psArray *readouts = cell->readouts; // Array of readouts 307 311 for (int k = 0; k < readouts->n; k++) { 308 312 pmReadout *readout = readouts->data[k]; // The readout 309 313 psImage *image = readout->image; // The image 310 psTrace(__func__, 4, "Image: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 +314 psTrace(__func__, 8, "Image: [%d:%d,%d:%d] (%dx%d)\n", image->col0, image->col0 + 311 315 image->numCols, image->row0, image->row0 + image->numRows, image->numCols, 312 316 image->numRows); -
trunk/archive/scripts/src/phase2/pmFPAMorph.c
r5633 r5651 3 3 #include <assert.h> 4 4 #include "pslib.h" 5 #include "papmodule.h" 5 6 #include "papStuff.h" 7 #include "pmFPA.h" 8 #include "pmFPAMorph.h" 6 9 7 10 #define MAX(x,y) ((x) > (y) ? (x) : (y)) … … 23 26 } 24 27 break; 28 case PS_TYPE_F32: 29 for (int y = 0; y < image->numRows; y++) { 30 for (int x = 0; x < image->numCols; x++) { 31 flipped->data.F32[y][size - x - 1] = image->data.F32[y][x]; 32 } 33 } 34 break; 25 35 default: 26 36 psError(PS_ERR_IO, true, "Image type %x not yet supported for flip.\n", image->type.type); … … 51 61 } 52 62 63 64 #if 0 53 65 // Return a list of the region strings and the method for interpreting them 54 66 static psList *getRegions(psString *method, // Method for evaluating the regions … … 67 79 return regionStrings; 68 80 } 81 #endif 82 83 84 // Splice an image into another image 85 static psRegion *spliceImage(psImage *target, // Target image onto which to splice 86 int *x0, int *y0, // Starting coordinates to splice to 87 psImage *source, // Source image from which to splice 88 const psRegion *from, // Region to splice from 89 int readdir, // Read direction 90 bool xFlip, bool yFlip // Flip x and y axes? 91 ) 92 { 93 psImage *toSplice = psImageSubset(source, *from); // Subimage, to splice into target 94 if (xFlip) { 95 int size = 0; // Size of flipped image 96 if (readdir == 1) { 97 size = toSplice->numCols; 98 } else if (readdir == 2) { 99 size = target->numCols; 100 } 101 psImage *temp = xFlipImage(toSplice, size); 102 psFree(toSplice); 103 toSplice = temp; 104 } 105 if (yFlip) { 106 int size = 0; // Size of flipped image 107 if (readdir == 1) { 108 size = target->numRows; 109 } else if (readdir == 2) { 110 size = toSplice->numRows; 111 } 112 psImage *temp = yFlipImage(toSplice, size); 113 psFree(toSplice); 114 toSplice = temp; 115 } 116 117 (void)psImageOverlaySection(target, toSplice, *x0, *y0, "="); 118 119 if (readdir == 1) { 120 *x0 += toSplice->numCols; 121 } else if (readdir == 2) { 122 *y0 += toSplice->numRows; 123 } 124 125 // Return the region where we pasted the image 126 psRegion *outRegion = psAlloc(sizeof(psRegion)); 127 // Addding 1 to get FITS standard 128 outRegion->x0 = *x0 + 1; 129 outRegion->x1 = *x0 + toSplice->numCols; 130 outRegion->y0 = *y0 + 1; 131 outRegion->y1 = *y0 + toSplice->numRows; 132 133 psFree(toSplice); 134 return outRegion; 135 } 136 137 // Splice bias regions (overscans) 138 static bool spliceBias(psImage *splice, // Image to which to splice 139 int *x0, int *y0, // Starting position for splice 140 const pmCell *in, // Input cell 141 pmCell *out, // Output cell 142 int xFlip, int yFlip, // Flip the image? 143 int readNum, // Number of readout 144 int readdir // Read direction 145 ) 146 { 147 psArray *readouts = in->readouts; // The readouts; 148 pmReadout *readout = readouts->data[readNum]; // The readout of interest 149 psList *inBiassecs = psMetadataLookupPtr(NULL, in->concepts, "CELL.BIASSEC"); // List of input biassecs 150 psListIterator *inBiassecsIter = psListIteratorAlloc(inBiassecs, PS_LIST_HEAD, false); 151 psRegion *inBiassec = NULL; // BIASSEC from list 152 psList *outBiassecs = psListAlloc(NULL); // List of biassecs for output 153 while (inBiassec = psListGetAndIncrement(inBiassecsIter)) { 154 psRegion *outBiassec = spliceImage(splice, x0, y0, readout->image, inBiassec, readdir, xFlip, 155 yFlip); 156 psListAdd(outBiassecs, PS_LIST_TAIL, outBiassec); 157 } 158 psFree(inBiassecsIter); 159 psMetadataAdd(out->concepts, PS_LIST_TAIL, "CELL.BIASSEC", PS_DATA_LIST | PS_META_REPLACE, 160 "BIASSEC from pmFPAMorph", outBiassecs); 161 162 return true; 163 } 164 69 165 70 166 // Splice a list of cells together … … 79 175 psTrace(__func__, 5, "Splicing together all cells in the bucket.\n"); 80 176 81 if (inCells-> size != outCells->size) {177 if (inCells->n != outCells->n) { 82 178 psError(PS_ERR_IO, true, "Sizes of input (%d) and output (%d) lists of cells don't match.\n", 83 inCells-> size, outCells->size);179 inCells->n, outCells->n); 84 180 return NULL; 85 181 } 86 182 87 int numCells = inCells-> size;// Number of cells183 int numCells = inCells->n; // Number of cells 88 184 int readdir = 0; // Read direction for CCD; currently unknown 89 185 int numReadouts = 0; // Number of readouts in a cell … … 97 193 psVector *yFlip = psVectorAlloc(numCells, PS_TYPE_U8); // Do we need to flip in y? 98 194 195 196 // We go through the cells to make sure everything's kosher, and to get the sizes. 99 197 psListIterator *inCellsIter = psListIteratorAlloc(inCells, PS_LIST_HEAD, false); // Iterator for cells 100 p apCell *inCell = NULL; // Cell from list of input cells198 pmCell *inCell = NULL; // Cell from list of input cells 101 199 psListIterator *outCellsIter = psListIteratorAlloc(outCells, PS_LIST_HEAD, false); // Iterator for cells 102 200 int cellNum = 0; // Cell number; … … 104 202 psArray *readouts = inCell->readouts; // The readouts comprising the cell 105 203 106 // Check the read direction204 // Get and check the read direction 107 205 int cellReaddir = psMetadataLookupS32(NULL, inCell->concepts, "CELL.READDIR"); 108 206 if (readdir == 0) { 207 // Zero means unknown; set it. 109 208 readdir = cellReaddir; 110 209 } else if (readdir != cellReaddir) { 111 psError(PS_ERR_IO, true, "Trying to splice cells with different read directions (%d vs %d) \n",112 readdir, cellReaddir);210 psError(PS_ERR_IO, true, "Trying to splice cells with different read directions (%d vs %d). I " 211 "don't know how to do that!\n", readdir, cellReaddir); 113 212 // XXX Clean up before returning 114 213 return NULL; 115 214 } 116 // Check the number of readouts 215 216 // Get and check the number of readouts 117 217 if (! spliced) { 118 218 numReadouts = readouts->n; … … 131 231 } 132 232 133 // Get the cell parities134 p apCell *outCell = psListGetAndIncrement(outCellsIter); // Corresponding output cell135 int xParityIn = psMetadataLookupS32(NULL, inCell , "CELL.XPARITY");136 int yParityIn = psMetadataLookupS32(NULL, inCell , "CELL.YPARITY");137 int xParityOut = psMetadataLookupS32(NULL, outCell , "CELL.XPARITY");138 int yParityOut = psMetadataLookupS32(NULL, outCell , "CELL.YPARITY");233 // Get and check the cell parities 234 pmCell *outCell = psListGetAndIncrement(outCellsIter); // Corresponding output cell 235 int xParityIn = psMetadataLookupS32(NULL, inCell->concepts, "CELL.XPARITY"); 236 int yParityIn = psMetadataLookupS32(NULL, inCell->concepts, "CELL.YPARITY"); 237 int xParityOut = psMetadataLookupS32(NULL, outCell->concepts, "CELL.XPARITY"); 238 int yParityOut = psMetadataLookupS32(NULL, outCell->concepts, "CELL.YPARITY"); 139 239 if (xParityIn == 0 || xParityOut == 0 || yParityIn == 0 || yParityOut == 0) { 140 240 psError(PS_ERR_IO, false, "Unable to determine parity of cell!\n"); … … 159 259 // Calculate the sizes of the spliced images 160 260 for (int i = 0; i < numReadouts; i++) { 161 p apReadout *readout = readouts->data[i]; // The readout of interest261 pmReadout *readout = readouts->data[i]; // The readout of interest 162 262 psImage *image = readout->image; // The image pixels 163 psList *overscans = readout->overscans; // The overscan regions164 263 165 264 // Check image type … … 173 272 } 174 273 274 psRegion *trimsec = psMetadataLookupPtr(NULL, inCell->concepts, "CELL.TRIMSEC"); // Trim section 275 psList *biassecs = psMetadataLookupPtr(NULL, inCell->concepts, "CELL.BIASSEC"); // Bias section 276 psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator 277 psRegion *biassec = NULL; // Bias section from list iteration 278 175 279 // Get the size of the spliced image 176 280 if (readdir == 1) { 177 psTrace(__func__, 9, "Image size: %dx%d\n", image->numCols, image->numRows); 178 xSize->data.S32[i] += image->numCols; 179 ySize->data.S32[i] = MAX(ySize->data.S32[i], image->numRows); 281 xSize->data.S32[i] += trimsec->x1 - trimsec->x0; 282 ySize->data.S32[i] = MAX(ySize->data.S32[i], trimsec->y1 - trimsec->y0); 283 while (biassec = psListGetAndIncrement(biassecsIter)) { 284 xSize->data.S32[i] += biassec->x1 - biassec->x0; 285 ySize->data.S32[i] = MAX(ySize->data.S32[i], biassec->y1 - biassec->y0); 286 } 180 287 } else if (readdir == 2) { 181 psTrace(__func__, 9, "Image size: %dx%d\n", image->numCols, image->numRows); 182 ySize->data.S32[i] += image->numRows; 183 xSize->data.S32[i] = MAX(xSize->data.S32[i], image->numCols); 288 ySize->data.S32[i] += trimsec->y1 - trimsec->y0; 289 xSize->data.S32[i] = MAX(xSize->data.S32[i], trimsec->x1 - trimsec->x0); 290 while (biassec = psListGetAndIncrement(biassecsIter)) { 291 ySize->data.S32[i] += biassec->y1 - biassec->y0; 292 xSize->data.S32[i] = MAX(ySize->data.S32[i], biassec->x1 - biassec->x0); 293 } 184 294 } else { 185 295 psError(PS_ERR_IO, true, "Invalid read direction: %d\n", readdir); … … 187 297 return NULL; 188 298 } 189 190 psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false); 191 psImage *overscan = NULL; // Overscan image 192 while (overscan = psListGetAndIncrement(overscansIter)) { 193 194 // Check image type 195 if (type == 0) { 196 type = image->type.type; 197 } else if (image->type.type != type) { 198 psError(PS_ERR_IO, true, "Trying to splice readouts with different image types " 199 "(%d vs %d)\n", type, image->type.type); 200 // XXX Clean up before returning 201 return NULL; 202 } 203 204 // Get the size of the spliced image 205 if (readdir == 1) { 206 psTrace(__func__, 9, "Overscan size: %dx%d\n", image->numCols, image->numRows); 207 xSize->data.S32[i] += overscan->numCols; 208 ySize->data.S32[i] = MAX(ySize->data.S32[i], overscan->numRows); 209 } else if (readdir == 2) { 210 psTrace(__func__, 9, "Overscan size: %dx%d\n", image->numCols, image->numRows); 211 ySize->data.S32[i] += overscan->numRows; 212 xSize->data.S32[i] = MAX(xSize->data.S32[i], overscan->numCols); 213 } 214 } 215 216 } 299 psFree(biassecsIter); 300 } 301 302 // Copy the concepts over 303 psMetadataCopy(outCell->concepts, inCell->concepts); 217 304 } 218 305 psFree(inCellsIter); 219 306 psFree(outCellsIter); 307 220 308 221 309 // Make sure all the readouts have the same size … … 234 322 for (int i = 0; i < numReadouts; i++) { 235 323 psImage *splice = psImageAlloc(numCols, numRows, type); // The spliced image 236 324 int x0 = 0, y0 = 0; // Position at which the splice begins 325 326 // Position-dependent overscans first 327 if (posDep) { 328 for (int cellNum = 0; cellNum < inCells->n / 2; cellNum++) { 329 pmCell *inCell = psListGet(inCells, cellNum); // Input cell of interest 330 pmCell *outCell = psListGet(outCells, cellNum); // Output cell of interest 331 spliceBias(splice, &x0, &y0, inCell, outCell, xFlip->data.U8[i], yFlip->data.U8[i], i, 332 readdir); 333 } 334 } 335 336 // Then the images 237 337 psListIterator *inCellsIter = psListIteratorAlloc(inCells, PS_LIST_HEAD, false);// Iterator for cells 238 p apCell *inCell = NULL; // Cell from the list of cells338 pmCell *inCell = NULL; // Cell from the list of cells 239 339 psListIterator *outCellsIter = psListIteratorAlloc(outCells, PS_LIST_HEAD, false); // Iterator 240 340 int cellNum = 0; // Cell number 241 int x0 = 0, y0 = 0; // Position at which the splice begins242 341 while (inCell = psListGetAndIncrement(inCellsIter)) { 243 342 psArray *readouts = inCell->readouts; // The readouts comprising the cell 244 papReadout *readout = readouts->data[i]; // The specific readout of interest 245 psImage *image = readout->image; // The image pixels 246 psList *overscans = readout->overscans; // The overscan regions 247 papCell *outCell = psListGetAndIncrement(outCellsIter); // Output cell 248 249 psImage *toSplice = psMemIncrRefCounter(image); // Image to splice in 250 if (xFlip->data.U8[cellNum]) { 251 int size = 0; // Size of flipped image 252 if (readdir == 1) { 253 size = toSplice->numCols; 254 } else if (readdir == 2) { 255 size = numCols; 256 } 257 psImage *temp = xFlipImage(toSplice, size); 258 psFree(toSplice); 259 toSplice = temp; 260 } 261 if (yFlip->data.U8[cellNum]) { 262 int size = 0; // Size of flipped image 263 if (readdir == 1) { 264 size = numRows; 265 } else if (readdir == 2) { 266 size = toSplice->numRows; 267 } 268 psImage *temp = yFlipImage(toSplice, size); 269 psFree(toSplice); 270 toSplice = temp; 271 } 272 273 (void)psImageOverlaySection(splice, toSplice, x0, y0, "="); 274 275 if (readdir == 1) { 276 x0 += toSplice->numCols; 277 } else if (readdir == 2) { 278 y0 += toSplice->numRows; 279 } 280 281 // Update the TRIMSEC for the output cell 282 psString trimsecString = psMetadataLookupString(NULL, outCell, "CELL.TRIMSEC"); 283 psString trimsecMethod = NULL; // Method of determining trimsec 284 psList *trimsecs = getRegions(&trimsecMethod, trimsecString); // List of trimsecs 285 if (strncmp(trimsecMethod, "HEADER", 6) != 0 && strncmp(trimsecMethod, "HD", 2) != 0) { 286 psError(PS_ERR_IO, true, "Can only splice cells if the CELL.TRIMSEC (= %s) is determined " 287 "from the header.\n", trimsecString); 288 // XXX Clean up before returning 289 return NULL; 290 } 291 if (trimsecs->size != 1) { 292 psError(PS_ERR_IO, true, "Multiple headers specified for CELL.TRIMSEC: %s\n", trimsecString); 293 // XXX Clean up before returning 294 return NULL; 295 } 296 psString trimsecName = trimsecs->head->data; // Grab header for TRIMSEC off the list 297 psFree(trimsecs); 298 299 // TRIMSEC region; add 1 to get FITS standard 300 psRegion trimsecRegion = {x0 + 1, x0 + toSplice->numCols, y0 + 1, y0 + toSplice->numRows}; 301 psString trimsecValue = psRegionToString(trimsecRegion); 302 psMetadataAddStr(header, PS_LIST_TAIL, trimsecName, 0, "TRIMSEC from pmFPAMorph", trimsecValue); 303 // XXX Does psMetadataAddStr overwrite a previous value? 304 305 // Repeat the above for each overscan (flip, overlay, update BIASSEC) 306 // Prepare the BIASSEC 307 psString biassecString = psMetadataLookupString(NULL, outCell, "CELL.BIASSEC"); 308 psString biassecMethod = NULL; // Method of determining biassec 309 psList *biassecs = getRegions(&biassecMethod, biassecString); // List of biassecs 310 if (strncmp(biassecMethod, "HEADER", 6) != 0 && strncmp(biassecMethod, "HD", 2) != 0) { 311 psError(PS_ERR_IO, true, "Can only splice cells if the CELL.BIASSEC (= %s) is determined " 312 "from the header.\n", biassecString); 313 // XXX Clean up before returning 314 return NULL; 315 } 316 if (biassecs->size != overscans->size); 317 318 psListIterator *overscansIter = psListIteratorAlloc(overscans, PS_LIST_HEAD, false); 319 psImage *overscan = NULL; // Overscan from list 320 psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); 321 psString biassecName = NULL;// FITS header keyword for biassec 322 while ((overscan = psListGetAndIncrement(overscansIter)) && 323 (biassecName = psListGetAndIncrement(biassecsIter))) { 324 // Splice the overscan on 325 psImage *toSplice = psMemIncrRefCounter(overscan); // Image to splice in 326 if (xFlip->data.U8[cellNum]) { 327 int size = 0; // Size of flipped image 328 if (readdir == 1) { 329 size = toSplice->numCols; 330 } else if (readdir == 2) { 331 size = numCols; 332 } 333 psImage *temp = xFlipImage(toSplice, size); 334 psFree(toSplice); 335 toSplice = temp; 336 } 337 if (yFlip->data.U8[cellNum]) { 338 int size = 0; // Size of flipped image 339 if (readdir == 1) { 340 size = numRows; 341 } else if (readdir == 2) { 342 size = toSplice->numRows; 343 } 344 psImage *temp = yFlipImage(toSplice, size); 345 psFree(toSplice); 346 toSplice = temp; 347 } 348 349 (void)psImageOverlaySection(splice, toSplice, x0, y0, "="); 350 351 if (readdir == 1) { 352 x0 += toSplice->numCols; 353 } else if (readdir == 2) { 354 y0 += toSplice->numRows; 355 } 356 357 // Update the header 358 psRegion biassecRegion = {x0 + 1, x0 + toSplice->numCols, y0 + 1, y0 + toSplice->numRows}; 359 psString biassecValue = psRegionToString(biassecRegion); 360 psMetadataAddStr(header, PS_LIST_TAIL, biassecName, 0, "BIASSEC from pmFPAMorph", 361 biassecValue); 362 } 363 psFree(overscansIter); 364 psFree(biassecsIter); 365 psFree(biassecs); 366 } // Iterating over input cells 343 pmReadout *readout = readouts->data[i]; // The specific readout of interest 344 pmCell *outCell = psListGetAndIncrement(outCellsIter); // Output cell 345 psRegion *inTrimsec = psMetadataLookupPtr(NULL, inCell->concepts, "CELL.TRIMSEC"); // TRIMSEC 346 psRegion *outTrimsec = spliceImage(splice, &x0, &y0, readout->image, inTrimsec, readdir, 347 xFlip->data.U8[cellNum], yFlip->data.U8[cellNum]); 348 349 // Update the output TRIMSEC 350 psMetadataAdd(outCell->concepts, PS_LIST_TAIL, "CELL.TRIMSEC", PS_DATA_UNKNOWN | PS_META_REPLACE, 351 "TRIMSEC from pmFPAMorph", outTrimsec); 352 } 353 psFree(inCellsIter); 354 psFree(outCellsIter); 355 356 // Then the biases 357 if (! posDep) { 358 // Need to only do half the biases 359 for (int cellNum = inCells->n / 2; cellNum < inCells->n; cellNum++) { 360 pmCell *inCell = psListGet(inCells, cellNum); // Input cell of interest 361 pmCell *outCell = psListGet(outCells, cellNum); // Output cell of interest 362 spliceBias(splice, &x0, &y0, inCell, outCell, xFlip->data.U8[i], yFlip->data.U8[i], i, 363 readdir); 364 } 365 } else { 366 // Need to do all the biases 367 for (int cellNum = 0; cellNum < inCells->n; cellNum++) { 368 pmCell *inCell = psListGet(inCells, cellNum); // Input cell of interest 369 pmCell *outCell = psListGet(outCells, cellNum); // Output cell of interest 370 spliceBias(splice, &x0, &y0, inCell, outCell, xFlip->data.U8[i], yFlip->data.U8[i], i, 371 readdir); 372 } 373 } 367 374 368 375 spliced->data[i] = splice; 376 369 377 } // Iterating over readouts 370 378 … … 426 434 psListAdd(sourceCells, PS_LIST_TAIL, fromCell); 427 435 428 int xParityIn = psMetadataLookupS32(NULL, fromCell, "CELL.XPARITY"); 429 int yParityIn = psMetadataLookupS32(NULL, fromCell, "CELL.YPARITY"); 430 int xParityOut = psMetadataLookupS32(NULL, toCell, "CELL.XPARITY"); 431 int yParityOut = psMetadataLookupS32(NULL, toCell, "CELL.YPARITY"); 436 #if 1 437 int xParityIn = psMetadataLookupS32(NULL, fromCell->concepts, "CELL.XPARITY"); 438 int yParityIn = psMetadataLookupS32(NULL, fromCell->concepts, "CELL.YPARITY"); 439 int xParityOut = psMetadataLookupS32(NULL, toCell->concepts, "CELL.XPARITY"); 440 int yParityOut = psMetadataLookupS32(NULL, toCell->concepts, "CELL.YPARITY"); 432 441 psTrace(__func__, 3, "Chip %d, cell %d: in (%d,%d) out (%d,%d)\n", i, j, xParityIn, yParityIn, 433 442 xParityOut, yParityOut); 443 #endif 434 444 435 445 // Copy the cell contents over 436 446 toCell->readouts = psMemIncrRefCounter(fromCell->readouts); 437 447 438 if (toCell-> private && strlen(toCell->private->extname) > 0) {448 if (toCell->hdu && strlen(toCell->hdu->extname) > 0) { 439 449 // Splice the component cells 440 p_pmHDU *hdu = toCell-> private;450 p_pmHDU *hdu = toCell->hdu; 441 451 if (! hdu->header) { 442 452 hdu->header = psMetadataAlloc(); 443 453 } 444 hdu-> pixels = spliceCells(hdu->header,targetCells, sourceCells, positionDependent);454 hdu->images = spliceCells(targetCells, sourceCells, positionDependent); 445 455 // Purge the lists 446 456 while (psListRemove(targetCells, PS_LIST_TAIL)); … … 450 460 } 451 461 452 if (toChip-> private && strlen(toChip->private->extname) > 0) {462 if (toChip->hdu && strlen(toChip->hdu->extname) > 0) { 453 463 // Splice the component cells 454 p_pmHDU *hdu = toChip-> private;464 p_pmHDU *hdu = toChip->hdu; 455 465 if (! hdu->header) { 456 466 hdu->header = psMetadataAlloc(); 457 467 } 458 hdu-> pixels = spliceCells(hdu->header, targetCells, sourceCells);468 hdu->images = spliceCells(targetCells, sourceCells, positionDependent); 459 469 // Purge the lists 460 470 while (psListRemove(targetCells, PS_LIST_TAIL)); … … 464 474 } 465 475 476 if (toFPA->hdu && strlen(toFPA->hdu->extname) > 0) { 477 // Splice the component cells 478 p_pmHDU *hdu = toFPA->hdu; 479 if (! hdu->header) { 480 hdu->header = psMetadataAlloc(); 481 } 482 hdu->images = spliceCells(targetCells, sourceCells, positionDependent); 483 // Purge the lists 484 while (psListRemove(targetCells, PS_LIST_TAIL)); 485 while (psListRemove(sourceCells, PS_LIST_TAIL)); 486 } 487 466 488 return true; 467 489 } 468 -
trunk/archive/scripts/src/phase2/pmFPAMorph.h
r5106 r5651 3 3 4 4 // Morph one focal plane representation into another 5 bool pmFPAMorph(papFPA *toFPA, // FPA structure to which to morph 6 papFPA *fromFPA, // FPA structure from which to morph 5 bool pmFPAMorph(pmFPA *toFPA, // FPA structure to which to morph 6 pmFPA *fromFPA, // FPA structure from which to morph 7 bool positionDependent, // Is the position of the overscan dependent on the position? 7 8 int chipNum, // Chip number, in case the scopes are different 8 9 int cellNum // Cell number, in case the scopes are different -
trunk/archive/scripts/src/phase2/psAdditionals.c
r5633 r5651 3 3 #include "pslib.h" 4 4 #include "psAdditionals.h" 5 6 7 psMetadata *psMetadataCopy(psMetadata *out, 8 const psMetadata *in) 9 { 10 PS_ASSERT_PTR_NON_NULL(in,NULL); 11 if (out == NULL) { 12 out = psMetadataAlloc(); 13 } 14 psMetadataItem *inItem = NULL; 15 psMetadataIterator *iter = psMetadataIteratorAlloc(*(psMetadata**)&in, PS_LIST_HEAD, NULL); 16 unsigned long numPointers = 0; // Number of pointers we were forced to copy 17 while (inItem = psMetadataGetAndIncrement(iter)) { 18 psMetadataItem *outItem = NULL; 19 20 // Need to look for MULTI, which won't be picked up using the iterator. 21 psMetadataItem *multiCheckItem = psMetadataLookup(in, inItem->name); 22 int multiFlag = 0; // Flag to indicate MULTI or not 23 if (multiCheckItem->type == PS_DATA_METADATA_MULTI) { 24 multiFlag = PS_DATA_METADATA_MULTI; 25 } 26 27 #define PS_METADATA_COPY_CASE(NAME,TYPE) \ 28 case PS_TYPE_##NAME: \ 29 psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_TYPE_##NAME | multiFlag, inItem->comment, \ 30 inItem->data.TYPE); \ 31 break; 32 33 switch (inItem->type) { 34 // Numerical types 35 PS_METADATA_COPY_CASE(BOOL,B); 36 PS_METADATA_COPY_CASE(S8, S8); 37 PS_METADATA_COPY_CASE(S16, S16); 38 PS_METADATA_COPY_CASE(S32, S32); 39 PS_METADATA_COPY_CASE(U8, U8); 40 PS_METADATA_COPY_CASE(U16, U16); 41 PS_METADATA_COPY_CASE(U32, U32); 42 PS_METADATA_COPY_CASE(F32, F32); 43 PS_METADATA_COPY_CASE(F64, F64); 44 45 // String: relying on the fact that this will copy the string, not point at it. 46 case PS_DATA_STRING: 47 psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_STRING | multiFlag, inItem->comment, 48 inItem->data.V); 49 break; 50 51 // Metadata: copy the next level and stuff that in too 52 case PS_DATA_METADATA: 53 { 54 psMetadata *metadata = psMetadataCopy(NULL, inItem->data.md); 55 psMetadataAdd(out, PS_LIST_TAIL, inItem->name, PS_DATA_METADATA | multiFlag, inItem->comment, 56 metadata); 57 break; 58 } 59 // Other kinds of pointers 60 default: 61 numPointers++; 62 psMetadataItemAlloc(inItem->name, inItem->type, inItem->comment, inItem->data.V); 63 break; 64 } 65 } 66 psFree(iter); 67 68 if (numPointers > 0) { 69 psLogMsg(__func__, PS_LOG_WARN, "Forced to copy %d pointers when copying metadata. Updating the " 70 "copied psMetadata will affect the original!\n"); 71 } 72 73 return out; 74 } 75 5 76 6 77 psMetadata *psMetadataLookupMD(bool *status, const psMetadata *md, const char *key) -
trunk/archive/scripts/src/phase2/psAdditionals.h
r5104 r5651 3 3 4 4 #include "pslib.h" 5 6 // Deep copy of metadata 7 psMetadata *psMetadataCopy(psMetadata *out, const psMetadata *in); 5 8 6 9 // Get a value from the metadata that we believe should be metadata.
Note:
See TracChangeset
for help on using the changeset viewer.
