Changeset 16382 for branches/pap_branch_080207/ppStack/src/ppStackLoop.c
- Timestamp:
- Feb 8, 2008, 11:43:52 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_080207/ppStack/src/ppStackLoop.c
r16367 r16382 13 13 // Here follows lists of files for activation/deactivation at various stages. Each must be NULL-terminated. 14 14 15 #if 0 15 16 // All files in the system 16 17 static char *allFiles[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.WEIGHT", … … 23 24 "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID", "PSPHOT.INPUT.CMF", 24 25 0 }; 26 #endif 25 27 26 28 // Files required in preparation for convolution 27 29 static char *prepareFiles[] = { "PSPHOT.PSF.LOAD", "PPSTACK.SOURCES", 0 }; 28 30 29 // Files for convolution; these should be turned on one by one30 static char *convolutionFiles[] = { "PPSTACK.INPUT", "PPSTACK.INPUT.MASK", "PPSTACK.INPUT.WEIGHT",31 "PPSTACK.OUTCONV", "PPSTACK.OUTCONV.MASK", "PPSTACK.OUTCONV.WEIGHT",32 0 };33 34 31 // Input files for the combination 35 static char *inCombineFiles = { "PPSTACK.INCONV", "PPSTACK.INCONV.MASK", "PPSTACK.INCONV.WEIGHT", 0 };32 static char *inCombineFiles[] = { "PPSTACK.INCONV", "PPSTACK.INCONV.MASK", "PPSTACK.INCONV.WEIGHT", 0 }; 36 33 37 34 // Output files for the combination and photometry 38 static char *outCombineFiles = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.WEIGHT",39 "PSPHOT.OUTPUT", "PSPHOT.RESID", "PSPHOT.BACKMDL",40 "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB",41 "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID",42 "PSPHOT.INPUT.CMF", 0 };35 static char *outCombineFiles[] = { "PPSTACK.OUTPUT", "PPSTACK.OUTPUT.MASK", "PPSTACK.OUTPUT.WEIGHT", 36 "PSPHOT.OUTPUT", "PSPHOT.RESID", "PSPHOT.BACKMDL", 37 "PSPHOT.BACKMDL.STDEV", "PSPHOT.BACKGND", "PSPHOT.BACKSUB", 38 "SOURCE.PLOT.MOMENTS", "SOURCE.PLOT.PSFMODEL", "SOURCE.PLOT.APRESID", 39 "PSPHOT.INPUT.CMF", 0 }; 43 40 44 41 … … 103 100 104 101 105 106 102 // Iterate down the hierarchy, loading files; we can get away with this because we're working on skycells 107 103 static pmFPAview *filesIterateDown(pmConfig *config // Configuration … … 158 154 bool ppStackLoop(pmConfig *config) 159 155 { 156 assert(config); 157 160 158 psMaskType maskBlank = psMetadataLookupU8(NULL, config->arguments, "MASK.BLANK"); // Mask for blank reg. 161 159 … … 182 180 return false; 183 181 } 182 int num = psMetadataLookupS32(NULL, config->arguments, "INPUTS.NUM"); // Number of inputs 183 int numScans = psMetadataLookupS32(NULL, config->arguments, "ROWS"); // Number of scans to read at once 184 185 186 187 // XXX Will need to adjust this when we're doing the convolution 188 int overlap = 0; // Overlap between consecutive scans 189 190 191 184 192 185 193 // Preparation iteration: Load the sources, and get a target PSF model 186 p sArray *sources = NULL; // Sources to use for PSF matching194 pmReadout *sources = NULL; // Readout with sources to use for PSF matching 187 195 pmPSF *targetPSF = NULL; // Target PSF 188 196 { … … 194 202 } 195 203 196 pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSTACK.SOURCES"); // Readout197 204 // We want to hang on to the 'sources' even when its host FPA is blown away 198 sources = psMemIncrRefCounter(p sMetadataLookupPtr(&mdok, sourcesRO->analysis, "PSPHOT.SOURCES"));205 sources = psMemIncrRefCounter(pmFPAfileThisReadout(config->files, view, "PPSTACK.SOURCES")); 199 206 if (!sources) { 200 207 psError(PS_ERR_UNKNOWN, true, "Unable to find sources."); … … 207 214 "^PPSTACK.INPUT$"); // Iterator 208 215 psMetadataItem *fileItem; // Item from iteration 209 int fileNum = 0; // Number of file210 216 psList *psfList = psListAlloc(NULL); // List of PSFs for PSF envelope 217 int numCols = 0, numRows = 0; // Size of image 211 218 while ((fileItem = psMetadataGetAndIncrement(fileIter))) { 212 219 assert(fileItem->type == PS_DATA_UNKNOWN); 213 220 pmFPAfile *inputFile = fileItem->data.V; // An input file 214 221 pmChip *chip = pmFPAviewThisChip(view, inputFile->fpa); // The chip: holds the PSF 215 pmPSF *psf = psMetadataLookupPtr(NULL, ro->parent->parent->analysis, "PSPHOT.PSF"); // PSF222 pmPSF *psf = psMetadataLookupPtr(NULL, chip->analysis, "PSPHOT.PSF"); // PSF 216 223 if (!psf) { 217 224 psError(PS_ERR_UNKNOWN, false, "Unable to find PSF."); 218 225 psFree(view); 219 226 psFree(sources); 227 psFree(fileIter); 228 psFree(psfList); 220 229 return false; 221 230 } 222 231 psListAdd(psfList, PS_LIST_TAIL, psf); 232 233 pmCell *cell = pmFPAviewThisCell(view, inputFile->fpa); // Cell of interest 234 pmHDU *hdu = pmHDUFromCell(cell); 235 assert(hdu && hdu->header); 236 int naxis1 = psMetadataLookupS32(NULL, hdu->header, "NAXIS1"); // Number of columns 237 int naxis2 = psMetadataLookupS32(NULL, hdu->header, "NAXIS2"); // Number of rows 238 if (naxis1 <= 0 || naxis2 <= 0) { 239 psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF."); 240 psFree(view); 241 psFree(sources); 242 psFree(fileIter); 243 psFree(psfList); 244 return false; 245 } 246 if (numCols == 0 && numRows == 0) { 247 numCols = naxis1; 248 numRows = naxis2; 249 } 223 250 } 224 251 psFree(fileIter); 225 252 psFree(view); 226 253 227 psArray *psfArray = psListToArray(psfList); // Array of PSFs254 targetPSF = ppStackPSF(config, numCols, numRows, psfList); 228 255 psFree(psfList); 229 targetPSF = pmPSFEnvelope(numCols, numRows, psfArray, psfInstances, psfRadius, psfModel,230 psfOrder, psfOrder);231 psFree(psfArray);232 256 if (!targetPSF) { 233 257 psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF."); … … 241 265 242 266 // Generate convolutions and write them to disk 243 psArray *cells = psArrayAlloc(num Files);// Cells for convolved images --- a handle for reading again244 for (int i = 0; i < num Files; i++) {267 psArray *cells = psArrayAlloc(num); // Cells for convolved images --- a handle for reading again 268 for (int i = 0; i < num; i++) { 245 269 pmFPAfileActivate(config->files, false, NULL); 246 270 psArray *files = fileActivationSingle(config, prepareFiles, true, i); 247 271 pmFPAview *view = filesIterateDown(config); 248 272 if (!view) { 273 psFree(sources); 274 psFree(targetPSF); 249 275 return false; 250 276 } … … 254 280 255 281 // Background subtraction, scaling and normalisation is performed automatically by the image matching 256 if (!ppStackMatch(r o, sources, outPSF, config)) {282 if (!ppStackMatch(readout, sources, targetPSF, config)) { 257 283 psError(PS_ERR_UNKNOWN, false, "Unable to match image %d --- ignoring.", i); 258 psFree(convolved); 284 psFree(sources); 285 psFree(targetPSF); 259 286 return false; 260 287 } … … 290 317 filesIterateUp(config); 291 318 } 319 psFree(sources); 320 psFree(targetPSF); 292 321 293 322 // Set files to read at the readout level --- then when we iterate down, the pmFPAfileIO stuff should take … … 295 324 fileSetDataLevel(config, inCombineFiles, PM_FPA_LEVEL_CHUNK); 296 325 pmFPAfileActivate(config->files, false, NULL); 297 fileActivation( inCombineFiles, true);298 fileActivation( outCombineFiles, true);326 fileActivation(config, inCombineFiles, true); 327 fileActivation(config, outCombineFiles, true); 299 328 300 329 { … … 304 333 return false; 305 334 } 306 pm Readout *outRO = pmFPAfileThisReadout(config->files, view, "PPSTACK.OUTPUT"); // Output readout307 p sFree(view);308 309 psArray *readouts = psArrayAlloc(num Files); // Readouts for convolved images310 for (int i = 0; i < num Files; i++) {335 pmCell *outCell = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT"); // Output cell 336 pmReadout *outRO = pmReadoutAlloc(outCell); // Output readout 337 338 psArray *readouts = psArrayAlloc(num); // Readouts for convolved images 339 for (int i = 0; i < num; i++) { 311 340 readouts->data[i] = pmReadoutAlloc(cells->data[i]); // Readout into which to read 312 341 } 342 psFree(cells); 313 343 314 344 // Read convolutions by chunks 315 int numRead = 0; // Number of inputs read316 int numChunk = 0; // Chunk number317 345 bool more = true; // More to read? 318 346 for (int numChunk = 0; more; numChunk++) { 319 for (int i = 0; i < num Files; i++) {347 for (int i = 0; i < num; i++) { 320 348 pmReadout *readout = readouts->data[i]; 321 349 assert(readout); … … 336 364 psError(PS_ERR_IO, false, "Unable to read chunk %d for file %d", numChunk, i); 337 365 psFree(readouts); 338 psFree(cells); 366 psFree(outRO); 367 psFree(view); 368 return false; 339 369 } 340 370 } 341 371 372 #if 0 342 373 if (!ppStackReadout(config, outRO, readouts)) { 343 374 psError(PS_ERR_UNKNOWN, false, "Unable to stack images.\n"); 375 psFree(readouts); 376 psFree(outRO); 377 psFree(view); 344 378 return false; 345 379 } 346 347 for (int i = 0; i < numFiles && more; i++) { 380 #else 381 printf("Stack...\n"); 382 #endif 383 384 for (int i = 0; i < num && more; i++) { 348 385 pmReadout *readout = readouts->data[i]; 349 386 assert(readout); … … 364 401 } 365 402 } 403 psFree(readouts); 366 404 367 405 // Get rid of the input files 368 fileActivation( outCombineFiles, false);406 fileActivation(config, outCombineFiles, false); 369 407 filesIterateUp(config); 370 408 371 ppStackPhotometry(config, outRO); 409 if (psMetadataLookupBool(&mdok, config->arguments, "PHOTOMETRY") && 410 !ppStackPhotometry(config, outRO, view)) { 411 psError(PS_ERR_UNKNOWN, false, "Unable to perform photometry on output."); 412 psFree(outRO); 413 psFree(view); 414 return false; 415 } 416 417 // Statistics on output 418 if (stats) { 419 ppStatsFPA(stats, outCell->parent->parent, view, maskBlank, config); 420 } 372 421 373 422 // Put version information into the header 374 423 pmHDU *hdu = pmHDUFromCell(outRO->parent); 375 424 if (!hdu) { 376 psError(PS_ERR_UNKNOWN, true, "Unable to find HDU for output.");425 psError(PS_ERR_UNKNOWN, false, "Unable to find HDU for output."); 377 426 return false; 378 427 } … … 382 431 ppStackVersionMetadata(hdu->header); 383 432 384 // Statistics on output385 if (stats) {386 ppStatsFPA(stats, output->fpa, view, maskBlank, config);387 }388 389 433 // Write out the output files 390 file sActivation(outCombineFiles, true);434 fileActivation(config, outCombineFiles, true); 391 435 filesIterateUp(config); 392 } 393 394 psFree(view); 436 437 psFree(outRO); 438 psFree(view); 439 } 440 395 441 396 442 // Write out summary statistics
Note:
See TracChangeset
for help on using the changeset viewer.
