Changeset 21359 for trunk/psphot/src/psphotSourceStats.c
- Timestamp:
- Feb 5, 2009, 3:12:59 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotSourceStats.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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.
