Changeset 21490
- Timestamp:
- Feb 15, 2009, 9:56:23 AM (17 years ago)
- Location:
- branches/eam_branch_20090208/psphot/src
- Files:
-
- 1 deleted
- 17 edited
-
psphotAddNoise.c (modified) (1 diff)
-
psphotApResid.c (modified) (6 diffs)
-
psphotArguments.c (modified) (3 diffs)
-
psphotBlendFit.c (modified) (6 diffs)
-
psphotDeblendSatstars.c (modified) (1 diff)
-
psphotExtendedSourceAnalysis.c (modified) (6 diffs)
-
psphotExtendedSourceFits.c (modified) (5 diffs)
-
psphotExtendedSources.c (deleted)
-
psphotFitSourcesLinear.c (modified) (5 diffs)
-
psphotGuessModels.c (modified) (7 diffs)
-
psphotImageLoop.c (modified) (2 diffs)
-
psphotMagnitudes.c (modified) (5 diffs)
-
psphotParseCamera.c (modified) (2 diffs)
-
psphotReplaceUnfit.c (modified) (6 diffs)
-
psphotSourceFits.c (modified) (5 diffs)
-
psphotSourceSize.c (modified) (6 diffs)
-
psphotSourceStats.c (modified) (6 diffs)
-
psphotVisual.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20090208/psphot/src/psphotAddNoise.c
r21183 r21490 50 50 51 51 // skip sources which were not subtracted 52 if (!(source-> mode & PM_SOURCE_MODE_SUBTRACTED)) continue;52 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 53 53 54 54 // select appropriate model -
branches/eam_branch_20090208/psphot/src/psphotApResid.c
r21359 r21490 1 1 # include "psphotInternal.h" 2 3 bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal);4 2 5 3 # define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; } … … 95 93 for (int j = 0; j < cells->n; j++) { 96 94 97 if (nThreads) {98 // allocate a job -- if threads are not defined, this just runs the job99 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS"); 100 101 psArrayAdd(job->args, 1, cells->data[j]); // sources102 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 Nskip107 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 { 95 // allocate a job -- if threads are not defined, this just runs the job 96 psThreadJob *job = psThreadJobAlloc ("PSPHOT_APRESID_MAGS"); 97 98 psArrayAdd(job->args, 1, cells->data[j]); // sources 99 psArrayAdd(job->args, 1, psf); 100 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 101 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 102 103 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nskip 104 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 105 106 if (!psThreadJobAddPending(job)) { 107 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 108 psFree (job); 109 return false; 110 } 111 psFree(job); 112 113 # if (0) 116 114 int nskip = 0; 117 115 int nfail = 0; … … 123 121 Nskip += nskip; 124 122 Nfail += nfail; 125 } 123 # endif 126 124 127 125 } 128 126 129 if (nThreads) { 130 // wait for the threads to finish and manage results 131 if (!psThreadPoolWait (false)) { 132 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 133 return false; 127 // wait for the threads to finish and manage results 128 if (!psThreadPoolWait (false)) { 129 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 130 return false; 131 } 132 133 // we have only supplied one type of job, so we can assume the types here 134 psThreadJob *job = NULL; 135 while ((job = psThreadJobGetDone()) != NULL) { 136 if (job->args->n < 1) { 137 fprintf (stderr, "error with job\n"); 138 } else { 139 psScalar *scalar = NULL; 140 scalar = job->args->data[4]; 141 Nskip += scalar->data.S32; 142 scalar = job->args->data[5]; 143 Nfail += scalar->data.S32; 134 144 } 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); 149 } 145 psFree(job); 150 146 } 151 147 } … … 497 493 continue; 498 494 } 495 source->mode |= PM_SOURCE_MODE_AP_MAGS; 499 496 } 500 497 … … 509 506 } 510 507 508 # if (0) 511 509 bool psphotApResidMags_Unthreaded (int *nskip, int *nfail, psArray *sources, pmPSF *psf, pmSourcePhotometryMode photMode, psImageMaskType maskVal) { 512 510 … … 542 540 return true; 543 541 } 542 # endif -
branches/eam_branch_20090208/psphot/src/psphotArguments.c
r21166 r21490 33 33 if ((N = psArgumentGet(argc, argv, "-threads"))) { 34 34 psArgumentRemove(N, &argc, argv); 35 int nThreads = atoi(argv[N]);35 int nThreads = atoi(argv[N]); 36 36 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "NTHREADS", 0, "number of psphot threads", nThreads); 37 37 psArgumentRemove(N, &argc, argv); 38 38 39 // create the thread pool with number of desired threads, supplying our thread launcher function40 psThreadPoolInit (nThreads);39 // create the thread pool with number of desired threads, supplying our thread launcher function 40 psThreadPoolInit (nThreads); 41 41 } 42 42 psphotSetThreads(); … … 82 82 if ((N = psArgumentGet (argc, argv, "-visual"))) { 83 83 psArgumentRemove (N, &argc, argv); 84 psphotSetVisual (true);85 // pmSourceSetVisual (true);84 psphotSetVisual (true); 85 // pmSourceSetVisual (true); 86 86 } 87 87 … … 118 118 // 119 119 pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist"); 120 pmConfigFileSetsMD (config->arguments, &argc, argv, " WEIGHT", "-weight", "-weightlist");120 pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist"); 121 121 pmConfigFileSetsMD (config->arguments, &argc, argv, "PSPHOT.PSF", "-psf", "-psflist"); 122 122 pmConfigFileSetsMD (config->arguments, &argc, argv, "SRC", "-src", "-srclist"); -
branches/eam_branch_20090208/psphot/src/psphotBlendFit.c
r21366 r21490 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);4 2 5 3 // XXX I don't like this name … … 62 60 for (int j = 0; j < cells->n; j++) { 63 61 64 if (nThreads) { 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)) { 82 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 83 psFree (job); 84 return NULL; 85 } 86 psFree(job); 87 } else { 62 // allocate a job -- if threads are not defined, this just runs the job 63 psThreadJob *job = psThreadJobAlloc ("PSPHOT_BLEND_FIT"); 64 psArray *newSources = psArrayAllocEmpty(16); 65 66 psArrayAdd(job->args, 1, readout); 67 psArrayAdd(job->args, 1, recipe); 68 psArrayAdd(job->args, 1, cells->data[j]); // sources 69 psArrayAdd(job->args, 1, psf); 70 psArrayAdd(job->args, 1, newSources); // return for new sources 71 psFree (newSources); 72 73 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfit 74 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Npsf 75 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Next 76 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nfail 77 78 if (!psThreadJobAddPending(job)) { 79 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 80 psFree (job); 81 return NULL; 82 } 83 psFree(job); 84 85 # if (0) 86 { 88 87 int nfit = 0; 89 88 int npsf = 0; … … 107 106 psFree (newSources); 108 107 } 109 } 110 111 if (nThreads) { 112 // wait for the threads to finish and manage results 113 if (!psThreadPoolWait (false)) { 114 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 115 return NULL; 116 } 117 118 // we have only supplied one type of job, so we can assume the types here 119 psThreadJob *job = NULL; 120 while ((job = psThreadJobGetDone()) != NULL) { 121 if (job->args->n < 1) { 122 fprintf (stderr, "error with job\n"); 123 } else { 124 psScalar *scalar = NULL; 125 scalar = job->args->data[5]; 126 Nfit += scalar->data.S32; 127 scalar = job->args->data[6]; 128 Npsf += scalar->data.S32; 129 scalar = job->args->data[7]; 130 Next += scalar->data.S32; 131 scalar = job->args->data[8]; 132 Nfail += scalar->data.S32; 133 134 // add these back onto sources 135 psArray *newSources = job->args->data[4]; 136 for (int j = 0; j < newSources->n; j++) { 137 psArrayAdd (sources, 16, newSources->data[j]); 138 } 139 } 140 psFree(job); 141 } 142 } 108 # endif 109 } 110 111 // wait for the threads to finish and manage results 112 if (!psThreadPoolWait (false)) { 113 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 114 return NULL; 115 } 116 117 // we have only supplied one type of job, so we can assume the types here 118 psThreadJob *job = NULL; 119 while ((job = psThreadJobGetDone()) != NULL) { 120 if (job->args->n < 1) { 121 fprintf (stderr, "error with job\n"); 122 } else { 123 psScalar *scalar = NULL; 124 scalar = job->args->data[5]; 125 Nfit += scalar->data.S32; 126 scalar = job->args->data[6]; 127 Npsf += scalar->data.S32; 128 scalar = job->args->data[7]; 129 Next += scalar->data.S32; 130 scalar = job->args->data[8]; 131 Nfail += scalar->data.S32; 132 133 // add these back onto sources 134 psArray *newSources = job->args->data[4]; 135 for (int j = 0; j < newSources->n; j++) { 136 psArrayAdd (sources, 16, newSources->data[j]); 137 } 138 } 139 psFree(job); 140 } 143 141 } 144 142 psFree (cellGroups); … … 225 223 226 224 // replace object in image 227 if (source->mode & PM_SOURCE_MODE_SUBTRACTED) { 225 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 226 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 227 } 228 Nfit ++; 229 230 // try fitting PSFs or extended sources depending on source->mode 231 // these functions subtract the resulting fitted source 232 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 233 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) { 234 source->type = PM_SOURCE_TYPE_EXTENDED; 235 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 236 Next ++; 237 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 238 continue; 239 } 240 } else { 241 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) { 242 source->type = PM_SOURCE_TYPE_STAR; 243 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 244 Npsf ++; 245 source->mode |= PM_SOURCE_MODE_NONLINEAR_FIT; 246 continue; 247 } 248 } 249 250 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); 251 Nfail ++; 252 253 // re-subtract the object, leave local sky 254 pmSourceCacheModel (source, maskVal); 255 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 256 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 257 } 258 259 // change the value of a scalar on the array (wrap this and put it in psArray.h) 260 scalar = job->args->data[5]; 261 scalar->data.S32 = Nfit; 262 263 scalar = job->args->data[6]; 264 scalar->data.S32 = Npsf; 265 266 scalar = job->args->data[7]; 267 scalar->data.S32 = Next; 268 269 scalar = job->args->data[8]; 270 scalar->data.S32 = Nfail; 271 272 return true; 273 } 274 275 # if (0) 276 bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources) { 277 278 bool status = false; 279 int Nfit = 0; 280 int Npsf = 0; 281 int Next = 0; 282 int Nfail = 0; 283 284 // bit-masks to test for good/bad pixels 285 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 286 assert (maskVal); 287 288 // bit-mask to mark pixels not used in analysis 289 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 290 assert (markVal); 291 292 // maskVal is used to test for rejected pixels, and must include markVal 293 maskVal |= markVal; 294 295 // S/N limit to perform full non-linear fits 296 float FIT_SN_LIM = psMetadataLookupF32 (&status, recipe, "FULL_FIT_SN_LIM"); 297 298 // option to limit analysis to a specific region 299 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 300 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 301 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 302 303 for (int i = 0; i < sources->n; i++) { 304 pmSource *source = sources->data[i]; 305 306 // skip non-astronomical objects (very likely defects) 307 if (source->mode & PM_SOURCE_MODE_BLEND) continue; 308 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 309 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 310 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 311 312 // skip DBL second sources (ie, added by psphotFitBlob) 313 if (source->mode & PM_SOURCE_MODE_PAIR) continue; 314 315 // limit selection to some SN limit 316 if (source->peak->SN < FIT_SN_LIM) continue; 317 318 // exclude sources outside optional analysis region 319 if (source->peak->xf < AnalysisRegion.x0) continue; 320 if (source->peak->yf < AnalysisRegion.y0) continue; 321 if (source->peak->xf > AnalysisRegion.x1) continue; 322 if (source->peak->yf > AnalysisRegion.y1) continue; 323 324 // if model is NULL, we don't have a starting guess 325 if (source->modelPSF == NULL) continue; 326 327 // skip sources which are insignificant flux? 328 // XXX this is somewhat ad-hoc 329 if (source->modelPSF->params->data.F32[1] < 0.1) { 330 psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n", 331 source->modelPSF->params->data.F32[1], 332 source->modelPSF->params->data.F32[2], 333 source->modelPSF->params->data.F32[3]); 334 continue; 335 } 336 337 // replace object in image 338 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 228 339 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 229 340 } … … 254 365 pmSourceCacheModel (source, maskVal); 255 366 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 256 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 257 } 258 259 // change the value of a scalar on the array (wrap this and put it in psArray.h) 260 scalar = job->args->data[5]; 261 scalar->data.S32 = Nfit; 262 263 scalar = job->args->data[6]; 264 scalar->data.S32 = Npsf; 265 266 scalar = job->args->data[7]; 267 scalar->data.S32 = Next; 268 269 scalar = job->args->data[8]; 270 scalar->data.S32 = Nfail; 271 272 return true; 273 } 274 275 bool psphotBlendFit_Unthreaded (int *nfit, int *npsf, int *next, int *nfail, pmReadout *readout, psMetadata *recipe, psArray *sources, pmPSF *psf, psArray *newSources) { 276 277 bool status = false; 278 int Nfit = 0; 279 int Npsf = 0; 280 int Next = 0; 281 int Nfail = 0; 282 283 // bit-masks to test for good/bad pixels 284 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 285 assert (maskVal); 286 287 // bit-mask to mark pixels not used in analysis 288 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 289 assert (markVal); 290 291 // maskVal is used to test for rejected pixels, and must include markVal 292 maskVal |= markVal; 293 294 // S/N limit to perform full non-linear fits 295 float FIT_SN_LIM = psMetadataLookupF32 (&status, recipe, "FULL_FIT_SN_LIM"); 296 297 // option to limit analysis to a specific region 298 char *region = psMetadataLookupStr (&status, recipe, "ANALYSIS_REGION"); 299 psRegion AnalysisRegion = psRegionForImage (readout->image, psRegionFromString (region)); 300 if (psRegionIsNaN (AnalysisRegion)) psAbort("analysis region mis-defined"); 301 302 for (int i = 0; i < sources->n; i++) { 303 pmSource *source = sources->data[i]; 304 305 // skip non-astronomical objects (very likely defects) 306 if (source->mode & PM_SOURCE_MODE_BLEND) continue; 307 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 308 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 309 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 310 311 // skip DBL second sources (ie, added by psphotFitBlob) 312 if (source->mode & PM_SOURCE_MODE_PAIR) continue; 313 314 // limit selection to some SN limit 315 if (source->peak->SN < FIT_SN_LIM) continue; 316 317 // exclude sources outside optional analysis region 318 if (source->peak->xf < AnalysisRegion.x0) continue; 319 if (source->peak->yf < AnalysisRegion.y0) continue; 320 if (source->peak->xf > AnalysisRegion.x1) continue; 321 if (source->peak->yf > AnalysisRegion.y1) continue; 322 323 // if model is NULL, we don't have a starting guess 324 if (source->modelPSF == NULL) continue; 325 326 // skip sources which are insignificant flux? 327 // XXX this is somewhat ad-hoc 328 if (source->modelPSF->params->data.F32[1] < 0.1) { 329 psTrace ("psphot", 5, "skipping near-zero source: %f, %f : %f\n", 330 source->modelPSF->params->data.F32[1], 331 source->modelPSF->params->data.F32[2], 332 source->modelPSF->params->data.F32[3]); 333 continue; 334 } 335 336 // replace object in image 337 if (source->mode & PM_SOURCE_MODE_SUBTRACTED) { 338 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 339 } 340 Nfit ++; 341 342 // try fitting PSFs or extended sources depending on source->mode 343 // these functions subtract the resulting fitted source 344 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 345 if (psphotFitBlob (readout, source, newSources, psf, maskVal, markVal)) { 346 source->type = PM_SOURCE_TYPE_EXTENDED; 347 psTrace ("psphot", 5, "source at %7.1f, %7.1f is ext", source->peak->xf, source->peak->yf); 348 Next ++; 349 continue; 350 } 351 } else { 352 if (psphotFitBlend (readout, source, psf, maskVal, markVal)) { 353 source->type = PM_SOURCE_TYPE_STAR; 354 psTrace ("psphot", 5, "source at %7.1f, %7.1f is psf", source->peak->xf, source->peak->yf); 355 Npsf ++; 356 continue; 357 } 358 } 359 360 psTrace ("psphot", 5, "source at %7.1f, %7.1f failed", source->peak->xf, source->peak->yf); 361 Nfail ++; 362 363 // re-subtract the object, leave local sky 364 pmSourceCacheModel (source, maskVal); 365 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 366 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 367 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 367 368 } 368 369 … … 375 376 return true; 376 377 } 378 # endif -
branches/eam_branch_20090208/psphot/src/psphotDeblendSatstars.c
r21408 r21490 111 111 112 112 // any peaks within this contour should be dropped (mark as blend, drop after loop is done) 113 // also drop any peaks which are too close to this pea l113 // also drop any peaks which are too close to this peak 114 114 psVector *xv = contour->data[0]; 115 115 psVector *yv = contour->data[1]; -
branches/eam_branch_20090208/psphot/src/psphotExtendedSourceAnalysis.c
r21183 r21490 61 61 62 62 // replace object in image 63 if (source-> mode & PM_SOURCE_MODE_SUBTRACTED) {63 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 64 64 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 65 65 } … … 73 73 psTrace ("psphot", 5, "failed to extract radial profile for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 74 74 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 75 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;75 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 76 76 continue; 77 77 } 78 source->mode |= PM_SOURCE_MODE_RADIAL_FLUX; 78 79 } 79 80 … … 85 86 psTrace ("psphot", 5, "measured isophotal mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 86 87 Nisophot ++; 88 source->mode |= PM_SOURCE_MODE_EXTENDED_STATS; 87 89 } 88 90 } … … 95 97 psTrace ("psphot", 5, "measured petrosian flux & radius for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 96 98 Npetro ++; 99 source->mode |= PM_SOURCE_MODE_EXTENDED_STATS; 97 100 } 98 101 } … … 105 108 psTrace ("psphot", 5, "measure kron mags for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 106 109 Nkron ++; 110 source->mode |= PM_SOURCE_MODE_EXTENDED_STATS; 107 111 } 108 112 } … … 116 120 psTrace ("psphot", 5, "measured annuli for source at %7.1f, %7.1f", source->moments->Mx, source->moments->My); 117 121 Nannuli ++; 122 source->mode |= PM_SOURCE_MODE_EXTENDED_STATS; 118 123 } 119 124 120 125 // re-subtract the object, leave local sky 121 126 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 122 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;127 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 123 128 } 124 129 -
branches/eam_branch_20090208/psphot/src/psphotExtendedSourceFits.c
r21183 r21490 110 110 111 111 // replace object in image 112 if (source-> mode & PM_SOURCE_MODE_SUBTRACTED) {112 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) { 113 113 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 114 114 } … … 170 170 if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) { 171 171 NconvolvePass ++; 172 source->mode |= PM_SOURCE_MODE_EXTENDED_FIT; 172 173 } 173 174 } else { … … 184 185 if (!(modelFit->flags & (PM_MODEL_STATUS_BADARGS | PM_MODEL_STATUS_NONCONVERGE | PM_MODEL_STATUS_OFFIMAGE))) { 185 186 NplainPass ++; 187 source->mode |= PM_SOURCE_MODE_EXTENDED_FIT; 186 188 } 187 189 } … … 224 226 225 227 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 226 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;228 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 227 229 228 230 psFree (modelFluxes); … … 251 253 // subtract the best fit from the object, leave local sky 252 254 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 253 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;255 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 254 256 255 257 // the initial model flux is no longer needed -
branches/eam_branch_20090208/psphot/src/psphotFitSourcesLinear.c
r21452 r21490 63 63 pmSource *source = sources->data[i]; 64 64 65 // turn this bit off and turn it on again if we pass this test 66 source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT; 67 65 68 // skip non-astronomical objects (very likely defects) 66 69 if (source->type == PM_SOURCE_TYPE_DEFECT) continue; 67 70 if (source->type == PM_SOURCE_TYPE_SATURATED) continue; 68 71 69 // if (source->type == PM_SOURCE_TYPE_STAR && 72 // do not include CRs in the full ensemble fit 70 73 if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue; 71 74 72 75 if (final) { 73 if (source-> mode & PM_SOURCE_MODE_SUBTRACTED) continue;76 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue; 74 77 } else { 75 if (source->mode & PM_SOURCE_MODE_BLEND) continue;78 if (source->mode & PM_SOURCE_MODE_BLEND) continue; 76 79 } 77 80 … … 91 94 if (y > AnalysisRegion.y1) continue; 92 95 96 source->mode |= PM_SOURCE_MODE_LINEAR_FIT; 93 97 psArrayAdd (fitSources, 100, source); 94 98 } … … 185 189 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "solve matrix: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem); 186 190 191 // XXXX **** philosophical question: 192 // we measure bright objects in three passes: 1) linear fit; 2) non-linear fit; 3) linear fit: 193 // should retain the chisq and errors from the intermediate non-linear fit? 194 // the non-linear fit provides better values for the position errors, and for 195 // extended sources, the shape errors 196 187 197 // adjust I0 for fitSources and subtract 188 198 for (int i = 0; i < fitSources->n; i++) { … … 194 204 psAbort("linear fitted source is nan"); 195 205 } 206 196 207 model->params->data.F32[PM_PAR_I0] = norm->data.F32[i]; 197 208 model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i]; … … 200 211 // subtract object 201 212 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 202 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;213 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 203 214 } 204 215 psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "sub models: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem); -
branches/eam_branch_20090208/psphot/src/psphotGuessModels.c
r21381 r21490 22 22 } 23 23 24 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);25 26 24 // construct an initial PSF model for each object 27 25 bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) { … … 67 65 for (int j = 0; j < cells->n; j++) { 68 66 69 if (nThreads) {70 // allocate a job -- if threads are not defined, this just runs the job71 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");72 psArrayAdd(job->args, 1, readout);73 psArrayAdd(job->args, 1, cells->data[j]); // sources74 psArrayAdd(job->args, 1, psf); 75 76 // XXX change these to use abstract mask type info77 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 { 67 // allocate a job -- if threads are not defined, this just runs the job 68 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL"); 69 psArrayAdd(job->args, 1, readout); 70 psArrayAdd(job->args, 1, cells->data[j]); // sources 71 psArrayAdd(job->args, 1, psf); 72 73 // XXX change these to use abstract mask type info 74 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 75 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 76 77 if (!psThreadJobAddPending(job)) { 78 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 79 psFree (job); 80 return false; 81 } 82 psFree(job); 83 84 # if (0) 87 85 if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) { 88 86 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 89 87 return false; 90 88 } 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)) { 99 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 100 return false; 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 // 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 } 89 # endif 90 } 91 92 // wait for the threads to finish and manage results 93 // wait here for the threaded jobs to finish 94 // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy); 95 if (!psThreadPoolWait (false)) { 96 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 97 return false; 98 } 99 100 // we have only supplied one type of job, so we can assume the types here 101 psThreadJob *job = NULL; 102 while ((job = psThreadJobGetDone()) != NULL) { 103 // we have no returned data from this operation 104 if (job->args->n < 1) { 105 fprintf (stderr, "error with job\n"); 106 } 107 psFree(job); 112 108 } 113 109 } … … 116 112 int nMiss = 0; 117 113 for (int i = 0; i < sources->n; i++) { 118 119 114 pmSource *source = sources->data[i]; 120 if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) { 121 source->mode &= ~PM_SOURCE_MODE_EXT_LIMIT; 115 if (source->tmpFlags & PM_SOURCE_TMPF_MODEL_GUESS) { 122 116 continue; 123 117 } 124 125 118 nMiss ++; 126 119 } 127 ps LogMsg ("psphot.models", 4, "failedto build models for %d objects\n", nMiss);120 psAssert (nMiss == 0, "failed to attempt to build models for %d objects\n", nMiss); 128 121 129 122 psFree (cellGroups); … … 148 141 pmSource *source = sources->data[i]; 149 142 150 // XXXX this is just for a test: use this to mark sources for which the model is measured151 // check later thatall are used.152 source-> mode |= PM_SOURCE_MODE_EXT_LIMIT;143 // this is used to mark sources for which the model is measured. We check later that 144 // all are used. 145 source->tmpFlags |= PM_SOURCE_TMPF_MODEL_GUESS; 153 146 154 147 // skip non-astronomical objects (very likely defects) … … 185 178 pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC X5 186 179 if (modelPSF == NULL) { 187 psError(PSPHOT_ERR_PSF, false, 188 "Failed to determine PSF model at r,c = (%d,%d); trying centre of image", 180 psWarning ("Failed to determine PSF model at r,c = (%d,%d); trying centre of image", 189 181 source->peak->y, source->peak->x); 190 // 191 // Try the centre of the image 192 // 182 183 // Try the center of the image 193 184 modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols; 194 185 modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows; 195 186 modelPSF = pmModelFromPSF (modelEXT, psf); 196 187 if (modelPSF == NULL) { 197 psError(PSPHOT_ERR_PSF, false, 198 "Failed to determine PSF model at centre of image"); 188 psError(PSPHOT_ERR_PSF, false, "Failed to determine PSF model at center of image"); 199 189 psFree(modelEXT); 200 190 return false; 201 191 } 202 203 192 source->mode |= PM_SOURCE_MODE_BADPSF; 204 193 } … … 221 210 } 222 211 212 # if (0) 223 213 // construct models only for sources in the specified region 224 214 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) { … … 301 291 return true; 302 292 } 293 # endif -
branches/eam_branch_20090208/psphot/src/psphotImageLoop.c
r20769 r21490 16 16 pmFPAfile *load = psMetadataLookupPtr (&status, config->files, "PSPHOT.LOAD"); 17 17 if (!status) { 18 psError(PSPHOT_ERR_PROG, false, "Can't find input data!");19 return false;18 psError(PSPHOT_ERR_PROG, false, "Can't find input data!"); 19 return false; 20 20 } 21 21 pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT"); 22 22 if (!status) { 23 psError(PSPHOT_ERR_PROG, false, "Can't find input data!");24 return false;23 psError(PSPHOT_ERR_PROG, false, "Can't find input data!"); 24 return false; 25 25 } 26 26 27 27 pmFPAview *view = pmFPAviewAlloc (0); 28 28 29 29 // files associated with the science image 30 30 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for fpa in psphot."); 31 31 32 // for psphot, we force data to be read at the chip level 32 // for psphot, we force data to be read at the chip level 33 33 while ((chip = pmFPAviewNextChip (view, load->fpa, 1)) != NULL) { 34 34 psLogMsg ("psphot", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 35 35 if (! chip->process || ! chip->file_exists) { continue; } 36 36 37 // load just the input image data (image, mask, weight)38 pmFPAfileActivate (config->files, false, NULL);39 pmFPAfileActivate (config->files, true, "PSPHOT.LOAD");40 pmFPAfileActivate (config->files, true, "PSPHOT.MASK");41 pmFPAfileActivate (config->files, true, "PSPHOT.WEIGHT");42 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot.");37 // load just the input image data (image, mask, weight) 38 pmFPAfileActivate (config->files, false, NULL); 39 pmFPAfileActivate (config->files, true, "PSPHOT.LOAD"); 40 pmFPAfileActivate (config->files, true, "PSPHOT.MASK"); 41 pmFPAfileActivate (config->files, true, "PSPHOT.VARIANCE"); 42 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot."); 43 43 44 // mosaic the cells of a chip into a single contiguous (trimmed) chip44 // mosaic the cells of a chip into a single contiguous (trimmed) chip 45 45 if (!psphotMosaicChip(config, view, "PSPHOT.INPUT", "PSPHOT.LOAD")) ESCAPE ("Unable to mosaic chip."); 46 46 47 // try to load other supporting data (PSF, SRC, etc).48 // do not re-load the following three files49 pmFPAfileActivate (config->files, true, NULL);50 pmFPAfileActivate (config->files, false, "PSPHOT.LOAD");51 pmFPAfileActivate (config->files, false, "PSPHOT.MASK");52 pmFPAfileActivate (config->files, false, "PSPHOT.WEIGHT");53 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot.");47 // try to load other supporting data (PSF, SRC, etc). 48 // do not re-load the following three files 49 pmFPAfileActivate (config->files, true, NULL); 50 pmFPAfileActivate (config->files, false, "PSPHOT.LOAD"); 51 pmFPAfileActivate (config->files, false, "PSPHOT.MASK"); 52 pmFPAfileActivate (config->files, false, "PSPHOT.VARIANCE"); 53 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) ESCAPE ("failed input for Chip in psphot."); 54 54 55 // re-activate files so they will be closed and freed below56 pmFPAfileActivate (config->files, true, NULL);55 // re-activate files so they will be closed and freed below 56 pmFPAfileActivate (config->files, true, NULL); 57 57 58 // there is now only a single chip (multiple readouts?). loop over it and process59 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {58 // there is now only a single chip (multiple readouts?). loop over it and process 59 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 60 60 psLogMsg ("psphot", 5, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 61 61 62 // process each of the readouts63 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {64 psLogMsg ("psphot", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);65 if (! readout->data_exists) { continue; }62 // process each of the readouts 63 while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) { 64 psLogMsg ("psphot", 6, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process); 65 if (! readout->data_exists) { continue; } 66 66 67 // run the actual photometry analysis on this chip/cell/readout68 if (!psphotReadout (config, view)) {69 psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);70 psFree (view);71 return false;72 }73 }67 // run the actual photometry analysis on this chip/cell/readout 68 if (!psphotReadout (config, view)) { 69 psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout); 70 psFree (view); 71 return false; 72 } 73 } 74 74 75 status = true;76 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL");77 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV");78 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND");79 if (!status) {80 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files");81 psFree (view);82 return false;83 }84 }75 status = true; 76 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL"); 77 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKMDL.STDEV"); 78 status &= pmFPAfileDropInternal (config->files, "PSPHOT.BACKGND"); 79 if (!status) { 80 psError(PSPHOT_ERR_PROG, false, "trouble dropping internal files"); 81 psFree (view); 82 return false; 83 } 84 } 85 85 86 // save output which is saved at the chip level87 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot.");86 // save output which is saved at the chip level 87 if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) ESCAPE ("failed output for Chip in psphot."); 88 88 } 89 89 // save output which is saved at the fpa level … … 108 108 109 109 // PSPHOT.MASK 110 // PSPHOT. WEIGHT111 // 110 // PSPHOT.VARIANCE 111 // -
branches/eam_branch_20090208/psphot/src/psphotMagnitudes.c
r21453 r21490 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);4 2 5 3 bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) { … … 59 57 for (int j = 0; j < cells->n; j++) { 60 58 61 if (nThreads) {62 // allocate a job -- if threads are not defined, this just runs the job63 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES"); 64 65 psArrayAdd(job->args, 1, cells->data[j]); // sources66 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 { 59 // allocate a job -- if threads are not defined, this just runs the job 60 psThreadJob *job = psThreadJobAlloc ("PSPHOT_MAGNITUDES"); 61 62 psArrayAdd(job->args, 1, cells->data[j]); // sources 63 psArrayAdd(job->args, 1, psf); 64 psArrayAdd(job->args, 1, binning); 65 psArrayAdd(job->args, 1, backModel); 66 psArrayAdd(job->args, 1, backStdev); 67 68 PS_ARRAY_ADD_SCALAR(job->args, photMode, PS_TYPE_S32); 69 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 70 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for nAp 71 72 if (!psThreadJobAddPending(job)) { 73 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 74 psFree (job); 75 return false; 76 } 77 psFree(job); 78 79 # if (0) 82 80 int nap = 0; 83 81 if (!psphotMagnitudes_Unthreaded (&nap, cells->data[j], psf, binning, backModel, backStdev, photMode, maskVal)) { … … 86 84 } 87 85 Nap += nap; 88 } 89 } 90 91 if (nThreads) { 92 // wait for the threads to finish and manage results 93 if (!psThreadPoolWait (false)) { 94 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 95 return false; 96 } 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 } 86 # endif 87 } 88 89 // wait for the threads to finish and manage results 90 if (!psThreadPoolWait (false)) { 91 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 92 return false; 93 } 94 95 // we have only supplied one type of job, so we can assume the types here 96 psThreadJob *job = NULL; 97 while ((job = psThreadJobGetDone()) != NULL) { 98 if (job->args->n < 1) { 99 fprintf (stderr, "error with job\n"); 100 } else { 101 psScalar *scalar = job->args->data[7]; 102 Nap += scalar->data.S32; 103 } 104 psFree(job); 109 105 } 110 106 } … … 162 158 } 163 159 160 # if (0) 164 161 bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal) { 165 162 … … 198 195 return true; 199 196 } 197 # endif 200 198 201 199 bool psphotPSFWeights(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources) { -
branches/eam_branch_20090208/psphot/src/psphotParseCamera.c
r19141 r21490 15 15 load->dataLevel = PM_FPA_LEVEL_CHIP; // force load at the CHIP level 16 16 17 // if MASK or WEIGHTwas supplied on command line, bind files to 'load'17 // if MASK or VARIANCE was supplied on command line, bind files to 'load' 18 18 // the mask and weight will be mosaicked with the image 19 19 pmFPAfileBindFromArgs (&status, load, config, "PSPHOT.MASK", "MASK"); … … 27 27 } 28 28 29 pmFPAfileBindFromArgs (&status, load, config, "PSPHOT. WEIGHT", "WEIGHT");29 pmFPAfileBindFromArgs (&status, load, config, "PSPHOT.VARIANCE", "VARIANCE"); 30 30 if (!status) { 31 31 psError (PS_ERR_UNKNOWN, false, "failed to load find definition"); -
branches/eam_branch_20090208/psphot/src/psphotReplaceUnfit.c
r21183 r21490 17 17 replace: 18 18 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 19 source-> mode &= ~PM_SOURCE_MODE_SUBTRACTED;19 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 20 20 } 21 21 psLogMsg ("psphot.replace", 3, "replace unfitted models: %f sec (%ld objects)\n", psTimerMark ("psphot.replace"), sources->n); … … 38 38 39 39 // replace other sources? 40 if (!(source-> mode & PM_SOURCE_MODE_SUBTRACTED)) continue;40 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue; 41 41 42 42 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 43 source-> mode &= ~PM_SOURCE_MODE_SUBTRACTED;43 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 44 44 } 45 45 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); … … 62 62 63 63 // replace other sources? 64 if (source-> mode & PM_SOURCE_MODE_SUBTRACTED) continue;64 if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue; 65 65 66 66 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 67 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;67 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 68 68 } 69 69 psLogMsg ("psphot.replace", PS_LOG_INFO, "replaced models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot.replace")); … … 75 75 76 76 // what is current state? (true : add; false : sub) 77 bool state = !(source-> mode & PM_SOURCE_MODE_SUBTRACTED);77 bool state = !(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 78 78 if (state && useState) return true; 79 79 … … 86 86 87 87 // what is current state? (true : sub; false : add) 88 bool state = (source-> mode & PM_SOURCE_MODE_SUBTRACTED);88 bool state = (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 89 89 if (state && useState) return true; 90 90 … … 97 97 98 98 // what is desired state? (true : add; false : sub) 99 bool newState = !(source-> mode & PM_SOURCE_MODE_SUBTRACTED);99 bool newState = !(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 100 100 if (curState == newState) return true; 101 101 -
branches/eam_branch_20090208/psphot/src/psphotSourceFits.c
r21183 r21490 120 120 pmSourceCacheModel (blend, maskVal); 121 121 pmSourceSub (blend, PM_MODEL_OP_FULL, maskVal); 122 blend->mode |= PM_SOURCE_MODE_SUBTRACTED; 122 blend->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 123 blend->mode |= PM_SOURCE_MODE_BLEND_FIT; 123 124 } 124 125 NfitBlend += modelSet->n; … … 143 144 pmSourceCacheModel (source, maskVal); 144 145 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 145 source->mode |= PM_SOURCE_MODE_SUBTRACTED; 146 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 147 source->mode |= PM_SOURCE_MODE_BLEND_FIT; 146 148 return true; 147 149 } … … 184 186 pmSourceCacheModel (source, maskVal); 185 187 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 186 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;188 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 187 189 return true; 188 190 } … … 285 287 pmSourceCacheModel (source, maskVal); 286 288 pmSourceSub (source, PM_MODEL_OP_FULL, maskVal); 287 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;289 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 288 290 psTrace ("psphot", 5, "blob as EXT: %f %f\n", EXT->params->data.F32[PM_PAR_XPOS], EXT->params->data.F32[PM_PAR_YPOS]); 289 291 return true; … … 296 298 psFree (source->modelPSF); 297 299 source->modelPSF = psMemIncrRefCounter (DBL->data[0]); 298 source-> mode |= PM_SOURCE_MODE_SUBTRACTED;299 source->mode |= PM_SOURCE_MODE_PAIR;300 source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED; 301 source->mode |= PM_SOURCE_MODE_PAIR; 300 302 301 303 // copy most data from the primary source (modelEXT, blends stay NULL) -
branches/eam_branch_20090208/psphot/src/psphotSourceSize.c
r21366 r21490 56 56 57 57 // source must have been subtracted 58 if (!(source->mode & PM_SOURCE_MODE_SUBTRACTED)) { 58 if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) { 59 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED; 59 60 psTrace("psphot", 7, "Not calculating extNsigma,crNsigma since source is not subtracted\n"); 60 61 continue; … … 63 64 psF32 **resid = source->pixels->data.F32; 64 65 psF32 **variance = source->variance->data.F32; 65 psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA;66 psImageMaskType **mask = source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA; 66 67 67 68 // check for extendedness: measure the delta flux significance at the 1 sigma contour … … 82 83 if (xPeak < 1 || xPeak > source->pixels->numCols - 2 || 83 84 yPeak < 1 || yPeak > source->pixels->numRows - 2) { 85 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED; 84 86 psTrace("psphot", 7, "Not calculating crNsigma due to edge\n"); 85 87 continue; … … 98 100 if (!keep) { 99 101 psTrace("psphot", 7, "Not calculating crNsigma due to masked pixels\n"); 102 source->mode |= PM_SOURCE_MODE_SIZE_SKIPPED; 100 103 continue; 101 104 } … … 156 159 } 157 160 source->crNsigma = (nCR > 0) ? fCR / nCR : 0.0; 158 if (!isfinite(source->crNsigma)) continue; 161 if (!isfinite(source->crNsigma)) { 162 continue; 163 } 159 164 160 165 // this source is thought to be a cosmic ray. flag the detection and mask the pixels … … 264 269 // replace the source flux 265 270 pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal); 266 source-> mode &= ~PM_SOURCE_MODE_SUBTRACTED;271 source->tmpFlags &= ~PM_SOURCE_TMPF_SUBTRACTED; 267 272 268 273 // flag this as a CR -
branches/eam_branch_20090208/psphot/src/psphotSourceStats.c
r21359 r21490 1 1 # include "psphotInternal.h" 2 3 bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe);4 2 5 3 psArray *psphotSourceStats (pmConfig *config, pmReadout *readout, pmDetections *detections) { … … 80 78 for (int j = 0; j < cells->n; j++) { 81 79 82 if (nThreads) {83 // allocate a job -- if threads are not defined, this just runs the job84 psThreadJob *job = psThreadJobAlloc ("PSPHOT_SOURCE_STATS"); 85 86 psArrayAdd(job->args, 1, cells->data[j]); // sources87 psArrayAdd(job->args, 1, recipe);88 PS_ARRAY_ADD_SCALAR(job->args, 0, PS_TYPE_S32); // this is used as a return value for Nmoments89 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 { 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)) { 89 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 90 psFree (job); 91 return NULL; 92 } 93 psFree(job); 94 95 # if (0) 98 96 int nfail = 0; 99 97 int nmoments = 0; … … 104 102 Nfail += nfail; 105 103 Nmoments += nmoments; 104 # endif 105 } 106 107 // wait for the threads to finish and manage results 108 if (!psThreadPoolWait (false)) { 109 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 110 return NULL; 111 } 112 113 // we have only supplied one type of job, so we can assume the types here 114 psThreadJob *job = NULL; 115 while ((job = psThreadJobGetDone()) != NULL) { 116 if (job->args->n < 1) { 117 fprintf (stderr, "error with job\n"); 118 } else { 119 psScalar *scalar = NULL; 120 scalar = job->args->data[2]; 121 Nmoments += scalar->data.S32; 122 scalar = job->args->data[3]; 123 Nfail += scalar->data.S32; 106 124 } 107 } 108 109 if (nThreads) { 110 // wait for the threads to finish and manage results 111 if (!psThreadPoolWait (false)) { 112 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 113 return NULL; 114 } 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); 129 } 125 psFree(job); 130 126 } 131 127 } … … 148 144 psArray *sources = job->args->data[0]; 149 145 psMetadata *recipe = job->args->data[1]; 146 147 float INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS"); 148 if (!status) return false; 149 float MIN_SN = psMetadataLookupF32 (&status, recipe, "MOMENTS_SN_MIN"); 150 if (!status) return false; 151 float RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_MOMENTS_RADIUS"); 152 if (!status) return false; 153 154 // bit-masks to test for good/bad pixels 155 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); 156 assert (maskVal); 157 158 // bit-mask to mark pixels not used in analysis 159 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT"); 160 assert (markVal); 161 162 // maskVal is used to test for rejected pixels, and must include markVal 163 maskVal |= markVal; 164 165 // threaded measurement of the sources moments 166 int Nfail = 0; 167 int Nmoments = 0; 168 for (int i = 0; i < sources->n; i++) { 169 pmSource *source = sources->data[i]; 170 171 // skip faint sources for moments measurement 172 if (source->peak->SN < MIN_SN) { 173 source->mode |= PM_SOURCE_MODE_BELOW_MOMENTS_SN; 174 continue; 175 } 176 177 // measure a local sky value 178 // the local sky is now ignored; kept here for reference only 179 status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal); 180 if (!status) { 181 source->mode |= PM_SOURCE_MODE_SKY_FAILURE; 182 psErrorClear(); // XXX re-consider the errors raised here 183 Nfail ++; 184 continue; 185 } 186 187 // measure the local sky variance (needed if noise is not sqrt(signal)) 188 // XXX EAM : this should use ROBUST not SAMPLE median, but it is broken 189 status = pmSourceLocalSkyVariance (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal); 190 if (!status) { 191 source->mode |= PM_SOURCE_MODE_SKYVAR_FAILURE; 192 Nfail ++; 193 psErrorClear(); 194 continue; 195 } 196 197 // measure basic source moments 198 status = pmSourceMoments (source, RADIUS); 199 if (status) { 200 Nmoments ++; 201 continue; 202 } 203 204 // if no valid pixels, or massive swing, likely saturated source, 205 // try a much larger box 206 BIG_RADIUS = PS_MIN (INNER, 3*RADIUS); 207 psTrace ("psphot", 4, "retrying moments for %d, %d\n", source->peak->x, source->peak->y); 208 status = pmSourceMoments (source, BIG_RADIUS); 209 if (status) { 210 source->mode |= PM_SOURCE_MODE_BIG_RADIUS; 211 Nmoments ++; 212 continue; 213 } 214 215 source->mode |= PM_SOURCE_MODE_MOMENTS_FAILURE; 216 Nfail ++; 217 psErrorClear(); 218 continue; 219 } 220 221 // change the value of a scalar on the array (wrap this and put it in psArray.h) 222 scalar = job->args->data[2]; 223 scalar->data.S32 = Nmoments; 224 225 scalar = job->args->data[3]; 226 scalar->data.S32 = Nfail; 227 228 return true; 229 } 230 231 # if (0) 232 bool psphotSourceStats_Unthreaded (int *nfail, int *nmoments, psArray *sources, psMetadata *recipe) { 233 234 bool status = false; 235 float BIG_RADIUS; 150 236 151 237 float INNER = psMetadataLookupF32 (&status, recipe, "SKY_INNER_RADIUS"); … … 219 305 220 306 // change the value of a scalar on the array (wrap this and put it in psArray.h) 221 scalar = job->args->data[2];222 scalar->data.S32 = Nmoments;223 224 scalar = job->args->data[3];225 scalar->data.S32 = Nfail;226 227 return true;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 pixels243 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT");244 assert (maskVal);245 246 // bit-mask to mark pixels not used in analysis247 psImageMaskType markVal = psMetadataLookupImageMask(&status, recipe, "MARK.PSPHOT");248 assert (markVal);249 250 // maskVal is used to test for rejected pixels, and must include markVal251 maskVal |= markVal;252 253 // threaded measurement of the sources moments254 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 measurement260 if (source->peak->SN < MIN_SN) {261 continue;262 }263 264 // measure a local sky value265 // the local sky is now ignored; kept here for reference only266 status = pmSourceLocalSky (source, PS_STAT_SAMPLE_MEDIAN, INNER, maskVal, markVal);267 if (!status) {268 psErrorClear(); // XXX re-consider the errors raised here269 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 broken275 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 moments283 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 box291 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 307 *nmoments = Nmoments; 306 308 *nfail = Nfail; … … 308 310 return true; 309 311 } 312 # endif -
branches/eam_branch_20090208/psphot/src/psphotVisual.c
r21366 r21490 1101 1101 Graphdata graphdata; 1102 1102 1103 bool state = !(source-> mode & PM_SOURCE_MODE_SUBTRACTED);1103 bool state = !(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED); 1104 1104 psphotAddWithTest (source, true, maskVal); // replace source if subtracted 1105 1105
Note:
See TracChangeset
for help on using the changeset viewer.
