Changeset 27838 for branches/tap_branches/psphot/src/psphotMergeSources.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (1 prop)
-
psphot/src/psphotMergeSources.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psphot
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psphot merged eligible /branches/eam_branches/stackphot.20100406/psphot 27622-27655 /branches/pap_delete/psphot 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psphot/src
- Property svn:ignore
-
old new 19 19 psphotMomentsStudy 20 20 psphotPetrosianStudy 21 psphotForced 22 psphotMakePSF 23 psphotStack
-
- Property svn:ignore
-
branches/tap_branches/psphot/src/psphotMergeSources.c
r21519 r27838 5 5 PM_SOURCE_MODE_CR_LIMIT | PM_SOURCE_MODE_EXT_LIMIT) // Mask to apply for PSF sources 6 6 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 7 25 // add newly selected sources to the existing list of sources 8 bool psphotMergeSources (psArray *oldSources, psArray *newSources) { 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; 9 55 10 56 for (int i = 0; i < newSources->n; i++) { 11 57 pmSource *source = newSources->data[i]; 12 psArrayAdd (oldSources, 100, source); 13 } 14 return true; 15 } 16 17 // merge the externally supplied sources with the existing sources. mark them as having 18 // mode PM_SOURCE_MODE_EXTERNAL 19 bool psphotLoadExtSources (pmConfig *config, const pmFPAview *view, psArray *sources) { 20 21 // find the currently selected readout 22 pmReadout *readout = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT.CMF"); 23 if (!readout) { 24 psLogMsg ("psphot", 3, "no external sources supplied"); 25 return true; 26 } 27 28 psArray *extSources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES"); 29 if (!extSources) { 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; 77 psArray *extSourcesTXT = NULL; 78 int index = 0; 79 80 // find the currently selected readout 81 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", index); // File of interest 82 psAssert (file, "missing file?"); 83 84 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 85 psAssert (readout, "missing readout?"); 86 87 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 88 if (!detections) { 89 detections = pmDetectionsAlloc(); 90 detections->newSources = psArrayAllocEmpty (100); 91 // save detections on the readout->analysis 92 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detections", detections)) { 93 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 94 return false; 95 } 96 } else { 97 psMemIncrRefCounter(detections); // so we can free the detections below 98 } 99 100 psArray *sources = detections->newSources; 101 psAssert (sources, "missing sources?"); 102 103 // load data from input CMF file: 104 { 105 pmReadout *readoutCMF = pmFPAfileThisReadout (config->files, view, "PSPHOT.INPUT.CMF"); 106 if (!readoutCMF) goto loadTXT; 107 108 extCMF = psMetadataLookupPtr (NULL, readoutCMF->analysis, "PSPHOT.DETECTIONS"); 109 if (extCMF) { 110 for (int i = 0; i < extCMF->allSources->n; i++) { 111 pmSource *source = extCMF->allSources->data[i]; 112 source->mode |= PM_SOURCE_MODE_EXTERNAL; 113 114 // the supplied peak flux needs to be re-normalized 115 source->peak->flux = 1.0; 116 source->peak->value = 1.0; 117 118 // drop the loaded source modelPSF 119 psFree (source->modelPSF); 120 source->modelPSF = NULL; 121 source->imageID = index; 122 123 psArrayAdd (detections->newSources, 100, source); 124 } 125 } 126 } 127 128 loadTXT: 129 130 // load data from input TXT file: 131 { 132 pmChip *chipTXT = pmFPAfileThisChip (config->files, view, "PSPHOT.INPUT"); 133 if (!chipTXT) goto finish; 134 135 extSourcesTXT = psMetadataLookupPtr (NULL, chipTXT->analysis, "PSPHOT.SOURCES.TEXT"); 136 if (extSourcesTXT) { 137 for (int i = 0; i < extSourcesTXT->n; i++) { 138 pmSource *source = extSourcesTXT->data[i]; 139 source->mode |= PM_SOURCE_MODE_EXTERNAL; 140 141 // drop the loaded source modelPSF 142 psFree (source->modelPSF); 143 source->modelPSF = NULL; 144 source->imageID = index; 145 146 psArrayAdd (detections->newSources, 100, source); 147 } 148 } 149 } 150 151 finish: 152 153 psFree (detections); 154 155 if (!extCMF && !extSourcesTXT) { 30 156 psLogMsg ("psphot", 3, "no external sources for this readout"); 31 157 return true; 32 158 } 33 159 34 for (int i = 0; i < extSources->n; i++) { 35 pmSource *source = extSources->data[i]; 36 source->mode |= PM_SOURCE_MODE_EXTERNAL; 37 pmModel *model = source->modelPSF; 38 39 float xpos = model->params->data.F32[PM_PAR_XPOS]; 40 float ypos = model->params->data.F32[PM_PAR_YPOS]; 41 42 source->peak = pmPeakAlloc(xpos, ypos, 1.0, PM_PEAK_LONE); 43 source->peak->xf = xpos; 44 source->peak->yf = ypos; 45 source->peak->flux = 1.0; 46 47 // drop the loaded source modelPSF 48 psFree (source->modelPSF); 49 source->modelPSF = NULL; 50 } 51 52 psphotMergeSources (sources, extSources); 53 psLogMsg ("psphot", 3, "%ld external sources merged to yield %ld total sources", extSources->n, sources->n); 54 160 int nCMF = extCMF ? extCMF->allSources->n : 0; 161 int nTXT = extSourcesTXT ? extSourcesTXT->n : 0; 162 163 psLogMsg ("psphot", 3, "%d external sources (%d cmf, %d text) merged to yield %ld total sources", 164 nCMF + nTXT, nCMF, nTXT, sources->n); 55 165 return true; 56 166 } 57 167 58 168 // extract the input sources corresponding to this readout 169 // XXX this function needs to be updated to work with the new context of pshot inputs 59 170 psArray *psphotLoadPSFSources (pmConfig *config, const pmFPAview *view) { 171 172 bool status; 60 173 61 174 // find the currently selected readout … … 66 179 } 67 180 68 psArray *sources = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.SOURCES"); 181 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 182 if (!detections) { 183 psLogMsg ("psphot", 3, "no psf sources for this readout"); 184 return NULL; 185 } 186 187 psArray *sources = detections->allSources; 69 188 if (!sources) { 70 189 psLogMsg ("psphot", 3, "no psf sources for this readout"); 190 return NULL; 71 191 } 72 192 … … 74 194 } 75 195 196 // this function is used to fix sources which were loaded externally, but have passed from 197 // psphotDetectionsFromSources to psphotSourceStats and are now stored on 198 // detections->newSources. 199 bool psphotRepairLoadedSources (pmConfig *config, const pmFPAview *view) { 200 201 // find the currently selected readout 202 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 203 psAssert (file, "missing file?"); 204 205 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 206 psAssert (readout, "missing readout?"); 207 208 pmDetections *detections = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.DETECTIONS"); 209 if (!detections) { 210 psError(PSPHOT_ERR_CONFIG, false, "missing detections"); 211 return false; 212 } 213 214 psArray *sources = detections->newSources; 215 psAssert (sources, "missing sources?"); 216 217 // peak flux is wrong : set based on previous image 218 // use the peak measured in the moments analysis: 219 for (int i = 0; i < sources->n; i++) { 220 pmSource *source = sources->data[i]; 221 source->peak->flux = source->moments->Peak; 222 } 223 224 return true; 225 } 226 76 227 // generate the detection structure for the supplied array of sources 77 pmDetections *psphotDetectionsFromSources (pmConfig *config, psArray *sources) { 228 // XXX this currently assumes there is a single input file 229 bool psphotDetectionsFromSources (pmConfig *config, const pmFPAview *view, psArray *sources) { 230 231 // find the currently selected readout 232 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 233 psAssert (file, "missing file?"); 234 235 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 236 psAssert (readout, "missing readout?"); 78 237 79 238 pmDetections *detections = pmDetectionsAlloc(); … … 88 247 float snMin = psMetadataLookupF32(NULL, recipe, "MOMENTS_SN_MIN"); 89 248 if (!isfinite(snMin)) { 90 return NULL;249 return false; 91 250 } 92 251 … … 96 255 97 256 if (source->mode & PSF_SOURCE_MASK || !isfinite(source->psfMag)) { 257 continue; 258 } 259 260 // use the existing peak information, otherwise generate a new peak 261 if (source->peak) { 262 source->peak->assigned = false; // So the moments will be measured 263 psArrayAdd (detections->peaks, 100, source->peak); 98 264 continue; 99 265 } … … 108 274 peak->flux = flux; // this are being set wrong, but does it matter? 109 275 110 if (isfinite (source->errMag) && (source->errMag > 0.0)) {111 peak->SN = 1.0 / source->errMag; 112 } else {113 peak->SN = 0.0;114 }276 if (isfinite (source->errMag) && (source->errMag > 0.0)) { 277 peak->SN = 1.0 / source->errMag; 278 } else { 279 peak->SN = 0.0; 280 } 115 281 116 282 psArrayAdd (detections->peaks, 100, peak); … … 120 286 psLogMsg ("psphot", 3, "%ld PSF sources loaded", detections->peaks->n); 121 287 122 return detections; 288 // save detections on the readout->analysis 289 if (!psMetadataAddPtr (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_META_REPLACE | PS_DATA_UNKNOWN, "psphot detectinos", detections)) { 290 psError (PSPHOT_ERR_CONFIG, false, "problem saving detections on readout"); 291 return false; 292 } 293 psFree (detections); 294 return true; 123 295 } 124 296 … … 149 321 peak->flux = flux; // this are being set wrong, but does it matter? 150 322 151 if (isfinite (source->errMag) && (source->errMag > 0.0)) {152 peak->SN = 1.0 / source->errMag; 153 } else {154 peak->SN = 0.0;155 }323 if (isfinite (source->errMag) && (source->errMag > 0.0)) { 324 peak->SN = 1.0 / source->errMag; 325 } else { 326 peak->SN = 0.0; 327 } 156 328 157 329 source->peak = peak; … … 162 334 return true; 163 335 } 336 337 bool psphotCheckExtSources (pmConfig *config, const pmFPAview *view) { 338 339 bool status; 340 341 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSPHOT_RECIPE); 342 psAssert (recipe, "missing recipe"); 343 344 // find the currently selected readout 345 pmFPAfile *file = pmFPAfileSelectSingle(config->files, "PSPHOT.INPUT", 0); // File of interest 346 psAssert (file, "missing file?"); 347 348 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 349 psAssert (readout, "missing readout?"); 350 351 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 352 psAssert (detections, "missing detections?"); 353 354 // XXX allSources of newSources? 355 psArray *sources = detections->allSources; 356 psAssert (sources, "missing sources?"); 357 358 if (sources->n) { 359 // the user wants to make the psf from these stars; define them as psf stars: 360 for (int i = 0; i < sources->n; i++) { 361 pmSource *source = sources->data[i]; 362 source->mode |= PM_SOURCE_MODE_PSFSTAR; 363 } 364 // force psphotChoosePSF to use all loaded sources 365 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF_MAX_NSTARS", PS_META_REPLACE, "max number of sources for PSF model", sources->n); 366 367 // measure stats of externally specified sources 368 if (!psphotSourceStatsUpdate (sources, config, readout)) { 369 psError(PSPHOT_ERR_CONFIG, false, "failure to measure stats of existing sources"); 370 return false; 371 } 372 } else { 373 374 // find the detections (by peak and/or footprint) in the image. 375 if (!psphotFindDetections (config, view, true)) { 376 psError(PSPHOT_ERR_CONFIG, false, "unable to find detections in this image"); 377 return psphotReadoutCleanup (config, view); 378 } 379 380 // construct sources and measure basic stats 381 psphotSourceStats (config, view, true); 382 383 // find blended neighbors of very saturated stars 384 psphotDeblendSatstars (config, view); 385 386 // mark blended peaks PS_SOURCE_BLEND 387 if (!psphotBasicDeblend (config, view)) { 388 psLogMsg ("psphot", 3, "failed on deblend analysis"); 389 return psphotReadoutCleanup (config, view); 390 } 391 392 // classify sources based on moments, brightness 393 if (!psphotRoughClass (config, view)) { 394 psLogMsg ("psphot", 3, "failed to find a valid PSF clump for image"); 395 return psphotReadoutCleanup (config, view); 396 } 397 } 398 399 return true; 400 }
Note:
See TracChangeset
for help on using the changeset viewer.
