Changeset 17349
- Timestamp:
- Apr 6, 2008, 2:41:48 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080324/psphot/src/psphotExtendedSourceFits.c
r17340 r17349 8 8 int Nconvolve = 0; 9 9 int Nplain = 0; 10 bool savePics = true;10 bool savePics = false; 11 11 12 12 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 14 14 assert (maskVal); 15 15 16 // perform full non-linear fits / extended source analysis?16 // perform full extended source non-linear fits? 17 17 if (!psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS")) { 18 18 psLogMsg ("psphot", PS_LOG_INFO, "skipping extended source measurements\n"); … … 107 107 Next ++; 108 108 109 // save the modelFlux here in case we need to subtract it (for failure) 110 psImage *modelFluxStart = psMemIncrRefCounter (source->modelFlux); 111 109 112 if (savePics) { 110 113 psphotSaveImage (NULL, readout->image, "image.xp.fits"); 114 } 115 116 // array to store the pointers to the model flux images while the models are being fitted 117 psArray *modelFluxes = psArrayAllocEmpty (4); 118 119 // allocate the array to store the model fits 120 if (source->modelFits == NULL) { 121 source->modelFits = psArrayAllocEmpty (4); 111 122 } 112 123 … … 136 147 assert (status); 137 148 138 psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6); 149 // XXX psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6); 150 // XXX psTraceSetLevel ("psphot.psphotModelWithPSF_LMM", 6); 139 151 140 152 // fit the model as convolved or not … … 145 157 Nconvolve ++; 146 158 } else { 159 psFree (source->modelFlux); 160 source->modelFlux = NULL; 147 161 modelFit = psphotFitEXT (readout, source, modelType, maskVal); 162 pmSourceCacheModel (source, maskVal); 148 163 psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (modelFit->type), modelFit->chisq); 149 164 Nplain ++; … … 154 169 } 155 170 156 if (savePics) { 157 pmModel *saveModel = source->modelEXT; 158 source->modelEXT = modelFit; 159 pmSourceCacheModel (source, maskVal); // XXX put this in the source model function? 160 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 161 162 psphotSaveImage (NULL, readout->image, "image.xf.fits"); 163 164 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 165 source->modelEXT = saveModel; 166 167 char key[10]; 168 fprintf (stdout, "continue? "); 169 fgets (key, 8, stdin); 170 if (key[0] == 'n') { 171 savePics = false; 172 } 173 } 174 175 if (source->modelFits == NULL) { 176 source->modelFits = psArrayAllocEmpty (5); 177 } 178 171 // save each of the model flux images and store the best 172 psArrayAdd (modelFluxes, 4, source->modelFlux); 173 179 174 // test for fit quality / result 180 psArrayAdd (source->modelFits, 5, modelFit); 175 psArrayAdd (source->modelFits, 4, modelFit); 176 181 177 psFree (modelFit); 182 178 } … … 204 200 // re-subtract the object, leave local sky 205 201 psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->x, source->moments->y); 202 203 // replace original model, subtract it 204 psFree (source->modelFlux); 205 source->modelFlux = modelFluxStart; 206 206 207 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 207 208 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 209 210 psFree (modelFluxes); 208 211 209 212 if (savePics) { … … 216 219 } 217 220 } 218 219 221 continue; 220 222 } 221 223 222 // XXX probably need to free the current value224 // save the best extended model in modelEXT 223 225 psFree (source->modelEXT); 224 226 source->modelEXT = psMemIncrRefCounter (source->modelFits->data[minModel]); 225 227 226 psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq); 227 228 // cache only the chosen model 229 pmSourceCacheModel (source, maskVal); // XXX put this in the source model function? 230 psTrace ("psphot", 5, "psf-convolved model for source at %7.1f, %7.1f", source->moments->x, source->moments->y); 231 232 // re-subtract the object, leave local sky 228 // save the modelFlux for the best model 229 psFree (source->modelFlux); 230 source->modelFlux = psMemIncrRefCounter (modelFluxes->data[minModel]); 231 232 // subtract the best fit from the object, leave local sky 233 233 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 234 234 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 235 236 // the initial model flux is no longer needed 237 psFree (modelFluxStart); 238 psFree (modelFluxes); 239 240 psTrace ("psphot", 4, "best ext model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (source->modelEXT->type), source->modelEXT->chisq); 241 psTrace ("psphot", 5, "extended source model for source at %7.1f, %7.1f", source->moments->x, source->moments->y); 235 242 236 243 if (savePics) {
Note:
See TracChangeset
for help on using the changeset viewer.
