IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 16, 2009, 12:34:24 PM (17 years ago)
Author:
eugene
Message:

added additional flag values, threaded functions always use the threaded version

File:
1 edited

Legend:

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

    r21381 r21519  
    2222}
    2323
    24 bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal);
    25 
    2624// construct an initial PSF model for each object
    2725bool psphotGuessModels (pmConfig *config, pmReadout *readout, psArray *sources, pmPSF *psf) {
     
    6765        for (int j = 0; j < cells->n; j++) {
    6866
    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 {
     67            // allocate a job -- if threads are not defined, this just runs the job
     68            psThreadJob *job = psThreadJobAlloc ("PSPHOT_GUESS_MODEL");
     69            psArrayAdd(job->args, 1, readout);
     70            psArrayAdd(job->args, 1, cells->data[j]); // sources
     71            psArrayAdd(job->args, 1, psf);
     72
     73            // XXX change these to use abstract mask type info
     74            PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
     75            PS_ARRAY_ADD_SCALAR(job->args, markVal,  PS_TYPE_IMAGE_MASK);
     76
     77            if (!psThreadJobAddPending(job)) {
     78                psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     79                psFree (job);
     80                return false;
     81            }
     82            psFree(job);
     83
     84# if (0)               
    8785                if (!psphotGuessModel_Unthreaded (readout, cells->data[j], psf, maskVal, markVal)) {
    8886                    psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    8987                    return false;
    9088                }
    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)) {
    99                 psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
    100                 return false;
    101             }
    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             }
     89# endif
     90        }
     91
     92        // wait for the threads to finish and manage results
     93        // wait here for the threaded jobs to finish
     94        // fprintf (stderr, "wait for threads (%d, %d)\n", jx, jy);
     95        if (!psThreadPoolWait (false)) {
     96            psError(PS_ERR_UNKNOWN, false, "Unable to guess model.");
     97            return false;
     98        }
     99
     100        // we have only supplied one type of job, so we can assume the types here
     101        psThreadJob *job = NULL;
     102        while ((job = psThreadJobGetDone()) != NULL) {
     103            // we have no returned data from this operation
     104            if (job->args->n < 1) {
     105                fprintf (stderr, "error with job\n");
     106            }
     107            psFree(job);
    112108        }
    113109    }
     
    116112    int nMiss = 0;
    117113    for (int i = 0; i < sources->n; i++) {
    118 
    119114        pmSource *source = sources->data[i];
    120         if (source->mode & PM_SOURCE_MODE_EXT_LIMIT) {
    121             source->mode &= ~PM_SOURCE_MODE_EXT_LIMIT;
     115        if (source->tmpFlags & PM_SOURCE_TMPF_MODEL_GUESS) {
    122116            continue;
    123117        }
    124 
    125118        nMiss ++;
    126119    }
    127     psLogMsg ("psphot.models", 4, "failed to build models for %d objects\n", nMiss);
     120    psAssert (nMiss == 0, "failed to attempt to build models for %d objects\n", nMiss);
    128121
    129122    psFree (cellGroups);
     
    148141        pmSource *source = sources->data[i];
    149142
    150         // XXXX this is just for a test: use this to mark sources for which the model is measured
    151         // check later that all are used.
    152         source->mode |= PM_SOURCE_MODE_EXT_LIMIT;
     143        // this is used to mark sources for which the model is measured. We check later that
     144        // all are used.
     145        source->tmpFlags |= PM_SOURCE_TMPF_MODEL_GUESS;
    153146
    154147        // skip non-astronomical objects (very likely defects)
     
    185178        pmModel *modelPSF = pmModelFromPSF (modelEXT, psf); // ALLOC X5
    186179        if (modelPSF == NULL) {
    187             psError(PSPHOT_ERR_PSF, false,
    188                     "Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
     180            psWarning ("Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
    189181                    source->peak->y, source->peak->x);
    190             //
    191             // Try the centre of the image
    192             //
     182
     183            // Try the center of the image
    193184            modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols;
    194185            modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows;
    195186            modelPSF = pmModelFromPSF (modelEXT, psf);
    196187            if (modelPSF == NULL) {
    197                 psError(PSPHOT_ERR_PSF, false,
    198                         "Failed to determine PSF model at centre of image");
     188                psError(PSPHOT_ERR_PSF, false, "Failed to determine PSF model at center of image");
    199189                psFree(modelEXT);
    200190                return false;
    201191            }
    202 
    203192            source->mode |= PM_SOURCE_MODE_BADPSF;
    204193        }
     
    221210}
    222211
     212# if (0)
    223213// construct models only for sources in the specified region
    224214bool psphotGuessModel_Unthreaded (pmReadout *readout, psArray *sources, pmPSF *psf, psImageMaskType maskVal, psImageMaskType markVal) {
     
    301291    return true;
    302292}
     293# endif
Note: See TracChangeset for help on using the changeset viewer.