Changeset 16820 for trunk/psphot/src/psphotGuessModels.c
- Timestamp:
- Mar 4, 2008, 3:10:25 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotGuessModels.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotGuessModels.c
r13900 r16820 17 17 18 18 // construct an initial PSF model for each object 19 bool psphotGuessModels (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf , psMaskType maskVal) {19 bool psphotGuessModels (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf) { 20 20 21 psTimerStart ("psphot");21 bool status; 22 22 23 // setup the PSF fit radius details 24 psphotInitRadiusPSF (recipe, psf->type); 23 psTimerStart ("psphot"); 25 24 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); 28 28 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); 32 31 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); 54 94 } 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; 91 97 } 92 98
Note:
See TracChangeset
for help on using the changeset viewer.
