Changeset 21359 for trunk/psphot/src/psphotBlendFit.c
- Timestamp:
- Feb 5, 2009, 3:12:59 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotBlendFit.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotBlendFit.c
r21250 r21359 1 1 # include "psphotInternal.h" 2 3 bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources); 2 4 3 5 // XXX I don't like this name … … 21 23 nThreads = 0; 22 24 } 23 // nThreads = 0; // XXX until testing is complete, do not thread this function24 25 25 26 // source fitting parameters for extended source fits … … 63 64 for (int j = 0; j < cells->n; j++) { 64 65 65 // allocate a job -- if threads are not defined, this just runs the job 66 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 67 psArray *newSources = psArrayAllocEmpty(16); 68 69 psArrayAdd(job->args, 1, readout); 70 psArrayAdd(job->args, 1, recipe); 71 psArrayAdd(job->args, 1, cells->data[j]); // sources 72 psArrayAdd(job->args, 1, psf); 73 psArrayAdd(job->args, 1, newSources); // return for new sources 74 psFree (newSources); 75 76 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 77 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 78 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 79 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 80 81 if (!psThreadJobAddPending(job)) { 66 if (nThreads) { 67 // allocate a job -- if threads are not defined, this just runs the job 68 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 69 psArray *newSources = psArrayAllocEmpty(16); 70 71 psArrayAdd(job->args, 1, readout); 72 psArrayAdd(job->args, 1, recipe); 73 psArrayAdd(job->args, 1, cells->data[j]); // sources 74 psArrayAdd(job->args, 1, psf); 75 psArrayAdd(job->args, 1, newSources); // return for new sources 76 psFree (newSources); 77 78 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 79 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 80 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 81 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 82 83 if (!psThreadJobAddPending(job)) { 84 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 85 psFree (job); 86 return NULL; 87 } 88 psFree(job); 89 } else { 90 int nfit = 0; 91 int npsf = 0; 92 int next = 0; 93 int nfail = 0; 94 psArray *newSources = psArrayAllocEmpty(16); 95 96 if (!psphotBlendFit_Unthreaded (&nfit, &npsf, &next, &nfail, readout, recipe, cells->data[j], psf, newSources)) { 97 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 98 return NULL; 99 } 100 Nfit += nfit; 101 Npsf += npsf; 102 Next += next; 103 Nfail += nfail; 104 105 // add these back onto sources 106 for (int k = 0; k < newSources->n; k++) { 107 psArrayAdd (sources, 16, newSources->data[k]); 108 } 109 psFree (newSources); 110 } 111 } 112 113 if (nThreads) { 114 // wait for the threads to finish and manage results 115 if (!psThreadPoolWait (false)) { 82 116 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 83 psFree (job);84 117 return NULL; 85 118 } 86 psFree(job); 87 88 } 89 90 // wait for the threads to finish and manage results 91 if (!psThreadPoolWait (false)) { 92 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 93 return NULL; 94 } 95 96 // we have only supplied one type of job, so we can assume the types here 97 psThreadJob *job = NULL; 98 while ((job = psThreadJobGetDone()) != NULL) { 99 if (job->args->n < 1) { 100 fprintf (stderr, "error with job\n"); 101 } else { 102 psScalar *scalar = NULL; 103 scalar = job->args->data[5]; 104 Nfit += scalar->data.S32; 105 scalar = job->args->data[6]; 106 Npsf += scalar->data.S32; 107 scalar = job->args->data[7]; 108 Next += scalar->data.S32; 109 scalar = job->args->data[8]; 110 Nfail += scalar->data.S32; 111 112 // add these back onto sources 113 psArray *newSources = job->args->data[4]; 114 for (int j = 0; j < newSources->n; j++) { 115 psArrayAdd (sources, 16, newSources->data[j]); 119 120 // we have only supplied one type of job, so we can assume the types here 121 psThreadJob *job = NULL; 122 while ((job = psThreadJobGetDone()) != NULL) { 123 if (job->args->n < 1) { 124 fprintf (stderr, "error with job\n"); 125 } else { 126 psScalar *scalar = NULL; 127 scalar = job->args->data[5]; 128 Nfit += scalar->data.S32; 129 scalar = job->args->data[6]; 130 Npsf += scalar->data.S32; 131 scalar = job->args->data[7]; 132 Next += scalar->data.S32; 133 scalar = job->args->data[8]; 134 Nfail += scalar->data.S32; 135 136 // add these back onto sources 137 psArray *newSources = job->args->data[4]; 138 for (int j = 0; j < newSources->n; j++) { 139 psArrayAdd (sources, 16, newSources->data[j]); 140 } 116 141 } 117 }118 psFree(job);142 psFree(job); 143 } 119 144 } 120 145 } … … 249 274 return true; 250 275 } 276 277 bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources) { 278 279 bool status = false; 280 int Nfit = 0; 281 int Npsf = 0; 282 int Next = 0; 283 int Nfail = 0; 284 285 // bit-masks to test for good/bad pixels 286 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 287 assert (maskVal); 288 289 // bit-mask to mark pixels not used in analysis 290 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 291 assert (markVal); 292 293 // maskVal is used to test for rejected pixels, and must include markVal 294 maskVal |= markVal; 295 296 // S/N limit to perform full non-linear fits 297 float FIT_SN_LIM = psMetadataLookupF32 (&status, recipe, "FULL_FIT_SN_LIM"); 298 299 // option to limit analysis to a specific region 300 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 301 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 302 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 303 304 for (int i = 0; i < sources->n; i++) { 305 pmSource *source = sources->data[i]; 306 307 // skip non-astronomical objects (very likely defects) 308 if (source->mode & PM_SOURCE_MODE_BLEND) continue; 309 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 310 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 311 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 312 313 // skip DBL second sources (ie, added by psphotFitBlob) 314 if (source->mode & PM_SOURCE_MODE_PAIR) continue; 315 316 // limit selection to some SN limit 317 if (source->peak->SN < FIT_SN_LIM) continue; 318 319 // exclude sources outside optional analysis region 320 if (source->peak->xf < AnalysisRegion.x0) continue; 321 if (source->peak->yf < AnalysisRegion.y0) continue; 322 if (source->peak->xf > AnalysisRegion.x1) continue; 323 if (source->peak->yf > AnalysisRegion.y1) continue; 324 325 // if model is NULL, we don't have a starting guess 326 if (source->modelPSF == NULL) continue; 327 328 // skip sources which are insignificant flux? 329 // XXX this is somewhat ad-hoc 330 if (source->modelPSF->params->data.F32[1] < 0.1) { 331 psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n", 332 source->modelPSF->params->data.F32[1], 333 source->modelPSF->params->data.F32[2], 334 source->modelPSF->params->data.F32[3]); 335 continue; 336 } 337 338 // replace object in image 339 if (source->mode & PM_SOURCE_MODE_SUBTRACTED) { 340 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 341 } 342 Nfit ++; 343 344 // try fitting PSFs or extended sources depending on source->mode 345 // these functions subtract the resulting fitted source 346 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 347 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) { 348 source->type = PM_SOURCE_TYPE_EXTENDED; 349 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 350 Next ++; 351 continue; 352 } 353 } else { 354 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) { 355 source->type = PM_SOURCE_TYPE_STAR; 356 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 357 Npsf ++; 358 continue; 359 } 360 } 361 362 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); 363 Nfail ++; 364 365 // re-subtract the object, leave local sky 366 pmSourceCacheModel (source, maskVal); 367 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 368 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 369 } 370 371 // change the value of a scalar on the array (wrap this and put it in psArray.h) 372 *nfit = Nfit; 373 *npsf = Npsf; 374 *next = Next; 375 *nfail = Nfail; 376 377 return true; 378 }
Note:
See TracChangeset
for help on using the changeset viewer.
