IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 4, 2008, 3:10:25 PM (18 years ago)
Author:
eugene
Message:

merge changes from eam_branch_20080229: better flag definitions, cleanup footprint code (move into psphotFindDetections), push mask selection into called functions

File:
1 edited

Legend:

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

    r13900 r16820  
    1717
    1818// construct an initial PSF model for each object
    19 bool psphotGuessModels (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal) {
     19bool psphotGuessModels (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf) {
    2020
    21   psTimerStart ("psphot");
     21    bool status;
    2222
    23   // setup the PSF fit radius details
    24   psphotInitRadiusPSF (recipe, psf->type);
     23    psTimerStart ("psphot");
    2524
    26   for (int i = 0; i < sources->n; i++) {
    27     pmSource *source = sources->data[i];
     25    // user-defined masks to test for good/bad pixels (build from recipe list if not yet set)
     26    psMaskType maskVal = psMetadataLookupU8(&status, recipe, "MASK.PSPHOT"); // Mask value for bad pixels
     27    assert (maskVal);
    2828
    29     // skip non-astronomical objects (very likely defects)
    30     if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
    31     if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     29    // setup the PSF fit radius details
     30    psphotInitRadiusPSF (recipe, psf->type);
    3231
    33     // XXX if a source is faint, it will not have moments measured.
    34     // it must be modelled as a PSF.  In this case, we need to use
    35     // the peak centroid to get the coordinates and get the peak flux
    36     // from the image?
    37     pmModel *modelEXT;
    38     if (!source->moments) {
    39         modelEXT = wildGuess(source, psf);
    40     } else {
    41         // use the source moments, etc to guess basic model parameters
    42         modelEXT = pmSourceModelGuess (source, psf->type);
    43         if (!modelEXT) {
    44             modelEXT = wildGuess(source, psf);
    45         }
    46         // these valuse are set in pmSourceModelGuess, should this rule be in there as well?
    47         if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
    48             modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->x;
    49             modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->y;
    50         } else {
    51             modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf;
    52             modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf;
    53         }
     32    for (int i = 0; i < sources->n; i++) {
     33        pmSource *source = sources->data[i];
     34
     35        // skip non-astronomical objects (very likely defects)
     36        if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
     37        if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
     38
     39        // XXX if a source is faint, it will not have moments measured.
     40        // it must be modelled as a PSF.  In this case, we need to use
     41        // the peak centroid to get the coordinates and get the peak flux
     42        // from the image?
     43        pmModel *modelEXT;
     44        if (!source->moments) {
     45            modelEXT = wildGuess(source, psf);
     46        } else {
     47            // use the source moments, etc to guess basic model parameters
     48            modelEXT = pmSourceModelGuess (source, psf->type);
     49            if (!modelEXT) {
     50                modelEXT = wildGuess(source, psf);
     51            }
     52            // these valuse are set in pmSourceModelGuess, should this rule be in there as well?
     53            if (source->mode &  PM_SOURCE_MODE_SATSTAR) {
     54                modelEXT->params->data.F32[PM_PAR_XPOS] = source->moments->x;
     55                modelEXT->params->data.F32[PM_PAR_YPOS] = source->moments->y;
     56            } else {
     57                modelEXT->params->data.F32[PM_PAR_XPOS] = source->peak->xf;
     58                modelEXT->params->data.F32[PM_PAR_YPOS] = source->peak->yf;
     59            }
     60        }
     61
     62        // set PSF parameters for this model (apply 2D shape model)
     63        pmModel *modelPSF = pmModelFromPSF (modelEXT, psf);
     64        if (modelPSF == NULL) {
     65            psError(PSPHOT_ERR_PSF, false,
     66                    "Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
     67                    source->peak->y, source->peak->x);
     68            //
     69            // Try the centre of the image
     70            //
     71            modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols;
     72            modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows;
     73            modelPSF = pmModelFromPSF (modelEXT, psf);
     74            if (modelPSF == NULL) {
     75                psError(PSPHOT_ERR_PSF, false,
     76                        "Failed to determine PSF model at centre of image");
     77                psFree(modelEXT);
     78                return false;
     79            }
     80
     81            source->mode |= PM_SOURCE_MODE_BADPSF;
     82        }
     83        psFree (modelEXT);
     84
     85        // XXX need to define the guess flux?
     86        // set the fit radius based on the object flux limit and the model
     87        psphotCheckRadiusPSF (readout, source, modelPSF);
     88
     89        // set the source PSF model
     90        source->modelPSF = modelPSF;
     91        source->modelPSF->residuals = psf->residuals;
     92
     93        pmSourceCacheModel (source, maskVal);
    5494    }
    55 
    56     // set PSF parameters for this model (apply 2D shape model)
    57     pmModel *modelPSF = pmModelFromPSF (modelEXT, psf);
    58     if (modelPSF == NULL) {
    59         psError(PSPHOT_ERR_PSF, false,
    60                 "Failed to determine PSF model at r,c = (%d,%d); trying centre of image",
    61                 source->peak->y, source->peak->x);
    62         //
    63         // Try the centre of the image
    64         //
    65         modelEXT->params->data.F32[PM_PAR_XPOS] = 0.5*readout->image->numCols;
    66         modelEXT->params->data.F32[PM_PAR_YPOS] = 0.5*readout->image->numRows;
    67         modelPSF = pmModelFromPSF (modelEXT, psf);
    68         if (modelPSF == NULL) {
    69             psError(PSPHOT_ERR_PSF, false,
    70                     "Failed to determine PSF model at centre of image");
    71             psFree(modelEXT);
    72             return false;
    73         }
    74 
    75         source->mode |= PM_SOURCE_MODE_BADPSF;
    76     }
    77     psFree (modelEXT);
    78 
    79     // XXX need to define the guess flux?
    80     // set the fit radius based on the object flux limit and the model
    81     psphotCheckRadiusPSF (readout, source, modelPSF);
    82 
    83     // set the source PSF model
    84     source->modelPSF = modelPSF;
    85     source->modelPSF->residuals = psf->residuals;
    86 
    87     pmSourceCacheModel (source, maskVal);
    88   }
    89   psLogMsg ("psphot.models", 4, "built models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot"));
    90   return true;
     95    psLogMsg ("psphot.models", 4, "built models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot"));
     96    return true;
    9197}
    9298
Note: See TracChangeset for help on using the changeset viewer.