- Timestamp:
- Feb 14, 2011, 1:05:28 PM (15 years ago)
- Location:
- branches/czw_branch/20101203
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20101203
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/psphot
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/psphot/src/psphotReplaceUnfit.c
r30118 r30631 75 75 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 76 76 } 77 78 psphotVisualShowImage(readout); 77 79 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 78 80 return true; … … 101 103 return true; 102 104 } 105 106 // modify the sources to point at the corresponding pixels for the given filerule 107 bool psphotRedefinePixels (pmConfig *config, const pmFPAview *view, const char *filerule) 108 { 109 bool status = true; 110 111 // select the appropriate recipe information 112 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 113 psAssert (recipe, "missing recipe?"); 114 115 int num = psphotFileruleCount(config, filerule); 116 117 // loop over the available readouts 118 for (int i = 0; i < num; i++) { 119 if (!psphotRedefinePixelsReadout (config, view, filerule, i, recipe)) { 120 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 121 return false; 122 } 123 } 124 return true; 125 } 126 127 bool psphotRedefinePixelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 128 129 bool status; 130 pmSource *source; 131 132 psTimerStart ("psphot.replace"); 133 134 // find the currently selected readout 135 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 136 psAssert (file, "missing file?"); 137 138 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 139 psAssert (readout, "missing readout?"); 140 141 // XXX the sources have already been copied (merge into here?) 142 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 143 psAssert (detections, "missing detections?"); 144 145 psArray *sources = detections->allSources; 146 psAssert (sources, "missing sources?"); 147 148 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 149 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 150 psAssert (maskVal, "missing mask value?"); 151 152 for (int i = 0; i < sources->n; i++) { 153 source = sources->data[i]; 154 155 // sources have not yet been subtracted in this image (but this flag may be raised) 156 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 157 158 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 159 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 160 float radius = source->modelPSF->fitRadius; 161 162 // force a redefine to this image 163 pmSourceFreePixels(source); 164 pmSourceRedefinePixels (source, readout, Xo, Yo, radius); 165 } 166 return true; 167 } 168 169 // for now, let's store the detections on the readout->analysis for each readout 170 bool psphotResetModels (pmConfig *config, const pmFPAview *view, const char *filerule) 171 { 172 bool status = true; 173 174 // select the appropriate recipe information 175 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 176 psAssert (recipe, "missing recipe?"); 177 178 int num = psphotFileruleCount(config, filerule); 179 180 // loop over the available readouts 181 for (int i = 0; i < num; i++) { 182 if (!psphotResetModelsReadout (config, view, filerule, i, recipe)) { 183 psError (PSPHOT_ERR_CONFIG, false, "failed to replace all sources for %s entry %d", filerule, i); 184 return false; 185 } 186 } 187 return true; 188 } 189 190 bool psphotResetModelsReadout (pmConfig *config, const pmFPAview *view, const char *filerule, int index, psMetadata *recipe) { 191 192 bool status; 193 pmSource *source; 194 195 psTimerStart ("psphot.replace"); 196 197 // find the currently selected readout 198 pmFPAfile *file = pmFPAfileSelectSingle(config->files, filerule, index); // File of interest 199 psAssert (file, "missing file?"); 200 201 pmReadout *readout = pmFPAviewThisReadout(view, file->fpa); 202 psAssert (readout, "missing readout?"); 203 204 // XXX the sources have already been copied (merge into here?) 205 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 206 psAssert (detections, "missing detections?"); 207 208 psArray *sources = detections->allSources; 209 psAssert (sources, "missing sources?"); 210 211 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 212 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels 213 psAssert (maskVal, "missing mask value?"); 214 215 // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box) 216 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE"); 217 assert (status); 218 219 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF"); 220 psAssert (psf, "missing psf?"); 221 222 for (int i = 0; i < sources->n; i++) { 223 source = sources->data[i]; 224 225 // *** we need to cache the 'best' model, and we have 3 cases: 226 // 1) model is the psf model --> generate from the new psf 227 // 2) model is an unconvolved extended model --> just cache the copy (not perfect) 228 // 3) model is a convolved extended model --> re-generate 229 230 // use the 'best' model to cache the model (PSF or EXT : EXT may point at one of modelFits 231 bool isPSF = false; 232 pmModel *model = pmSourceGetModel(&isPSF, source); 233 float radius = model->fitRadius; // save for future use below 234 235 // regenerate the PSF if the model is a PSF, or if we need the PSF for a PCM 236 if (isPSF || model->isPCM) { 237 // the guess central intensity comes from the peak: 238 float Io = source->peak->flux; 239 float Xo = source->modelPSF->params->data.F32[PM_PAR_XPOS]; 240 float Yo = source->modelPSF->params->data.F32[PM_PAR_YPOS]; 241 242 // generate a model for this object with Io = 1.0 243 pmModel *modelPSF = pmModelFromPSFforXY(psf, Xo, Yo, Io); 244 if (modelPSF == NULL) { 245 psWarning ("Failed to determine PSF model for source at (%f,%f), skipping", Xo, Yo); 246 continue; 247 } 248 249 // set the source PSF model 250 psFree (source->modelPSF); 251 source->modelPSF = modelPSF; 252 source->modelPSF->fitRadius = radius; 253 } 254 255 if (model->isPCM) { 256 psAssert(false, "this section is not complete"); 257 258 pmSourceCachePSF (source, maskVal); 259 260 psKernel *psfKernel = pmPCMkernelFromPSF(source, psfSize); 261 if (!psfKernel) { 262 psWarning ("no psf kernel"); 263 } 264 265 // generate an image of the right size 266 psImage *rawModelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 267 psImageInit (rawModelFlux, 0.0); 268 269 // insert the model image normalized to 1.0 270 pmModelAdd (rawModelFlux, NULL, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal); 271 272 psImageConvolveFFT (source->modelFlux, rawModelFlux, NULL, 0, psfKernel); 273 274 psFree (psfKernel); 275 psFree (rawModelFlux); 276 } 277 278 pmSourceCacheModel (source, maskVal); // ALLOC x14 (!) 279 } 280 281 psLogMsg ("psphot.replace", PS_LOG_INFO, "subtracted models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); 282 return true; 283 } 284
Note:
See TracChangeset
for help on using the changeset viewer.
