IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 3, 2009, 1:55:26 PM (17 years ago)
Author:
eugene
Message:

modify threading to call unthreaded versions of functions for nThreads <= 1 (for testing)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20090203/psphot/src/psphotGuessModels.c

    r21183 r21274  
    2222}
    2323
     24bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
     25
    2426// construct an initial PSF model for each object
    2527bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) {
     
    6668        for (int j = 0; j < cells->n; j++) {
    6769
    68             // allocate a job -- if threads are not defined, this just runs the job
    69             psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
    70             psArrayAdd(job->args, 1, readout);
    71             psArrayAdd(job->args, 1, cells->data[j]); // sources
    72             psArrayAdd(job->args, 1, psf);
    73 
    74             // XXX change these to use abstract mask type info
    75             PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
    76             PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
    77 
    78             if (!psThreadJobAddPending(job)) {
     70            if (nThreads > 1) {
     71                // allocate a job -- if threads are not defined, this just runs the job
     72                psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
     73                psArrayAdd(job->args, 1, readout);
     74                psArrayAdd(job->args, 1, cells->data[j]); // sources
     75                psArrayAdd(job->args, 1, psf);
     76
     77                // XXX change these to use abstract mask type info
     78                PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     79                PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
     80
     81                if (!psThreadJobAddPending(job)) {
     82                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     83                    psFree (job);
     84                    return false;
     85                }
     86                psFree(job);
     87            } else {
     88                if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) {
     89                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     90                    return false;
     91                }
     92            }
     93        }
     94
     95        if (nThreads > 1) {
     96            // wait for the threads to finish and manage results
     97            // wait here for the threaded jobs to finish
     98            // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
     99            if (!psThreadPoolWait (false)) {
    79100                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    80                 psFree (job);
    81101                return false;
    82102            }
    83             psFree(job);
    84         }
    85 
    86         // wait for the threads to finish and manage results
    87         // wait here for the threaded jobs to finish
    88         // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
    89         if (!psThreadPoolWait (false)) {
    90             psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    91             return false;
    92         }
    93 
    94         // we have only supplied one type of job, so we can assume the types here
    95         psThreadJob *job = NULL;
    96         while ((job = psThreadJobGetDone()) != NULL) {
    97             // we have no returned data from this operation
    98             if (job->args->n < 1) {
    99                 fprintf (stderr, "error with job\n");
    100             }
    101             psFree(job);
     103
     104            // we have only supplied one type of job, so we can assume the types here
     105            psThreadJob *job = NULL;
     106            while ((job = psThreadJobGetDone()) != NULL) {
     107                // we have no returned data from this operation
     108                if (job->args->n < 1) {
     109                    fprintf (stderr, "error with job\n");
     110                }
     111                psFree(job);
     112            }
    102113        }
    103114    }
     
    211222}
    212223
     224// construct models only for sources in the specified region
     225bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
     226
     227    int nSrc = 0;
     228
     229    for (int i = 0; i < sources->n; i++) {
     230        pmSource *source = sources->data[i];
     231
     232        // XXXX this is just for a test: use this to mark sources for which the model is measured
     233        // check later that all are used.
     234        source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
     235
     236        // skip non-astronomical objects (very likely defects)
     237        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
     238        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     239        if (!source->peak) continue;
     240
     241        nSrc ++;
     242       
     243        // XXX if a source is faint, it will not have moments measured.
     244        // it must be modelled as a PSF.  In this case, we need to use
     245        // the peak centroid to get the coordinates and get the peak flux
     246        // from the image?
     247        pmModel *modelEXT;
     248        if (!source->moments) {
     249            modelEXT = wildGuess(source, psf);
     250        } else {
     251            // use the source moments, etc to guess basic model parameters
     252            modelEXT = pmSourceModelGuess (source, psf->type); // ALLOC
     253            if (!modelEXT) {
     254                modelEXT = wildGuess(source, psf);
     255            }
     256            // these valuse are set in pmSourceModelGuess, should this rule be in there as well?
     257            if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
     258                modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->Mx;
     259                modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->My;
     260            } else {
     261                modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf;
     262                modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf;
     263            }
     264        }
     265
     266        // set PSF parameters for this model (apply 2D shape model)
     267        pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC
     268        if (modelPSF == NULL) {
     269            psError(PSPHOT_ERR_PSF, false,
     270                    "Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
     271                    source->peak->y, source->peak->x);
     272            //
     273            // Try the centre of the image
     274            //
     275            modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols;
     276            modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows;
     277            modelPSF = pmModelFromPSF (modelEXT, psf);
     278            if (modelPSF == NULL) {
     279                psError(PSPHOT_ERR_PSF, false,
     280                        "Failed to determine PSF model at centre of image");
     281                psFree(modelEXT);
     282                return false;
     283            }
     284
     285            source->mode |= PM_SOURCE_MODE_BADPSF;
     286        }
     287        psFree (modelEXT);
     288
     289        // XXX need to define the guess flux?
     290        // set the fit radius based on the object flux limit and the model
     291        // this function affects the mask pixels
     292        psphotCheckRadiusPSF (readout, source, modelPSF, markVal);
     293
     294        // set the source PSF model
     295        source->modelPSF = modelPSF;
     296        source->modelPSF->residuals = psf->residuals;
     297
     298        pmSourceCacheModel (source, maskVal);
     299
     300    }
     301
     302    return true;
     303}
Note: See TracChangeset for help on using the changeset viewer.