Changeset 17340
- Timestamp:
- Apr 6, 2008, 10:14:53 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080324/psphot/src/psphotExtendedSourceFits.c
r17314 r17340 1 # include "psphot .h"1 # include "psphotInternal.h" 2 2 3 3 // non-linear model fitting for extended sources … … 8 8 int Nconvolve = 0; 9 9 int Nplain = 0; 10 bool savePics = true; 10 11 11 12 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) … … 40 41 } 41 42 42 psMetadata *model = (psMetadata *) item->data ;43 psMetadata *model = (psMetadata *) item->data.md; 43 44 44 45 // check on the model type 45 46 char *modelName = psMetadataLookupStr (&status, model, "MODEL"); 46 int modelType = p sModelClassGetType (modelName);47 int modelType = pmModelClassGetType (modelName); 47 48 if (modelType < 0) { 48 psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, model Type);49 psAbort ("Unknown model class for EXTENDED_SOURCE_MODEL entry %s: %s", item->name, modelName); 49 50 } 50 51 psMetadataAddS32 (model, PS_LIST_TAIL, "MODEL_TYPE", PS_META_REPLACE, "", modelType); … … 61 62 char *convolvedWord = psMetadataLookupStr (&status, model, "PSF_CONVOLVED"); 62 63 if (!status || (strcasecmp (convolvedWord, "true") && strcasecmp (convolvedWord, "false"))) { 63 psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name , modelType);64 psAbort ("PSF_CONVOLVED entry invalid or missing for EXTENDED_SOURCE_MODEL entry %s", item->name); 64 65 } 65 66 bool convolved = !strcasecmp (convolvedWord, "true"); 66 67 psMetadataAddBool (model, PS_LIST_TAIL, "PSF_CONVOLVED_VALUE", PS_META_REPLACE, "", convolved); 67 68 } 69 psFree (iter); 68 70 69 71 // option to limit analysis to a specific region … … 72 74 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 73 75 74 // S/N limit to perform full non-linear fits75 float SN_LIM = psMetadataLookupF32 (&status, recipe, "EXTENDED_SOURCE_SN_LIM");76 77 76 // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box) 78 77 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE"); 79 if (!status) { 80 psfSize = 2; 81 } 78 assert (status); 82 79 83 80 // source analysis is done in S/N order (brightest first) … … 110 107 Next ++; 111 108 109 if (savePics) { 110 psphotSaveImage (NULL, readout->image, "image.xp.fits"); 111 } 112 112 113 // loop here over the models chosen for each source (exclude by S/N) 113 114 psMetadataIterator *iter = psMetadataIteratorAlloc (models, PS_LIST_HEAD, NULL); … … 117 118 // XXX this should have been forced above 118 119 assert (item->type == PS_DATA_METADATA); 119 psMetadata *model = (psMetadata *) item->data ;120 psMetadata *model = (psMetadata *) item->data.md; 120 121 121 122 // check the SNlim and skip model if source is too faint … … 135 136 assert (status); 136 137 138 psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6); 139 137 140 // fit the model as convolved or not 138 // XXX use the values above, rework this function141 pmModel *modelFit = NULL; 139 142 if (convolved) { 140 pmModel *EXT = psphotPSFConvModel (readout, source, modelType, maskVal, psfSize); 143 modelFit = psphotPSFConvModel (readout, source, modelType, maskVal, psfSize); 144 psTrace ("psphot", 4, "fit psf-conv model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (modelFit->type), modelFit->chisq); 141 145 Nconvolve ++; 142 146 } else { 143 pmModel *EXT = psphotFitExt (readout, source, modelType, maskVal); 147 modelFit = psphotFitEXT (readout, source, modelType, maskVal); 148 psTrace ("psphot", 4, "fit plain model for %f, %f : %s chisq = %f\n", source->moments->x, source->moments->y, pmModelClassGetName (modelFit->type), modelFit->chisq); 144 149 Nplain ++; 145 150 } 146 if (! EXT) {147 ps Error(PSPHOT_ERR_UNKNOWN, false, "failure to fit extended model");148 return false;151 if (!modelFit) { 152 psTrace ("psphot", 5, "failed to generate model guess for object at %f, %f", source->moments->x, source->moments->y); 153 continue; 149 154 } 155 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 } 150 174 151 175 if (source->modelFits == NULL) { … … 154 178 155 179 // test for fit quality / result 156 psArrayAdd (source->modelFits, 5, EXT); 180 psArrayAdd (source->modelFits, 5, modelFit); 181 psFree (modelFit); 157 182 } 183 psFree (iter); 158 184 159 185 // evaluate the relative quality of the models, choose one 160 float minChisq = 0;0;186 float minChisq = NAN; 161 187 int minModel = -1; 162 188 for (int i = 0; i < source->modelFits->n; i++) { … … 176 202 177 203 if (minModel == -1) { 178 psAbort ("failed to fit extended source model"); 204 // re-subtract the object, leave local sky 205 psTrace ("psphot", 5, "failed to fit extended source model to object at %f, %f", source->moments->x, source->moments->y); 206 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 207 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 208 209 if (savePics) { 210 psphotSaveImage (NULL, readout->image, "image.xp.fits"); 211 char key[10]; 212 fprintf (stdout, "continue? "); 213 fgets (key, 8, stdin); 214 if (key[0] == 'n') { 215 savePics = false; 216 } 217 } 218 219 continue; 179 220 } 180 221 181 222 // XXX probably need to free the current value 182 223 psFree (source->modelEXT); 183 source->modelEXT = source->modelFits->data[minModel]; 224 source->modelEXT = psMemIncrRefCounter (source->modelFits->data[minModel]); 225 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); 184 227 185 228 // cache only the chosen model … … 190 233 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 191 234 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 235 236 if (savePics) { 237 psphotSaveImage (NULL, readout->image, "image.xm.fits"); 238 char key[10]; 239 fprintf (stdout, "continue? "); 240 fgets (key, 8, stdin); 241 if (key[0] == 'n') { 242 savePics = false; 243 } 244 } 192 245 } 193 246
Note:
See TracChangeset
for help on using the changeset viewer.
