IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 5, 2009, 3:12:59 PM (17 years ago)
Author:
eugene
Message:

defining test unthreaded versions for these functions to avoid hitting the psThreadJob array; remove eventually

File:
1 edited

Legend:

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

    r21252 r21359  
    11# include "psphotInternal.h"
     2
     3bool psphotMagnitudes_Unthreaded (int *nap, psArray *sources, pmPSF *psf, psImageBinning *binning, pmReadout *backModel, pmReadout *backStdev, pmSourcePhotometryMode photMode, psImageMaskType maskVal);
    24
    35bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) {
     
    1719        nThreads = 0;
    1820    }
    19     // nThreads = 0; // XXX until testing is complete, do not thread this function
    2021
    2122    // if backModel or backStdev are missing, the values of sky and/or skyErr will be set to NAN
     
    5859        for (int j = 0; j < cells->n; j++) {
    5960
    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)) {
    7494                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    75                 psFree (job);
    7695                return false;
    7796            }
    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            }
    98109        }
    99110    }
     
    116127    pmReadout *backStdev            = job->args->data[4];
    117128    pmSourcePhotometryMode photMode = PS_SCALAR_VALUE(job->args->data[5],S32);
    118     psMaskType maskVal              = PS_SCALAR_VALUE(job->args->data[6],U8);
     129    psImageMaskType maskVal         = PS_SCALAR_VALUE(job->args->data[6],PS_TYPE_IMAGE_MASK_DATA);
    119130
    120131    for (int i = 0; i < sources->n; i++) {
     
    150161    return true;
    151162}
     163
     164bool 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)
     202bool 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
     285bool 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
Note: See TracChangeset for help on using the changeset viewer.