Changeset 17396 for trunk/psphot/src/psphotPSFConvModel.c
- Timestamp:
- Apr 8, 2008, 8:36:06 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotPSFConvModel.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotPSFConvModel.c
r14655 r17396 1 # include "psphot.h" 1 # include "psphotInternal.h" 2 # define USE_DELTA_PSF 0 2 3 3 4 // save as static values so they may be set externally 4 5 static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15; 5 6 static psF32 PM_SOURCE_FIT_MODEL_TOLERANCE = 0.1; 6 // static psF32 PM_SOURCE_FIT_MODEL_WEIGHT = 1.0;7 // static bool PM_SOURCE_FIT_MODEL_PIX_WEIGHTS = true;8 7 9 8 // input source has both modelPSF and modelEXT. on successful exit, we set the 10 9 // modelConv to contain the fitted parameters, and the modelFlux to contain the 11 10 // convolved model image. 12 bool psphotPSFConvModel (pmSource *source, psMetadata *recipe, psMaskType maskVal) {11 pmModel *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmModelType modelType, psMaskType maskVal, int psfSize) { 13 12 14 bool status;15 16 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE");17 if (!status) {18 psfSize = 2;19 }20 21 13 // make sure we save a cached copy of the psf flux 22 14 pmSourceCachePSF (source, maskVal); 23 15 24 16 // convert the cached cached psf model for this source to a psKernel 25 // XXX for the moment, hard-wire the kernel to be 5x5 (2 pix radius)26 // XXX for the moment, hard-wire the kernel to be 9x9 (4 pix radius)27 17 psKernel *psf = psphotKernelFromPSF (source, psfSize); 18 if (!psf) return NULL; 28 19 29 // psf must be normalized (integral = 1.0) 30 double sum = 0.0; 31 for (int i = 0; i < psf->image->numRows; i++) { 32 for (int j = 0; j < psf->image->numCols; j++) { 33 sum += psf->image->data.F32[i][j]; 34 } 35 } 36 assert (sum > 0.0); 37 for (int i = 0; i < psf->image->numRows; i++) { 38 for (int j = 0; j < psf->image->numCols; j++) { 39 psf->image->data.F32[i][j] /= sum; 40 } 41 } 42 43 # if (0) 44 // XXX sanity check: convolve with delta function should behave like unconvolved version 45 for (int i = 0; i < psf->image->numRows; i++) { 46 for (int j = 0; j < psf->image->numCols; j++) { 47 psf->image->data.F32[i][j] = 0.0; 48 } 49 } 50 psf->image->data.F32[2][2] = 1.0; 20 # if (USE_DELTA_PSF) 21 psImageInit (psf->image, 0.0); 22 psf->image->data.F32[(int)(0.5*psf->image->numRows)][(int)(0.5*psf->image->numCols)] = 1.0; 51 23 # endif 52 24 … … 54 26 // XXX we could modify the parameter values or even the model 55 27 // here based on the observed seeing (some lookup table...) 56 pmModel *modelConv = pmModelCopy (source->modelEXT); 28 29 // use the source moments, etc to guess basic model parameters 30 pmModel *modelConv = pmSourceModelGuess (source, modelType); 31 if (!modelConv) { 32 psFree (psf); 33 return NULL; 34 } 35 36 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 37 psEllipseShape psfShape; 38 psfShape.sx = source->modelPSF->params->data.F32[PM_PAR_SXX] / M_SQRT2; 39 psfShape.sxy = source->modelPSF->params->data.F32[PM_PAR_SXY]; 40 psfShape.sy = source->modelPSF->params->data.F32[PM_PAR_SYY] / M_SQRT2; 41 psEllipseAxes psfAxes = psEllipseShapeToAxes (psfShape, 20.0); 42 43 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 44 psEllipseShape extShape; 45 extShape.sx = modelConv->params->data.F32[PM_PAR_SXX] / M_SQRT2; 46 extShape.sxy = modelConv->params->data.F32[PM_PAR_SXY]; 47 extShape.sy = modelConv->params->data.F32[PM_PAR_SYY] / M_SQRT2; 48 psEllipseAxes extAxes = psEllipseShapeToAxes (extShape, 20.0); 49 50 // decrease the initial guess ellipse by psf_minor axis: 51 psEllipseAxes extAxesMod; 52 extAxesMod.major = sqrt (PS_MAX (1.0, PS_SQR(extAxes.major) - PS_SQR(psfAxes.minor))); 53 extAxesMod.minor = sqrt (PS_MAX (1.0, PS_SQR(extAxes.minor) - PS_SQR(psfAxes.minor))); 54 extAxesMod.theta = extAxes.theta; 55 56 psEllipseShape extShapeMod = psEllipseAxesToShape (extAxesMod); 57 modelConv->params->data.F32[PM_PAR_SXX] = extShapeMod.sx * M_SQRT2; 58 modelConv->params->data.F32[PM_PAR_SXY] = extShapeMod.sxy; 59 modelConv->params->data.F32[PM_PAR_SYY] = extShapeMod.sy * M_SQRT2; 60 61 // increase the initial guess central intensity by 2pi r^2: 62 modelConv->params->data.F32[PM_PAR_I0] *= (1.0 + PS_SQR(psfAxes.minor) / PS_SQR(extAxesMod.minor)); 63 57 64 psVector *params = modelConv->params; 58 65 psVector *dparams = modelConv->dparams; 66 67 psphotCheckRadiusEXT (readout, source, modelConv); 59 68 60 69 // create the minimization constraints … … 91 100 psTrace ("psphot", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value); 92 101 93 // renormalize output model image 102 // renormalize output model image (generated by fitting process) 94 103 float Io = params->data.F32[PM_PAR_I0]; 95 104 for (int iy = 0; iy < source->modelFlux->numRows; iy++) { … … 115 124 onPic &= (params->data.F32[PM_PAR_YPOS] >= source->pixels->row0); 116 125 onPic &= (params->data.F32[PM_PAR_YPOS] < source->pixels->row0 + source->pixels->numRows); 117 if (!onPic) { 118 modelConv->flags |= PM_MODEL_STATUS_OFFIMAGE; 119 } 126 if (!onPic) modelConv->flags |= PM_MODEL_STATUS_OFFIMAGE; 120 127 121 source->mode |= PM_SOURCE_MODE_FITTED; 122 source->modelConv = modelConv; 128 source->mode |= PM_SOURCE_MODE_FITTED; // XXX is this needed? 123 129 130 psFree(psf); 124 131 psFree(myMin); 125 132 psFree(covar); 126 133 psFree(constraint); 127 134 128 bool retval = (onPic && fitStatus); 129 psTrace("psphot", 5, "---- %s(%d) end ----\n", __func__, retval); 130 return(retval); 135 return modelConv; 131 136 }
Note:
See TracChangeset
for help on using the changeset viewer.
