Changeset 20995 for trunk/ppStack/src/ppStackLoop.c
- Timestamp:
- Dec 15, 2008, 1:18:30 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ppStack/src/ppStackLoop.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackLoop.c
r20837 r20995 252 252 // Preparation iteration: Load the sources, and get a target PSF model 253 253 psTrace("ppStack", 1, "Determining target PSF....\n"); 254 psArray *globalSources = NULL; // Global list of sources for matching (haveSources = TRUE) 255 psArray *indSources = psArrayAlloc(num); // Individual lists of sources for matching (haveSources = FALSE) 254 psArray *sourceLists = psArrayAlloc(num); // Individual lists of sources for matching 256 255 pmPSF *targetPSF = NULL; // Target PSF 257 bool haveSources = psMetadataLookupBool(NULL, config->arguments, "HAVE.SOURCES"); // Global sources?258 256 if (psMetadataLookupBool(NULL, config->arguments, "HAVE.PSF")) { 259 257 pmFPAfileActivate(config->files, false, NULL); … … 269 267 psMetadataItem *fileItem; // Item from iteration 270 268 psArray *psfs = psArrayAlloc(num); // PSFs for PSF envelope 271 psArray *sourceLists = NULL; // Source lists for merging sources from multiple readouts272 269 int numCols = 0, numRows = 0; // Size of image 273 270 int index = 0; // Index for file … … 280 277 psError(PS_ERR_UNKNOWN, false, "Unable to find PSF."); 281 278 psFree(view); 282 psFree(globalSources);283 psFree(indSources);284 279 psFree(sourceLists); 285 280 psFree(fileIter); … … 298 293 psError(PS_ERR_UNKNOWN, false, "Unable to determine size of image from PSF."); 299 294 psFree(view); 300 psFree(globalSources);301 psFree(indSources);302 295 psFree(sourceLists); 303 296 psFree(fileIter); … … 310 303 } 311 304 312 if (!haveSources) { 313 pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources 314 psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources 315 if (!sources) { 316 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout."); 317 return NULL; 318 } 319 indSources->data[index] = psMemIncrRefCounter(sources); 320 321 322 // Calculate zero points if we don't trust the source lists 323 if (psMetadataLookupBool(NULL, recipe, "ZP")) { 324 psTrace("ppStack", 2, "Photometering input %d of %d....\n", index, num); 325 pmFPAfileActivate(config->files, false, NULL); 326 fileActivationSingle(config, convolveFiles, true, index); 327 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", 328 index);// File of interest 329 pmFPAview *view = filesIterateDown(config); 330 if (!view) { 331 psFree(globalSources); 332 psFree(indSources); 333 psFree(targetPSF); 334 return false; 335 } 336 337 pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout of interest 338 339 if (!ppStackInputPhotometry(ro, sources, config)) { 340 psError(PS_ERR_UNKNOWN, false, "Unable to do photometry on input sources"); 341 psFree(globalSources); 342 psFree(indSources); 343 psFree(targetPSF); 344 return false; 345 } 346 347 psFree(view); 348 if (!filesIterateUp(config)) { 349 psFree(globalSources); 350 psFree(indSources); 351 psFree(targetPSF); 352 return false; 353 } 354 pmFPAfileActivate(config->files, false, NULL); 355 fileActivation(config, prepareFiles, true); 356 } 357 358 359 #ifdef TESTING 360 ppStackSourcesPrint(sources); 361 #endif 362 sourceLists = ppStackSourceListAdd(sourceLists, sources, config); 363 if (!sourceLists) { 364 psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list."); 365 psFree(view); 366 psFree(globalSources); 367 psFree(indSources); 368 psFree(fileIter); 369 psFree(psfs); 305 pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Readout with sources 306 psArray *sources = psMetadataLookupPtr(NULL, ro->analysis, "PSPHOT.SOURCES"); // Sources 307 if (!sources) { 308 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find sources in readout."); 309 return NULL; 310 } 311 sourceLists->data[index] = psMemIncrRefCounter(sources); 312 313 // Re-do photometry if we don't trust the source lists 314 if (psMetadataLookupBool(NULL, recipe, "PHOT")) { 315 psTrace("ppStack", 2, "Photometering input %d of %d....\n", index, num); 316 pmFPAfileActivate(config->files, false, NULL); 317 fileActivationSingle(config, convolveFiles, true, index); 318 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PPSTACK.INPUT", index); // File 319 pmFPAview *view = filesIterateDown(config); 320 if (!view) { 321 psFree(sourceLists); 322 psFree(targetPSF); 370 323 return false; 371 324 } 325 326 pmReadout *ro = pmFPAviewThisReadout(view, file->fpa); // Readout of interest 327 328 if (!ppStackInputPhotometry(ro, sources, config)) { 329 psError(PS_ERR_UNKNOWN, false, "Unable to do photometry on input sources"); 330 psFree(sourceLists); 331 psFree(targetPSF); 332 return false; 333 } 334 335 psFree(view); 336 if (!filesIterateUp(config)) { 337 psFree(sourceLists); 338 psFree(targetPSF); 339 return false; 340 } 341 pmFPAfileActivate(config->files, false, NULL); 342 fileActivation(config, prepareFiles, true); 372 343 } 373 344 … … 375 346 } 376 347 psFree(fileIter); 348 349 // Zero point calibration 350 if (!ppStackSourcesTransparency(sourceLists, view, config)) { 351 psError(PS_ERR_UNKNOWN, false, "Unable to calculate transparency differences"); 352 psFree(sourceLists); 353 psFree(targetPSF); 354 return false; 355 } 356 357 exit(1); 377 358 378 359 targetPSF = ppStackPSF(config, numCols, numRows, psfs); … … 380 361 if (!targetPSF) { 381 362 psError(PS_ERR_UNKNOWN, false, "Unable to determine output PSF."); 382 psFree(globalSources); 383 psFree(indSources); 363 psFree(sourceLists); 384 364 psFree(view); 385 365 return false; … … 390 370 "Target PSF", targetPSF); 391 371 outChip->data_exists = true; 392 393 if (haveSources) {394 // We want to hang on to the 'sources' even when its host FPA is blown away395 pmReadout *sourcesRO = pmFPAfileThisReadout(config->files, view, "PPSTACK.INPUT.SOURCES");396 globalSources = psMetadataLookupPtr(NULL, sourcesRO->analysis, "PSPHOT.SOURCES");397 psMemIncrRefCounter(globalSources);398 if (!globalSources) {399 psError(PS_ERR_UNKNOWN, true, "Unable to find sources.");400 psFree(view);401 return false;402 }403 } else {404 globalSources = ppStackSourceListCombine(sourceLists, config);405 psFree(sourceLists);406 if (!globalSources) {407 psError(PS_ERR_UNKNOWN, false, "Unable to add sources to list.");408 psFree(view);409 psFree(psfs);410 return false;411 }412 #ifdef TESTING413 ppStackSourcesPrint(globalSources);414 #endif415 }416 372 417 373 psFree(view); … … 460 416 pmFPAview *view = filesIterateDown(config); 461 417 if (!view) { 462 psFree(globalSources); 463 psFree(indSources); 418 psFree(sourceLists); 464 419 psFree(targetPSF); 465 420 psFree(rng); … … 478 433 psError(PS_ERR_UNKNOWN, true, "Sizes of input images don't match: %dx%d vs %dx%d", 479 434 readout->image->numCols, readout->image->numRows, numCols, numRows); 480 psFree(globalSources); 481 psFree(indSources); 435 psFree(sourceLists); 482 436 psFree(targetPSF); 483 437 psFree(rng); … … 489 443 // Background subtraction, scaling and normalisation is performed automatically by the image matching 490 444 psArray *regions = NULL, *kernels = NULL; // Regions and kernels used in subtraction 491 psArray *sources = haveSources ? globalSources : indSources->data[i]; // Sources for matching492 445 psTimerStart("PPSTACK_MATCH"); 493 446 if (!ppStackMatch(readout, ®ions, &kernels, &matchChi2->data.F32[i], &weightings->data.F32[i], 494 source s, targetPSF, rng, config)) {447 sourceLists->data[i], targetPSF, rng, config)) { 495 448 psErrorStackPrint(stderr, "Unable to match image %d --- ignoring.", i); 496 449 inputMask->data.U8[i] = PPSTACK_MASK_MATCH; … … 532 485 memDump("match"); 533 486 } 534 psFree(globalSources); 535 psFree(indSources); 487 psFree(sourceLists); 536 488 psFree(targetPSF); 537 489 psFree(rng);
Note:
See TracChangeset
for help on using the changeset viewer.
