- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psphot (modified) (1 prop)
-
psphot/src (modified) (2 props)
-
psphot/src/psphotReplaceUnfit.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/psphot
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/psphot/src
- Property svn:ignore
-
old new 22 22 psphotMakePSF 23 23 psphotStack 24 psphotModelTest
-
- Property svn:mergeinfo set to
- Property svn:ignore
-
branches/meh_branches/ppstack_test/psphot/src/psphotReplaceUnfit.c
r31452 r33415 9 9 10 10 for (int i = 0; i < sources->n; i++) { 11 source = sources->data[i];12 13 // replace other sources?14 if (source->mode & PM_SOURCE_MODE_FAIL) goto replace;15 continue;11 source = sources->data[i]; 12 13 // replace other sources? 14 if (source->mode & PM_SOURCE_MODE_FAIL) goto replace; 15 continue; 16 16 17 17 replace: … … 23 23 24 24 // for now, let's store the detections on the readout->analysis for each readout 25 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule )25 bool psphotReplaceAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState) 26 26 { 27 27 bool status = true; … … 35 35 // loop over the available readouts 36 36 for (int i = 0; i < num; i++) { 37 if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe )) {37 if (!psphotReplaceAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) { 38 38 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 39 39 return false; … … 43 43 } 44 44 45 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe) { 46 47 bool status; 48 pmSource *source; 45 bool psphotReplaceAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) { 46 47 bool status; 49 48 50 49 psTimerStart ("psphot.replace"); … … 75 74 76 75 for (int i = 0; i < sources->n; i++) { 77 source = sources->data[i]; 78 79 // replace other sources? 80 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 81 82 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 76 pmSource *source = sources->data[i]; 77 78 if (ignoreState) { 79 // rely on the type of source to decide if we subtract it or not 80 81 // skip non-astronomical objects (very likely defects) 82 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 83 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 84 85 // do not include CRs in the full ensemble fit 86 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 87 88 // do not include MOMENTS_FAILURES in the fit 89 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 90 } else { 91 // if we respect the state, do not replace unsubtracted sources 92 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 93 } 94 95 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 83 96 } 84 97 … … 88 101 } 89 102 90 bool psphotRemoveAllSources (const psArray *sources, const psMetadata *recipe) { 103 // for now, let's store the detections on the readout->analysis for each readout 104 bool psphotRemoveAllSources (pmConfig *config, const pmFPAview *view, const char *filerule, bool ignoreState) 105 { 106 bool status = true; 107 108 // select the appropriate recipe information 109 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 110 psAssert (recipe, "missing recipe?"); 111 112 int num = psphotFileruleCount(config, filerule); 113 114 // loop over the available readouts 115 for (int i = 0; i < num; i++) { 116 if (!psphotRemoveAllSourcesReadout (config, view, filerule, i, recipe, ignoreState)) { 117 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 118 return false; 119 } 120 } 121 return true; 122 } 123 124 bool psphotRemoveAllSourcesReadout (pmConfig *config, const pmFPAview *view, const char *filename, int index, psMetadata *recipe, bool ignoreState) { 125 126 bool status; 127 128 psTimerStart ("psphot.replace"); 129 130 // find the currently selected readout 131 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filename, index); // File of interest 132 psAssert (file, "missing file?"); 133 134 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 135 psAssert (readout, "missing readout?"); 136 137 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 138 psAssert (detections, "missing detections?"); 139 140 psArray *sources = detections->allSources; 141 psAssert (sources, "missing sources?"); 142 143 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 144 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 145 psAssert (maskVal, "missing mask value?"); 146 147 // bit-mask to mark pixels not used in analysis 148 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 149 assert (markVal); 150 151 // maskVal is used to test for rejected pixels, and must include markVal 152 maskVal |= markVal; 153 154 for (int i = 0; i < sources->n; i++) { 155 pmSource *source = sources->data[i]; 156 157 if (ignoreState) { 158 // rely on the type of source to decide if we subtract it or not 159 160 // skip non-astronomical objects (very likely defects) 161 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 162 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 163 164 // do not include CRs in the full ensemble fit 165 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 166 167 // do not include MOMENTS_FAILURES in the fit 168 if (source->mode & PM_SOURCE_MODE_MOMENTS_FAILURE) continue; 169 } else { 170 // if we respect the state, only remove unsubtracted sources 171 if ((source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 172 } 173 174 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 175 } 176 177 psphotVisualShowImage(readout); 178 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 179 return true; 180 } 181 182 bool psphotRemoveAllSourcesByArray (const psArray *sources, const psMetadata *recipe) { 91 183 92 184 bool status; … … 100 192 101 193 for (int i = 0; i < sources->n; i++) { 102 source = sources->data[i];103 104 // replace other sources?105 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;106 107 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);194 source = sources->data[i]; 195 196 // replace other sources? 197 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue; 198 199 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 108 200 } 109 201 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); … … 158 250 159 251 for (int i = 0; i < sources->n; i++) { 160 source = sources->data[i];161 162 // sources have not yet been subtracted in this image (but this flag may be raised)163 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED;164 if (!source->modelPSF) continue;165 166 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS];167 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS];168 float radius = source->modelPSF->fitRadius;169 170 // force a redefine to this image171 pmSourceFreePixels(source);172 pmSourceRedefinePixels (source, readout, Xo, Yo, radius);252 source = sources->data[i]; 253 254 // sources have not yet been subtracted in this image (but this flag may be raised) 255 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 256 if (!source->modelPSF) continue; 257 258 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 259 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 260 float radius = source->modelPSF->fitRadius; 261 262 // force a redefine to this image 263 pmSourceFreePixels(source); 264 pmSourceRedefinePixels (source, readout, Xo, Yo, radius); 173 265 } 174 266 return true; … … 229 321 230 322 for (int i = 0; i < sources->n; i++) { 231 source = sources->data[i]; 232 233 // *** we need to cache the 'best' model, and we have 3 cases: 234 // 1) model is the psf model --> generate from the new psf 235 // 2) model is an unconvolved extended model --> just cache the copy (not perfect) 236 // 3) model is a convolved extended model --> re-generate 237 238 // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits 239 bool isPSF = false; 240 pmModel *model = pmSourceGetModel(&isPSF, source); 241 if (!model) continue; 242 243 float radius = model->fitRadius; // save for future use below 244 245 // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM 246 if (isPSF || model->isPCM) { 247 // the guess central intensity comes from the peak: 248 float Io = source->peak->rawFlux; 249 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 250 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 251 252 // generate a model for this object with Io = 1.0 253 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io); 254 if (modelPSF == NULL) { 255 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo); 256 continue; 257 } 258 259 // set the source PSF model 260 psFree (source->modelPSF); 261 source->modelPSF = modelPSF; 262 source->modelPSF->fitRadius = radius; 263 } 264 265 if (model->isPCM) { 266 psAssert(false, "this section is not complete"); 267 268 pmSourceCachePSF (source, maskVal); 269 270 psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize); 271 if (!psfKernel) { 272 psWarning ("no psf kernel"); 273 } 274 275 // generate an image of the right size 276 psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 277 psImageInit (rawModelFlux, 0.0); 323 source = sources->data[i]; 324 325 // *** we need to cache the 'best' model, and we have 3 cases: 326 // 1) model is the psf model --> generate from the new psf 327 // 2) model is an unconvolved extended model --> just cache the copy (not perfect) 328 // 3) model is a convolved extended model --> re-generate 329 330 // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits 331 bool isPSF = false; 332 pmModel *model = pmSourceGetModel(&isPSF, source); 333 if (!model) continue; 334 335 float radius = model->fitRadius; // save for future use below 336 337 // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM 338 if (isPSF || model->isPCM) { 339 // the guess central intensity comes from the peak: 340 float Io = source->peak->rawFlux; 341 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 342 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 343 344 // generate a model for this object with Io = 1.0 345 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io); 346 if (modelPSF == NULL) { 347 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo); 348 continue; 349 } 350 351 // set the source PSF model 352 psFree (source->modelPSF); 353 source->modelPSF = modelPSF; 354 source->modelPSF->fitRadius = radius; 355 model = source->modelPSF; 356 } 357 358 if (model->isPCM) { 359 psAssert(false, "this section is not complete"); 360 361 pmSourceCachePSF (source, maskVal); 362 363 psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize); 364 if (!psfKernel) { 365 psWarning ("no psf kernel"); 366 } 367 368 // generate an image of the right size 369 psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 370 psImageInit (rawModelFlux, 0.0); 278 371 279 // insert the model image normalized to 1.0280 pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);281 282 psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel);372 // insert the model image normalized to 1.0 373 pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal); 374 375 psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel); 283 376 284 psFree (psfKernel);285 psFree (rawModelFlux);286 }287 288 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!)377 psFree (psfKernel); 378 psFree (rawModelFlux); 379 } 380 381 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!) 289 382 } 290 383
Note:
See TracChangeset
for help on using the changeset viewer.
