Changeset 21359
- Timestamp:
- Feb 5, 2009, 3:12:59 PM (17 years ago)
- Location:
- trunk/psphot/src
- Files:
-
- 5 edited
-
psphotApResid.c (modified) (4 diffs)
-
psphotBlendFit.c (modified) (4 diffs)
-
psphotGuessModels.c (modified) (4 diffs)
-
psphotMagnitudes.c (modified) (5 diffs)
-
psphotSourceStats.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotApResid.c
r21183 r21359 1 1 # include "psphotInternal.h" 2 3 bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal); 2 4 3 5 # define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; } … … 29 31 nThreads = 0; 30 32 } 31 // nThreads = 0; // XXX until testing is complete, do not thread this function32 33 33 34 bool measureAptrend = psMetadataLookupBool (&status, recipe, "MEASURE.APTREND"); … … 94 95 for (int j = 0; j < cells->n; j++) { 95 96 96 // allocate a job -- if threads are not defined, this just runs the job 97 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS"); 98 99 psArrayAdd(job->args, 1, cells->data[j]); // sources 100 psArrayAdd(job->args, 1, psf); 101 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 102 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 103 104 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nskip 105 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 106 107 if (!psThreadJobAddPending(job)) { 97 if (nThreads) { 98 // allocate a job -- if threads are not defined, this just runs the job 99 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS"); 100 101 psArrayAdd(job->args, 1, cells->data[j]); // sources 102 psArrayAdd(job->args, 1, psf); 103 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 104 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 105 106 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nskip 107 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 108 109 if (!psThreadJobAddPending(job)) { 110 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 111 psFree (job); 112 return false; 113 } 114 psFree(job); 115 } else { 116 int nskip = 0; 117 int nfail = 0; 118 119 if (!psphotApResidMags_Unthreaded (&nskip, &nfail, sources, psf, photMode, maskVal)) { 120 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 121 return false; 122 } 123 Nskip += nskip; 124 Nfail += nfail; 125 } 126 127 } 128 129 if (nThreads) { 130 // wait for the threads to finish and manage results 131 if (!psThreadPoolWait (false)) { 108 132 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 109 psFree (job);110 133 return false; 111 134 } 112 psFree(job); 113 114 } 115 116 // wait for the threads to finish and manage results 117 if (!psThreadPoolWait (false)) { 118 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 119 return false; 120 } 121 122 // we have only supplied one type of job, so we can assume the types here 123 psThreadJob *job = NULL; 124 while ((job = psThreadJobGetDone()) != NULL) { 125 if (job->args->n < 1) { 126 fprintf (stderr, "error with job\n"); 127 } else { 128 psScalar *scalar = NULL; 129 scalar = job->args->data[4]; 130 Nskip += scalar->data.S32; 131 scalar = job->args->data[5]; 132 Nfail += scalar->data.S32; 135 136 // we have only supplied one type of job, so we can assume the types here 137 psThreadJob *job = NULL; 138 while ((job = psThreadJobGetDone()) != NULL) { 139 if (job->args->n < 1) { 140 fprintf (stderr, "error with job\n"); 141 } else { 142 psScalar *scalar = NULL; 143 scalar = job->args->data[4]; 144 Nskip += scalar->data.S32; 145 scalar = job->args->data[5]; 146 Nfail += scalar->data.S32; 147 } 148 psFree(job); 133 149 } 134 psFree(job);135 150 } 136 151 } … … 493 508 return true; 494 509 } 510 511 bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal) { 512 513 int Nskip = 0; 514 int Nfail = 0; 515 516 for (int i = 0; i < sources->n; i++) { 517 pmSource *source = (pmSource *) sources->data[i]; 518 519 if (source->type != PM_SOURCE_TYPE_STAR) SKIPSTAR ("NOT STAR"); 520 if (source->mode & PM_SOURCE_MODE_SATSTAR) SKIPSTAR ("SATSTAR"); 521 if (source->mode & PM_SOURCE_MODE_BLEND) SKIPSTAR ("BLEND"); 522 if (source->mode & PM_SOURCE_MODE_FAIL) SKIPSTAR ("FAIL STAR"); 523 if (source->mode & PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR"); 524 525 if (!pmSourceMagnitudes (source, psf, photMode, maskVal)) { 526 Nskip ++; 527 psTrace ("psphot", 3, "skip : bad source mag"); 528 continue; 529 } 530 531 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 532 Nfail ++; 533 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag); 534 continue; 535 } 536 } 537 538 // change the value of a scalar on the array (wrap this and put it in psArray.h) 539 *nskip = Nskip; 540 *nfail = Nfail; 541 542 return true; 543 } -
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 } -
trunk/psphot/src/psphotGuessModels.c
r21183 r21359 22 22 } 23 23 24 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal); 25 24 26 // construct an initial PSF model for each object 25 27 bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) { … … 38 40 nThreads = 0; 39 41 } 40 // nThreads = 0; // XXX until testing is complete, do not thread this function41 42 42 43 // bit-masks to test for good/bad pixels … … 66 67 for (int j = 0; j < cells->n; j++) { 67 68 68 // allocate a job -- if threads are not defined, this just runs the job 69 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL"); 70 psArrayAdd(job->args, 1, readout); 71 psArrayAdd(job->args, 1, cells->data[j]); // sources 72 psArrayAdd(job->args, 1, psf); 73 74 // XXX change these to use abstract mask type info 75 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 76 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 77 78 if (!psThreadJobAddPending(job)) { 69 if (nThreads) { 70 // allocate a job -- if threads are not defined, this just runs the job 71 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL"); 72 psArrayAdd(job->args, 1, readout); 73 psArrayAdd(job->args, 1, cells->data[j]); // sources 74 psArrayAdd(job->args, 1, psf); 75 76 // XXX change these to use abstract mask type info 77 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 78 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 79 80 if (!psThreadJobAddPending(job)) { 81 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 82 psFree (job); 83 return false; 84 } 85 psFree(job); 86 } else { 87 if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) { 88 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 89 return false; 90 } 91 } 92 } 93 94 if (nThreads) { 95 // wait for the threads to finish and manage results 96 // wait here for the threaded jobs to finish 97 // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy); 98 if (!psThreadPoolWait (false)) { 79 99 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 80 psFree (job);81 100 return false; 82 101 } 83 psFree(job); 84 } 85 86 // wait for the threads to finish and manage results 87 // wait here for the threaded jobs to finish 88 // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy); 89 if (!psThreadPoolWait (false)) { 90 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 91 return false; 92 } 93 94 // we have only supplied one type of job, so we can assume the types here 95 psThreadJob *job = NULL; 96 while ((job = psThreadJobGetDone()) != NULL) { 97 // we have no returned data from this operation 98 if (job->args->n < 1) { 99 fprintf (stderr, "error with job\n"); 100 } 101 psFree(job); 102 103 // we have only supplied one type of job, so we can assume the types here 104 psThreadJob *job = NULL; 105 while ((job = psThreadJobGetDone()) != NULL) { 106 // we have no returned data from this operation 107 if (job->args->n < 1) { 108 fprintf (stderr, "error with job\n"); 109 } 110 psFree(job); 111 } 102 112 } 103 113 } … … 211 221 } 212 222 223 // construct models only for sources in the specified region 224 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) { 225 226 int nSrc = 0; 227 228 for (int i = 0; i < sources->n; i++) { 229 pmSource *source = sources->data[i]; 230 231 // XXXX this is just for a test: use this to mark sources for which the model is measured 232 // check later that all are used. 233 source->mode |= PM_SOURCE_MODE_EXT_LIMIT; 234 235 // skip non-astronomical objects (very likely defects) 236 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 237 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 238 if (!source->peak) continue; 239 240 nSrc ++; 241 242 // XXX if a source is faint, it will not have moments measured. 243 // it must be modelled as a PSF. In this case, we need to use 244 // the peak centroid to get the coordinates and get the peak flux 245 // from the image? 246 pmModel *modelEXT; 247 if (!source->moments) { 248 modelEXT = wildGuess(source, psf); 249 } else { 250 // use the source moments, etc to guess basic model parameters 251 modelEXT = pmSourceModelGuess (source, psf->type); // ALLOC 252 if (!modelEXT) { 253 modelEXT = wildGuess(source, psf); 254 } 255 // these valuse are set in pmSourceModelGuess, should this rule be in there as well? 256 if (source->mode & PM_SOURCE_MODE_SATSTAR) { 257 modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->Mx; 258 modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->My; 259 } else { 260 modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf; 261 modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf; 262 } 263 } 264 265 // set PSF parameters for this model (apply 2D shape model) 266 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC 267 if (modelPSF == NULL) { 268 psError(PSPHOT_ERR_PSF, false, 269 "Failed to determine PSF model at r,c = (%d,%d); trying centre of image", 270 source->peak->y, source->peak->x); 271 // 272 // Try the centre of the image 273 // 274 modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols; 275 modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows; 276 modelPSF = pmModelFromPSF (modelEXT, psf); 277 if (modelPSF == NULL) { 278 psError(PSPHOT_ERR_PSF, false, 279 "Failed to determine PSF model at centre of image"); 280 psFree(modelEXT); 281 return false; 282 } 283 284 source->mode |= PM_SOURCE_MODE_BADPSF; 285 } 286 psFree (modelEXT); 287 288 // XXX need to define the guess flux? 289 // set the fit radius based on the object flux limit and the model 290 // this function affects the mask pixels 291 psphotCheckRadiusPSF (readout, source, modelPSF, markVal); 292 293 // set the source PSF model 294 source->modelPSF = modelPSF; 295 source->modelPSF->residuals = psf->residuals; 296 297 pmSourceCacheModel (source, maskVal); 298 299 } 300 301 return true; 302 } -
trunk/psphot/src/psphotMagnitudes.c
r21252 r21359 1 1 # include "psphotInternal.h" 2 3 bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal); 2 4 3 5 bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) { … … 17 19 nThreads = 0; 18 20 } 19 // nThreads = 0; // XXX until testing is complete, do not thread this function20 21 21 22 // if backModel or backStdev are missing, the values of sky and/or skyErr will be set to NAN … … 58 59 for (int j = 0; j < cells->n; j++) { 59 60 60 // allocate a job -- if threads are not defined, this just runs the job 61 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES"); 62 63 psArrayAdd(job->args, 1, cells->data[j]); // sources 64 psArrayAdd(job->args, 1, psf); 65 psArrayAdd(job->args, 1, binning); 66 psArrayAdd(job->args, 1, backModel); 67 psArrayAdd(job->args, 1, backStdev); 68 69 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 70 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_U8); // XXX change this to use abstract mask type info 71 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for nAp 72 73 if (!psThreadJobAddPending(job)) { 61 if (nThreads) { 62 // allocate a job -- if threads are not defined, this just runs the job 63 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES"); 64 65 psArrayAdd(job->args, 1, cells->data[j]); // sources 66 psArrayAdd(job->args, 1, psf); 67 psArrayAdd(job->args, 1, binning); 68 psArrayAdd(job->args, 1, backModel); 69 psArrayAdd(job->args, 1, backStdev); 70 71 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 72 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 73 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for nAp 74 75 if (!psThreadJobAddPending(job)) { 76 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 77 psFree (job); 78 return false; 79 } 80 psFree(job); 81 } else { 82 int nap = 0; 83 if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) { 84 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 85 return false; 86 } 87 Nap += nap; 88 } 89 } 90 91 if (nThreads) { 92 // wait for the threads to finish and manage results 93 if (!psThreadPoolWait (false)) { 74 94 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 75 psFree (job);76 95 return false; 77 96 } 78 psFree(job); 79 80 } 81 82 // wait for the threads to finish and manage results 83 if (!psThreadPoolWait (false)) { 84 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 85 return false; 86 } 87 88 // we have only supplied one type of job, so we can assume the types here 89 psThreadJob *job = NULL; 90 while ((job = psThreadJobGetDone()) != NULL) { 91 if (job->args->n < 1) { 92 fprintf (stderr, "error with job\n"); 93 } else { 94 psScalar *scalar = job->args->data[7]; 95 Nap += scalar->data.S32; 96 } 97 psFree(job); 97 98 // we have only supplied one type of job, so we can assume the types here 99 psThreadJob *job = NULL; 100 while ((job = psThreadJobGetDone()) != NULL) { 101 if (job->args->n < 1) { 102 fprintf (stderr, "error with job\n"); 103 } else { 104 psScalar *scalar = job->args->data[7]; 105 Nap += scalar->data.S32; 106 } 107 psFree(job); 108 } 98 109 } 99 110 } … … 116 127 pmReadout *backStdev = job->args->data[4]; 117 128 pmSourcePhotometryMode photMode = PS_SCALAR_VALUE(job->args->data[5],S32); 118 ps MaskType maskVal = PS_SCALAR_VALUE(job->args->data[6],U8);129 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA); 119 130 120 131 for (int i = 0; i < sources->n; i++) { … … 150 161 return true; 151 162 } 163 164 bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal) { 165 166 bool status; 167 int Nap = 0; 168 169 for (int i = 0; i < sources->n; i++) { 170 pmSource *source = (pmSource *) sources->data[i]; 171 status = pmSourceMagnitudes (source, psf, photMode, maskVal); 172 if (status && isfinite(source->apMag)) Nap ++; 173 174 if (backModel) { 175 psAssert (binning, "if backModel is defined, so should binning be"); 176 source->sky = psImageUnbinPixel(source->peak->x, source->peak->y, backModel->image, binning); 177 if (isnan(source->sky) && false) { 178 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.sky"); 179 } 180 } else { 181 source->sky = NAN; 182 } 183 184 if (backStdev) { 185 psAssert (binning, "if backStdev is defined, so should binning be"); 186 source->skyErr = psImageUnbinPixel(source->peak->x, source->peak->y, backStdev->image, binning); 187 if (isnan(source->skyErr) && false) { 188 psLogMsg ("psphot.magnitudes", PS_LOG_DETAIL, "error setting pmSource.skyErr"); 189 } 190 } else { 191 source->skyErr = NAN; 192 } 193 } 194 195 // change the value of a scalar on the array (wrap this and put it in psArray.h) 196 *nap = Nap; 197 198 return true; 199 } 200 201 # if (0) 202 bool psphotPSFWeights(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) { 203 204 bool status = false; 205 int Nap = 0; 206 207 psTimerStart ("psphot.mags"); 208 209 // select the appropriate recipe information 210 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 211 assert (recipe); 212 213 // determine the number of allowed threads 214 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 215 if (!status) { 216 nThreads = 0; 217 } 218 nThreads = 0; // XXX until testing is complete, do not thread this function 219 220 // bit-masks to test for good/bad pixels 221 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 222 assert (maskVal); 223 224 // bit-mask to mark pixels not used in analysis 225 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 226 assert (markVal); 227 228 // maskVal is used to test for rejected pixels, and must include markVal 229 maskVal |= markVal; 230 231 pmSourcePhotometryMode photMode = PM_SOURCE_PHOT_APCORR | PM_SOURCE_PHOT_WEIGHT; 232 if (!IGNORE_GROWTH) photMode |= PM_SOURCE_PHOT_GROWTH; 233 if (INTERPOLATE_AP) photMode |= PM_SOURCE_PHOT_INTERP; 234 235 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 236 int Cx = 1, Cy = 1; 237 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 238 239 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 240 241 for (int i = 0; i < cellGroups->n; i++) { 242 243 psArray *cells = cellGroups->data[i]; 244 245 for (int j = 0; j < cells->n; j++) { 246 247 // allocate a job -- if threads are not defined, this just runs the job 248 psThreadJob *job = psThreadJobAlloc ("PSPHOT_PSF_WEIGHTS"); 249 250 psArrayAdd(job->args, 1, cells->data[j]); // sources 251 psArrayAdd(job->args, 1, psf); 252 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 253 254 if (!psThreadJobAddPending(job)) { 255 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 256 psFree (job); 257 return false; 258 } 259 psFree(job); 260 261 } 262 263 // wait for the threads to finish and manage results 264 if (!psThreadPoolWait (false)) { 265 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 266 return false; 267 } 268 269 // we have only supplied one type of job, so we can assume the types here 270 psThreadJob *job = NULL; 271 while ((job = psThreadJobGetDone()) != NULL) { 272 if (job->args->n < 1) { 273 fprintf (stderr, "error with job\n"); 274 } 275 psFree(job); 276 } 277 } 278 279 psFree (cellGroups); 280 281 psLogMsg ("psphot", PS_LOG_DETAIL, "measure psf weights : %f sec for %ld objects\n", psTimerMark ("psphot.mags"), sources->n); 282 return true; 283 } 284 285 bool psphotPSFWeights_Threaded (psThreadJob *job) { 286 287 bool status; 288 bool isPSF; 289 290 psArray *sources = job->args->data[0]; 291 pmPSF *psf = job->args->data[1]; 292 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[2],PS_TYPE_IMAGE_MASK_DATA); 293 294 for (int i = 0; i < sources->n; i++) { 295 pmSource *source = (pmSource *) sources->data[i]; 296 297 // we must have a valid model 298 pmModel *model = pmSourceGetModel (&isPSF, source); 299 if (model == NULL) { 300 psTrace ("psphot", 3, "fail mag : no valid model"); 301 source->pixWeight = NAN; 302 continue; 303 } 304 305 status = pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal); 306 if (!status) { 307 psTrace ("psphot", 3, "fail to measure pixel weight"); 308 source->pixWeight = NAN; 309 continue; 310 } 311 312 } 313 314 return true; 315 } 316 317 # endif 318 -
trunk/psphot/src/psphotSourceStats.c
r21183 r21359 1 1 # include "psphotInternal.h" 2 3 bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe); 2 4 3 5 psArray *psphotSourceStats (pmConfig *config, pmReadout *readout, pmDetections *detections) { … … 78 80 for (int j = 0; j < cells->n; j++) { 79 81 80 // allocate a job -- if threads are not defined, this just runs the job 81 psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS"); 82 83 psArrayAdd(job->args, 1, cells->data[j]); // sources 84 psArrayAdd(job->args, 1, recipe); 85 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments 86 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 87 88 if (!psThreadJobAddPending(job)) { 82 if (nThreads) { 83 // allocate a job -- if threads are not defined, this just runs the job 84 psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS"); 85 86 psArrayAdd(job->args, 1, cells->data[j]); // sources 87 psArrayAdd(job->args, 1, recipe); 88 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments 89 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 90 91 if (!psThreadJobAddPending(job)) { 92 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 93 psFree (job); 94 return NULL; 95 } 96 psFree(job); 97 } else { 98 int nfail = 0; 99 int nmoments = 0; 100 if (!psphotSourceStats_Unthreaded (&nfail, &nmoments, cells->data[j], recipe)) { 101 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 102 return NULL; 103 } 104 Nfail += nfail; 105 Nmoments += nmoments; 106 } 107 } 108 109 if (nThreads) { 110 // wait for the threads to finish and manage results 111 if (!psThreadPoolWait (false)) { 89 112 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 90 psFree (job);91 113 return NULL; 92 114 } 93 psFree(job); 94 95 } 96 97 // wait for the threads to finish and manage results 98 if (!psThreadPoolWait (false)) { 99 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 100 return NULL; 101 } 102 103 // we have only supplied one type of job, so we can assume the types here 104 psThreadJob *job = NULL; 105 while ((job = psThreadJobGetDone()) != NULL) { 106 if (job->args->n < 1) { 107 fprintf (stderr, "error with job\n"); 108 } else { 109 psScalar *scalar = NULL; 110 scalar = job->args->data[2]; 111 Nmoments += scalar->data.S32; 112 scalar = job->args->data[3]; 113 Nfail += scalar->data.S32; 115 116 // we have only supplied one type of job, so we can assume the types here 117 psThreadJob *job = NULL; 118 while ((job = psThreadJobGetDone()) != NULL) { 119 if (job->args->n < 1) { 120 fprintf (stderr, "error with job\n"); 121 } else { 122 psScalar *scalar = NULL; 123 scalar = job->args->data[2]; 124 Nmoments += scalar->data.S32; 125 scalar = job->args->data[3]; 126 Nfail += scalar->data.S32; 127 } 128 psFree(job); 114 129 } 115 psFree(job);116 130 } 117 131 } … … 213 227 return true; 214 228 } 229 230 bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe) { 231 232 bool status = false; 233 float BIG_RADIUS; 234 235 float INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS"); 236 if (!status) return false; 237 float MIN_SN = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN"); 238 if (!status) return false; 239 float RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 240 if (!status) return false; 241 242 // bit-masks to test for good/bad pixels 243 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 244 assert (maskVal); 245 246 // bit-mask to mark pixels not used in analysis 247 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 248 assert (markVal); 249 250 // maskVal is used to test for rejected pixels, and must include markVal 251 maskVal |= markVal; 252 253 // threaded measurement of the sources moments 254 int Nfail = 0; 255 int Nmoments = 0; 256 for (int i = 0; i < sources->n; i++) { 257 pmSource *source = sources->data[i]; 258 259 // skip faint sources for moments measurement 260 if (source->peak->SN < MIN_SN) { 261 continue; 262 } 263 264 // measure a local sky value 265 // the local sky is now ignored; kept here for reference only 266 status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal); 267 if (!status) { 268 psErrorClear(); // XXX re-consider the errors raised here 269 Nfail ++; 270 continue; 271 } 272 273 // measure the local sky variance (needed if noise is not sqrt(signal)) 274 // XXX EAM : this should use ROBUST not SAMPLE median, but it is broken 275 status = pmSourceLocalSkyVariance (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal); 276 if (!status) { 277 Nfail ++; 278 psErrorClear(); 279 continue; 280 } 281 282 // measure basic source moments 283 status = pmSourceMoments (source, RADIUS); 284 if (status) { 285 Nmoments ++; 286 continue; 287 } 288 289 // if no valid pixels, or massive swing, likely saturated source, 290 // try a much larger box 291 BIG_RADIUS = PS_MIN (INNER, 3*RADIUS); 292 psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y); 293 status = pmSourceMoments (source, BIG_RADIUS); 294 if (status) { 295 Nmoments ++; 296 continue; 297 } 298 299 Nfail ++; 300 psErrorClear(); 301 continue; 302 } 303 304 // change the value of a scalar on the array (wrap this and put it in psArray.h) 305 *nmoments = Nmoments; 306 *nfail = Nfail; 307 308 return true; 309 }
Note:
See TracChangeset
for help on using the changeset viewer.
