Changeset 21166 for trunk/psphot/src/psphotApResid.c
- Timestamp:
- Jan 24, 2009, 10:54:29 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotApResid.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotApResid.c
r21080 r21166 4 4 // measure the aperture residual statistics and 2D variations 5 5 6 bool psphotApResid (pm Readout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf)6 bool psphotApResid (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) 7 7 { 8 8 int Nfail = 0; … … 13 13 pmSource *source; 14 14 15 PS_ASSERT_PTR_NON_NULL( psf, false);15 PS_ASSERT_PTR_NON_NULL(config, false); 16 16 PS_ASSERT_PTR_NON_NULL(readout, false); 17 17 PS_ASSERT_PTR_NON_NULL(sources, false); 18 PS_ASSERT_PTR_NON_NULL( recipe, false);18 PS_ASSERT_PTR_NON_NULL(psf, false); 19 19 20 20 psTimerStart ("psphot.apresid"); 21 22 // select the appropriate recipe information 23 psMetadata *recipe = psMetadataLookupPtr (&status, config->recipes, PSPHOT_RECIPE); 24 assert (recipe); 25 26 // determine the number of allowed threads 27 int nThreads = psMetadataLookupS32(&status, config->arguments, "NTHREADS"); // Number of threads 28 if (!status) { 29 nThreads = 0; 30 } 31 // nThreads = 0; // XXX until testing is complete, do not thread this function 21 32 22 33 bool measureAptrend = psMetadataLookupBool (&status, recipe, "MEASURE.APTREND"); … … 70 81 pmSourceMagnitudesInit (recipe); 71 82 83 // threaded measurement of the source magnitudes 84 // choose Cx, Cy (see psphotThreadTools.c for overview of the concepts) 85 int Cx = 1, Cy = 1; 86 psphotChooseCellSizes (&Cx, &Cy, readout, nThreads); 87 88 psArray *cellGroups = psphotAssignSources (Cx, Cy, sources); 89 90 for (int i = 0; i < cellGroups->n; i++) { 91 92 psArray *cells = cellGroups->data[i]; 93 94 for (int j = 0; j < cells->n; j++) { 95 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_U8); // XXX change this to use abstract mask type info 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)) { 108 psError(PS_ERR_UNKNOWN, false, "Unable to guess model."); 109 psFree (job); 110 return false; 111 } 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; 133 } 134 psFree(job); 135 } 136 } 137 138 psFree (cellGroups); 139 140 // gather the stats to assess the aperture residuals 72 141 psVector *mask = psVectorAllocEmpty (300, PS_TYPE_U8); 73 142 psVector *mag = psVectorAllocEmpty (300, PS_TYPE_F32); … … 78 147 Npsf = 0; 79 148 80 // select all good PM_SOURCE_TYPE_STAR entries81 149 for (int i = 0; i < sources->n; i++) { 82 150 source = sources->data[i]; … … 89 157 if (source->mode & PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR"); 90 158 91 // get growth-corrected, apTrend-uncorrected magnitudes in scaled apertures92 // will fail if below S/N threshold or model is missing93 if (!pmSourceMagnitudes (source, psf, photMode, maskVal)) {94 Nskip ++;95 psTrace ("psphot", 3, "skip : bad source mag");96 continue;97 }98 99 159 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 100 Nfail ++;101 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);102 160 continue; 103 161 } … … 206 264 207 265 psLogMsg ("psphot.apresid", PS_LOG_DETAIL, "aperture residual: %f +/- %f\n", psf->ApResid, psf->dApResid); 208 psLogMsg ("psphot.apresid", PS_LOG_INFO, "measure full-frame aperture residuals for : %f sec\n", psTimerMark ("psphot.apresid"));266 psLogMsg ("psphot.apresid", PS_LOG_INFO, "measure full-frame aperture residuals for %d sources: %f sec\n", Npsf, psTimerMark ("psphot.apresid")); 209 267 210 268 psFree (mag); … … 392 450 } 393 451 452 bool psphotApResidMags_Threaded (psThreadJob *job) { 453 454 int Nskip = 0; 455 int Nfail = 0; 456 457 psScalar *scalar = NULL; 458 459 psArray *sources = job->args->data[0]; 460 pmPSF *psf = job->args->data[1]; 461 pmSourcePhotometryMode photMode = PS_SCALAR_VALUE(job->args->data[2],S32); 462 psMaskType maskVal = PS_SCALAR_VALUE(job->args->data[3],U8); 463 464 for (int i = 0; i < sources->n; i++) { 465 pmSource *source = (pmSource *) sources->data[i]; 466 467 if (source->type != PM_SOURCE_TYPE_STAR) SKIPSTAR ("NOT STAR"); 468 if (source->mode & PM_SOURCE_MODE_SATSTAR) SKIPSTAR ("SATSTAR"); 469 if (source->mode & PM_SOURCE_MODE_BLEND) SKIPSTAR ("BLEND"); 470 if (source->mode & PM_SOURCE_MODE_FAIL) SKIPSTAR ("FAIL STAR"); 471 if (source->mode & PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR"); 472 473 if (!pmSourceMagnitudes (source, psf, photMode, maskVal)) { 474 Nskip ++; 475 psTrace ("psphot", 3, "skip : bad source mag"); 476 continue; 477 } 478 479 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 480 Nfail ++; 481 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag); 482 continue; 483 } 484 } 485 486 // change the value of a scalar on the array (wrap this and put it in psArray.h) 487 scalar = job->args->data[4]; 488 scalar->data.S32 = Nskip; 489 490 scalar = job->args->data[5]; 491 scalar->data.S32 = Nfail; 492 493 return true; 494 }
Note:
See TracChangeset
for help on using the changeset viewer.
