- Timestamp:
- Aug 26, 2010, 9:18:39 AM (16 years ago)
- Location:
- branches/sc_branches/trunkTest
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sc_branches/trunkTest
- Property svn:mergeinfo changed
-
branches/sc_branches/trunkTest/psphot
- Property svn:mergeinfo deleted
-
branches/sc_branches/trunkTest/psphot/src/psphotBlendFit.c
r28405 r29060 65 65 assert (status && fitIter > 0); 66 66 67 float fitTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_TOL"); // Fit tolerance 68 assert (status && isfinite(fitTol) && fitTol > 0); 67 float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance 68 if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) { 69 fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance 70 if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) { 71 psAbort("PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive"); 72 } 73 } 74 75 float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance 76 if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) { 77 fitMaxTol = 1.0; 78 } 69 79 70 80 bool poisson = psMetadataLookupBool(&status, recipe, "POISSON.ERRORS.PHOT.LMM"); // Poisson errors? 71 81 assert (status); 72 82 83 float maxChisqDOF = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_CHISQ"); // Fit tolerance 84 73 85 float skySig = psMetadataLookupF32(&status, recipe, "SKY_SIG"); 74 86 assert (status && isfinite(skySig) && skySig > 0); 75 87 76 88 // Define source fitting parameters for extended source fits 77 pmSourceFitModelInit(fitIter, fitTol, PS_SQR(skySig), poisson); 89 pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc(); 90 fitOptions->nIter = fitIter; 91 fitOptions->minTol = fitMinTol; 92 fitOptions->maxTol = fitMaxTol; 93 fitOptions->maxChisqDOF = maxChisqDOF; 94 fitOptions->poissonErrors = poisson; 95 fitOptions->weight = PS_SQR(skySig); 96 fitOptions->mode = PM_SOURCE_FIT_PSF; 78 97 79 98 psphotInitLimitsPSF (recipe, readout); 80 psphotInitLimitsEXT (recipe );81 psphotInitRadiusPSF (recipe, readout ->analysis, psf->type);99 psphotInitLimitsEXT (recipe, readout); 100 psphotInitRadiusPSF (recipe, readout); 82 101 83 102 // starts the timer, sets up the array of fitSets … … 88 107 if (!sources->n) { 89 108 psLogMsg ("psphot", PS_LOG_INFO, "no sources, skipping blend"); 109 psFree (fitOptions); 90 110 return true; 91 111 } … … 112 132 psArrayAdd(job->args, 1, psf); 113 133 psArrayAdd(job->args, 1, newSources); // return for new sources 134 psArrayAdd(job->args, 1, fitOptions); // default fit options 114 135 psFree (newSources); 115 136 … … 121 142 if (!psThreadJobAddPending(job)) { 122 143 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 144 psFree (fitOptions); 123 145 return NULL; 124 146 } 125 126 # if (0)127 {128 int nfit = 0;129 int npsf = 0;130 int next = 0;131 int nfail = 0;132 psArray *newSources = psArrayAllocEmpty(16);133 134 if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) {135 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");136 return NULL;137 }138 Nfit += nfit;139 Npsf += npsf;140 Next += next;141 Nfail += nfail;142 143 // add these back onto sources144 for (int k = 0; k < newSources->n; k++) {145 psArrayAdd (sources, 16, newSources->data[k]);146 }147 psFree (newSources);148 }149 # endif150 147 } 151 148 … … 153 150 if (!psThreadPoolWait (false)) { 154 151 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 152 psFree (fitOptions); 155 153 return NULL; 156 154 } … … 163 161 } else { 164 162 psScalar *scalar = NULL; 165 scalar = job->args->data[ 5];163 scalar = job->args->data[6]; 166 164 Nfit += scalar->data.S32; 167 scalar = job->args->data[ 6];165 scalar = job->args->data[7]; 168 166 Npsf += scalar->data.S32; 169 scalar = job->args->data[ 7];167 scalar = job->args->data[8]; 170 168 Next += scalar->data.S32; 171 scalar = job->args->data[ 8];169 scalar = job->args->data[9]; 172 170 Nfail += scalar->data.S32; 173 171 … … 186 184 psphotSaveImage (NULL, readout->image, "image.v2.fits"); 187 185 } 186 psFree (fitOptions); 188 187 189 188 psLogMsg ("psphot.psphotBlendFit", PS_LOG_INFO, "fit models: %f sec for %d objects (%d psf, %d ext, %d failed, %ld skipped)\n", psTimerMark ("psphot.fit.nonlinear"), Nfit, Npsf, Next, Nfail, sources->n - Nfit); … … 204 203 psScalar *scalar = NULL; 205 204 206 pmReadout *readout = job->args->data[0]; 207 psMetadata *recipe = job->args->data[1]; 208 psArray *sources = job->args->data[2]; 209 pmPSF *psf = job->args->data[3]; 210 psArray *newSources = job->args->data[4]; 205 pmReadout *readout = job->args->data[0]; 206 psMetadata *recipe = job->args->data[1]; 207 psArray *sources = job->args->data[2]; 208 pmPSF *psf = job->args->data[3]; 209 psArray *newSources = job->args->data[4]; 210 pmSourceFitOptions *fitOptions = job->args->data[5]; 211 211 212 212 // bit-masks to test for good/bad pixels … … 269 269 Nfit ++; 270 270 271 if (0) { 272 psF32 Mxx = source->moments->Mxx; 273 psF32 Myy = source->moments->Myy; 274 fprintf (stderr, "1: Mxx: %f, Myy: %f\n", Mxx, Myy); 275 } 276 271 277 // try fitting PSFs or extended sources depending on source->mode 272 278 // these functions subtract the resulting fitted source 273 279 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 274 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) {280 if (psphotFitBlob (readout, source, newSources, psf, fitOptions, maskVal, markVal)) { 275 281 source->type = PM_SOURCE_TYPE_EXTENDED; 276 282 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); … … 280 286 } 281 287 } else { 282 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) {288 if (psphotFitBlend (readout, source, psf, fitOptions, maskVal, markVal)) { 283 289 source->type = PM_SOURCE_TYPE_STAR; 284 290 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); … … 289 295 } 290 296 297 if (0) { 298 psF32 Mxx = source->moments->Mxx; 299 psF32 Myy = source->moments->Myy; 300 fprintf (stderr, "2: Mxx: %f, Myy: %f\n", Mxx, Myy); 301 } 302 291 303 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); 292 304 Nfail ++; … … 298 310 299 311 // change the value of a scalar on the array (wrap this and put it in psArray.h) 300 scalar = job->args->data[ 5];312 scalar = job->args->data[6]; 301 313 scalar->data.S32 = Nfit; 302 314 303 scalar = job->args->data[ 6];315 scalar = job->args->data[7]; 304 316 scalar->data.S32 = Npsf; 305 317 306 scalar = job->args->data[ 7];318 scalar = job->args->data[8]; 307 319 scalar->data.S32 = Next; 308 320 309 scalar = job->args->data[ 8];321 scalar = job->args->data[9]; 310 322 scalar->data.S32 = Nfail; 311 323
Note:
See TracChangeset
for help on using the changeset viewer.
