- Timestamp:
- Feb 5, 2010, 1:38:43 PM (16 years ago)
- Location:
- branches/eam_branches/20091201/psphot
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/psphotMergeSources.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psphot
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/eam_branches/psphot.stack.20100120 merged eligible /branches/eam_branches/20091113/psphot 26119-26255
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/eam_branches/20091201/psphot/src/psphotMergeSources.c
r26645 r26788 5 5 PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT) // Mask to apply for PSF sources 6 6 7 // merge the externally supplied sources with the existing sources. mark them as having 8 // mode PM_SOURCE_MODE_EXTERNAL 9 bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, psArray *sources) { 10 11 psArray *extSourcesCMF = NULL; 7 // for now, let's store the detections on the readout->analysis for each readout 8 bool psphotMergeSources (pmConfig *config, const pmFPAview *view) 9 { 10 bool status = true; 11 12 int num = psMetadataLookupS32 (&status, config->arguments, "PSPHOT.INPUT.NUM"); 13 psAssert (status, "programming error: must define PSPHOT.INPUT.NUM"); 14 15 // loop over the available readouts 16 for (int i = 0; i < num; i++) { 17 if (!psphotMergeSourcesReadout (config, view, "PSPHOT.INPUT", i)) { 18 psError (PSPHOT_ERR_CONFIG, false, "failed to merge sources for PSPHOT.INPUT entry %d", i); 19 return false; 20 } 21 } 22 return true; 23 } 24 25 // add newly selected sources to the existing list of sources 26 bool psphotMergeSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index) { 27 28 bool status; 29 30 // find the currently selected readout 31 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 32 psAssert (file, "missing file?"); 33 34 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 35 psAssert (readout, "missing readout?"); 36 37 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 38 psAssert (detections, "missing detections?"); 39 40 psArray *newSources = detections->newSources; 41 psAssert (newSources, "missing sources?"); 42 43 // XXX TEST: 44 if (detections->allSources) { 45 psphotMaskCosmicRayFootprintCheck(detections->allSources); 46 } 47 if (detections->newSources) { 48 psphotMaskCosmicRayFootprintCheck(detections->newSources); 49 } 50 51 if (!detections->allSources) { 52 detections->allSources = psArrayAllocEmpty(newSources->n); 53 } 54 psArray *allSources = detections->allSources; 55 56 for (int i = 0; i < newSources->n; i++) { 57 pmSource *source = newSources->data[i]; 58 psArrayAdd (allSources, 100, source); 59 } 60 61 psFree (detections->newSources); 62 detections->newSources = NULL; 63 64 return true; 65 } 66 67 // Merge the externally supplied sources with the existing sources. Mark them as having mode 68 // PM_SOURCE_MODE_EXTERNAL. 69 70 // XXX This function needs to be updated to loop over set of input files. At the moment, we 71 // only expect a single entry for PSPHOT.INPUT.CMF and PSPHOT.SOURCES.TEXT, so we can only 72 // associate input sources with a single entry for PSPHOT.INPUT 73 bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view) { 74 75 bool status; 76 pmDetections *extCMF = NULL; 12 77 psArray *extSourcesTXT = NULL; 78 79 // find the currently selected readout 80 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 81 psAssert (file, "missing file?"); 82 83 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 84 psAssert (readout, "missing readout?"); 85 86 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 87 psAssert (detections, "missing detections?"); 88 89 // XXX allSources of newSources? 90 psArray *sources = detections->allSources; 91 psAssert (sources, "missing sources?"); 13 92 14 93 // load data from input CMF file: … … 17 96 if (!readoutCMF) goto loadTXT; 18 97 19 extSourcesCMF = psMetadataLookupPtr (NULL, readoutCMF->analysis, "PSPHOT.SOURCES");20 if (extSourcesCMF) {21 for (int i = 0; i < extSourcesCMF->n; i++) {22 pmSource *source = extSourcesCMF->data[i];23 source->mode |= PM_SOURCE_MODE_EXTERNAL;98 extCMF = psMetadataLookupPtr (NULL, readoutCMF->analysis, "PSPHOT.DETECTIONS"); 99 if (extCMF) { 100 for (int i = 0; i < extCMF->allSources->n; i++) { 101 pmSource *source = extCMF->allSources->data[i]; 102 source->mode |= PM_SOURCE_MODE_EXTERNAL; 24 103 25 104 // the supplied peak flux needs to be re-normalized … … 27 106 source->peak->value = 1.0; 28 107 29 // drop the loaded source modelPSF 30 psFree (source->modelPSF); 31 source->modelPSF = NULL; 32 } 33 psphotMergeSources (sources, extSourcesCMF); 34 } 108 // drop the loaded source modelPSF 109 psFree (source->modelPSF); 110 source->modelPSF = NULL; 111 112 psArrayAdd (detections->allSources, 100, source); 113 } 114 } 35 115 } 36 116 … … 48 128 source->mode |= PM_SOURCE_MODE_EXTERNAL; 49 129 50 // drop the loaded source modelPSF 51 psFree (source->modelPSF); 52 source->modelPSF = NULL; 53 } 54 psphotMergeSources (sources, extSourcesTXT); 55 } 130 // drop the loaded source modelPSF 131 psFree (source->modelPSF); 132 source->modelPSF = NULL; 133 134 psArrayAdd (detections->allSources, 100, source); 135 } 136 } 56 137 } 57 138 58 139 finish: 59 140 60 if (!ext SourcesTXT&& !extSourcesTXT) {141 if (!extCMF && !extSourcesTXT) { 61 142 psLogMsg ("psphot", 3, "no external sources for this readout"); 62 143 return true; 63 144 } 64 145 65 int nCMF = ext SourcesCMF ? extSourcesCMF->n: 0;146 int nCMF = extCMF ? extCMF->allSources->n : 0; 66 147 int nTXT = extSourcesTXT ? extSourcesTXT->n : 0; 67 148 … … 71 152 } 72 153 73 // add newly selected sources to the existing list of sources74 bool psphotMergeSources (psArray *oldSources, psArray *newSources) {75 76 for (int i = 0; i < newSources->n; i++) {77 pmSource *source = newSources->data[i];78 psArrayAdd (oldSources, 100, source);79 }80 return true;81 }82 83 154 // extract the input sources corresponding to this readout 155 // XXX this function needs to be updated to work with the new context of pshot inputs 84 156 psArray *psphotLoadPSFSources (pmConfig *config, const pmFPAview *view) { 157 158 bool status; 85 159 86 160 // find the currently selected readout … … 91 165 } 92 166 93 psArray *sources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES"); 167 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 168 if (!detections) { 169 psLogMsg ("psphot", 3, "no psf sources for this readout"); 170 return NULL; 171 } 172 173 psArray *sources = detections->allSources; 94 174 if (!sources) { 95 175 psLogMsg ("psphot", 3, "no psf sources for this readout"); 176 return NULL; 96 177 } 97 178 … … 99 180 } 100 181 182 // this function is used to fix sources which were loaded externally, but have passed from 183 // psphotDetectionsFromSources to psphotSourceStats and are now stored on 184 // detections->newSources. 185 bool psphotRepairLoadedSources (pmConfig *config, const pmFPAview *view) { 186 187 // find the currently selected readout 188 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 189 psAssert (file, "missing file?"); 190 191 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 192 psAssert (readout, "missing readout?"); 193 194 pmDetections *detections = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.DETECTIONS"); 195 if (!detections) { 196 psError(PSPHOT_ERR_CONFIG, false, "missing detections"); 197 return false; 198 } 199 200 psArray *sources = detections->newSources; 201 psAssert (sources, "missing sources?"); 202 203 // peak flux is wrong : set based on previous image 204 // use the peak measured in the moments analysis: 205 for (int i = 0; i < sources->n; i++) { 206 pmSource *source = sources->data[i]; 207 source->peak->flux = source->moments->Peak; 208 } 209 210 return true; 211 } 212 101 213 // generate the detection structure for the supplied array of sources 102 pmDetections *psphotDetectionsFromSources (pmConfig *config, psArray *sources) { 214 // XXX this currently assumes there is a single input file 215 bool psphotDetectionsFromSources (pmConfig *config, const pmFPAview *view, psArray *sources) { 216 217 // find the currently selected readout 218 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 219 psAssert (file, "missing file?"); 220 221 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 222 psAssert (readout, "missing readout?"); 103 223 104 224 pmDetections *detections = pmDetectionsAlloc(); … … 113 233 float snMin = psMetadataLookupF32(NULL, recipe, "MOMENTS_SN_MIN"); 114 234 if (!isfinite(snMin)) { 115 return NULL;235 return false; 116 236 } 117 237 … … 152 272 psLogMsg ("psphot", 3, "%ld PSF sources loaded", detections->peaks->n); 153 273 154 return detections; 274 // save detections on the readout->analysis 275 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detectinos", detections)) { 276 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 277 return false; 278 } 279 psFree (detections); 280 return true; 155 281 } 156 282 … … 194 320 return true; 195 321 } 322 323 bool psphotCheckExtSources (pmConfig *config, const pmFPAview *view) { 324 325 bool status; 326 327 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE); 328 psAssert (recipe, "missing recipe"); 329 330 // find the currently selected readout 331 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 332 psAssert (file, "missing file?"); 333 334 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 335 psAssert (readout, "missing readout?"); 336 337 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 338 psAssert (detections, "missing detections?"); 339 340 // XXX allSources of newSources? 341 psArray *sources = detections->allSources; 342 psAssert (sources, "missing sources?"); 343 344 if (sources->n) { 345 // the user wants to make the psf from these stars; define them as psf stars: 346 for (int i = 0; i < sources->n; i++) { 347 pmSource *source = sources->data[i]; 348 source->mode |= PM_SOURCE_MODE_PSFSTAR; 349 } 350 // force psphotChoosePSF to use all loaded sources 351 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF_MAX_NSTARS", PS_META_REPLACE, "max number of sources for PSF model", sources->n); 352 353 // measure stats of externally specified sources 354 if (!psphotSourceStatsUpdate (sources, config, readout)) { 355 psError(PSPHOT_ERR_CONFIG, false, "failure to measure stats of existing sources"); 356 return false; 357 } 358 } else { 359 360 // find the detections (by peak and/or footprint) in the image. 361 if (!psphotFindDetections (config, view, true)) { 362 psError(PSPHOT_ERR_CONFIG, false, "unable to find detections in this image"); 363 return psphotReadoutCleanup (config, view); 364 } 365 366 // construct sources and measure basic stats 367 psphotSourceStats (config, view, true); 368 369 // find blended neighbors of very saturated stars 370 psphotDeblendSatstars (config, view); 371 372 // mark blended peaks PS_SOURCE_BLEND 373 if (!psphotBasicDeblend (config, view)) { 374 psLogMsg ("psphot", 3, "failed on deblend analysis"); 375 return psphotReadoutCleanup (config, view); 376 } 377 378 // classify sources based on moments, brightness 379 if (!psphotRoughClass (config, view)) { 380 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 381 return psphotReadoutCleanup (config, view); 382 } 383 } 384 385 return true; 386 }
Note:
See TracChangeset
for help on using the changeset viewer.
