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/psphotGuessModels.c

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