IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 24, 2009, 10:54:29 AM (17 years ago)
Author:
eugene
Message:

clean up threading model for psphotGuessModel (defined standard way to split sources into regions); extending the threading to psphotMagnitudes, psphotApReset, psphotBlendFit, psphotSourceStats

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psphot/src/psphotApResid.c

    r21080 r21166  
    44// measure the aperture residual statistics and 2D variations
    55
    6 bool psphotApResid (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf)
     6bool psphotApResid (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf)
    77{
    88    int Nfail = 0;
     
    1313    pmSource *source;
    1414
    15     PS_ASSERT_PTR_NON_NULL(psf, false);
     15    PS_ASSERT_PTR_NON_NULL(config, false);
    1616    PS_ASSERT_PTR_NON_NULL(readout, false);
    1717    PS_ASSERT_PTR_NON_NULL(sources, false);
    18     PS_ASSERT_PTR_NON_NULL(recipe, false);
     18    PS_ASSERT_PTR_NON_NULL(psf, false);
    1919
    2020    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
    2132
    2233    bool measureAptrend = psMetadataLookupBool (&status, recipe, "MEASURE.APTREND");
     
    7081    pmSourceMagnitudesInit (recipe);
    7182
     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
    72141    psVector *mask    = psVectorAllocEmpty (300, PS_TYPE_U8);
    73142    psVector *mag     = psVectorAllocEmpty (300, PS_TYPE_F32);
     
    78147    Npsf = 0;
    79148
    80     // select all good PM_SOURCE_TYPE_STAR entries
    81149    for (int i = 0; i < sources->n; i++) {
    82150        source = sources->data[i];
     
    89157        if (source->mode &  PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR");
    90158
    91         // get growth-corrected, apTrend-uncorrected magnitudes in scaled apertures
    92         // will fail if below S/N threshold or model is missing
    93         if (!pmSourceMagnitudes (source, psf, photMode, maskVal)) {
    94             Nskip ++;
    95             psTrace ("psphot", 3, "skip : bad source mag");
    96             continue;
    97         }
    98 
    99159        if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
    100             Nfail ++;
    101             psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);
    102160            continue;
    103161        }
     
    206264
    207265    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"));
    209267
    210268    psFree (mag);
     
    392450}
    393451
     452bool 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.