Changeset 21166 for trunk/psphot/src/psphotBlendFit.c
- Timestamp:
- Jan 24, 2009, 10:54:29 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotBlendFit.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotBlendFit.c
r20453 r21166 2 2 3 3 // XXX I don't like this name 4 bool psphotBlendFit (pm Readout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf) {4 bool psphotBlendFit (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) { 5 5 6 6 int Nfit = 0; … … 12 12 psTimerStart ("psphot.fit.nonlinear"); 13 13 14 // select the appropriate recipe information 15 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 16 assert (recipe); 17 18 // determine the number of allowed threads 19 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 20 if (!status) { 21 nThreads = 0; 22 } 23 // nThreads = 0; // XXX until testing is complete, do not thread this function 24 25 psphotInitLimitsPSF (recipe, readout); 26 psphotInitLimitsEXT (recipe); 27 psphotInitRadiusPSF (recipe, psf->type); 28 29 // starts the timer, sets up the array of fitSets 30 psphotFitInit (nThreads); 31 32 // source analysis is done in S/N order (brightest first) 33 sources = psArraySort (sources, pmSourceSortBySN); 34 35 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 36 int Cx = 1, Cy = 1; 37 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 38 39 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 40 41 fprintf (stderr, "starting with %ld sources\n", sources->n); 42 43 for (int i = 0; i < cellGroups->n; i++) { 44 45 psArray *cells = cellGroups->data[i]; 46 47 for (int j = 0; j < cells->n; j++) { 48 49 // allocate a job -- if threads are not defined, this just runs the job 50 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 51 psArray *newSources = psArrayAllocEmpty(16); 52 53 psArrayAdd(job->args, 1, readout); 54 psArrayAdd(job->args, 1, recipe); 55 psArrayAdd(job->args, 1, cells->data[j]); // sources 56 psArrayAdd(job->args, 1, psf); 57 psArrayAdd(job->args, 1, newSources); // return for new sources 58 psFree (newSources); 59 60 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 61 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 62 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 63 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 64 65 if (!psThreadJobAddPending(job)) { 66 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 67 psFree (job); 68 return NULL; 69 } 70 psFree(job); 71 72 } 73 74 // wait for the threads to finish and manage results 75 if (!psThreadPoolWait (false)) { 76 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 77 return NULL; 78 } 79 80 // we have only supplied one type of job, so we can assume the types here 81 psThreadJob *job = NULL; 82 while ((job = psThreadJobGetDone()) != NULL) { 83 if (job->args->n < 1) { 84 fprintf (stderr, "error with job\n"); 85 } else { 86 psScalar *scalar = NULL; 87 scalar = job->args->data[5]; 88 Nfit += scalar->data.S32; 89 scalar = job->args->data[6]; 90 Npsf += scalar->data.S32; 91 scalar = job->args->data[7]; 92 Next += scalar->data.S32; 93 scalar = job->args->data[8]; 94 Nfail += scalar->data.S32; 95 96 // add these back onto sources 97 psArray *newSources = job->args->data[4]; 98 for (int j = 0; j < newSources->n; j++) { 99 psArrayAdd (sources, 16, newSources->data[j]); 100 } 101 } 102 psFree(job); 103 } 104 } 105 psFree (cellGroups); 106 107 if (psTraceGetLevel("psphot") >= 6) { 108 psphotSaveImage (NULL, readout->image, "image.v2.fits"); 109 } 110 111 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); 112 113 psphotVisualShowResidualImage (readout); 114 psphotVisualShowFlags (sources); 115 116 return true; 117 } 118 119 bool psphotBlendFit_Threaded (psThreadJob *job) { 120 121 bool status = false; 122 int Nfit = 0; 123 int Npsf = 0; 124 int Next = 0; 125 int Nfail = 0; 126 psScalar *scalar = NULL; 127 128 pmReadout *readout = job->args->data[0]; 129 psMetadata *recipe = job->args->data[1]; 130 psArray *sources = job->args->data[2]; 131 pmPSF *psf = job->args->data[3]; 132 psArray *newSources = job->args->data[4]; 133 14 134 // bit-masks to test for good/bad pixels 15 135 psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); … … 23 143 maskVal |= markVal; 24 144 25 // source analysis is done in S/N order (brightest first)26 sources = psArraySort (sources, pmSourceSortBySN);27 28 145 // S/N limit to perform full non-linear fits 29 146 float FIT_SN_LIM = psMetadataLookupF32 (&status, recipe, "FULL_FIT_SN_LIM"); 30 31 psphotInitLimitsPSF (recipe, readout);32 psphotInitLimitsEXT (recipe);33 psphotInitRadiusPSF (recipe, psf->type);34 35 psphotFitInit ();36 147 37 148 // option to limit analysis to a specific region … … 41 152 42 153 for (int i = 0; i < sources->n; i++) { 43 // if (i%100 == 0) psphotFitSummary ();44 45 154 pmSource *source = sources->data[i]; 46 155 … … 57 166 if (source->peak->SN < FIT_SN_LIM) continue; 58 167 59 // XXX this should use peak? 168 // exclude sources outside optional analysis region 60 169 if (source->peak->xf < AnalysisRegion.x0) continue; 61 170 if (source->peak->yf < AnalysisRegion.y0) continue; … … 66 175 if (source->modelPSF == NULL) continue; 67 176 68 // skip sources which are insignificant flux? 177 // skip sources which are insignificant flux? 178 // XXX this is somewhat ad-hoc 69 179 if (source->modelPSF->params->data.F32[1] < 0.1) { 70 180 psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n", … … 81 191 Nfit ++; 82 192 83 // XXX TEST 84 // if ((fabs(source->peak->x - 1202) < 2) && (fabs(source->peak->y - 1065) < 2)) { 85 // psTraceSetLevel ("psLib.math.psMinimizeLMChi2", 6); 86 // } 87 88 // try fitting PSFs, then try extended sources 89 // these functions subtract the resulting fitted source (XXX and update the modelFlux?) 90 // XXX re-consider conditions under which the source has EXT fit: 91 // I should try EXT if the source size measurement says it is large 193 // try fitting PSFs or extended sources depending on source->mode 194 // these functions subtract the resulting fitted source 92 195 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 93 if (psphotFitBlob (readout, source, sources, psf, maskVal, markVal)) {196 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) { 94 197 source->type = PM_SOURCE_TYPE_EXTENDED; 95 198 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); … … 115 218 } 116 219 117 if (psTraceGetLevel("psphot") >= 6) { 118 psphotSaveImage (NULL, readout->image, "image.v2.fits"); 119 } 120 121 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); 122 123 psphotVisualShowResidualImage (readout); 124 psphotVisualShowFlags (sources); 220 // change the value of a scalar on the array (wrap this and put it in psArray.h) 221 scalar = job->args->data[5]; 222 scalar->data.S32 = Nfit; 223 224 scalar = job->args->data[6]; 225 scalar->data.S32 = Npsf; 226 227 scalar = job->args->data[7]; 228 scalar->data.S32 = Next; 229 230 scalar = job->args->data[8]; 231 scalar->data.S32 = Nfail; 125 232 126 233 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
