Changeset 28692
- Timestamp:
- Jul 20, 2010, 7:21:53 PM (16 years ago)
- Location:
- branches/eam_branches/ipp-20100621
- Files:
-
- 1 added
- 14 edited
-
psModules/src/objects/Makefile.am (modified) (2 diffs)
-
psModules/src/objects/pmPCM_MinimizeChisq.c (modified) (13 diffs)
-
psModules/src/objects/pmPCMdata.c (modified) (1 diff)
-
psModules/src/objects/pmPCMdata.h (added)
-
psModules/src/objects/pmPSFtryFitPSF.c (modified) (1 diff)
-
psModules/src/objects/pmSourceFitPCM.c (modified) (4 diffs)
-
psModules/src/objects/pmSourcePhotometry.c (modified) (2 diffs)
-
psModules/src/objects/pmSourcePhotometry.h (modified) (1 diff)
-
psModules/src/psmodules.h (modified) (1 diff)
-
psphot/src/Makefile.am (modified) (1 diff)
-
psphot/src/psphot.h (modified) (3 diffs)
-
psphot/src/psphotApResid.c (modified) (1 diff)
-
psphot/src/psphotMagnitudes.c (modified) (1 diff)
-
psphot/src/psphotSourceFits.c (modified) (9 diffs)
-
psphot/src/psphotSourceSize.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/psModules/src/objects/Makefile.am
r28643 r28692 61 61 pmPSFtryFitPSF.c \ 62 62 pmPSFtryMetric.c \ 63 pmPCMdata.c \ 64 pmPCM_MinimizeChisq.c \ 65 pmSourceFitPCM.c \ 63 66 pmTrend2D.c \ 64 67 pmGrowthCurveGenerate.c \ … … 105 108 pmPSF_IO.h \ 106 109 pmPSFtry.h \ 110 pmPCMdata.h \ 107 111 pmTrend2D.h \ 108 112 pmGrowthCurve.h \ -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCM_MinimizeChisq.c
r28687 r28692 1 # include "psphotInternal.h" 2 # define SAVE_IMAGES 0 3 4 bool psphotModelWithPSF_LMM ( 1 /* @file pmPCM_MinimizeChisq.c 2 * structures and functions to support PSF-convolved model fitting 3 * 4 * @author EAM, IfA 5 * 6 * @version $Revision: 1.29 $ 7 * @date $Date: 2009-02-16 22:30:50 $ 8 * Copyright 2010 Institute for Astronomy, University of Hawaii 9 */ 10 11 #ifdef HAVE_CONFIG_H 12 #include <config.h> 13 #endif 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include <strings.h> 19 #include <pslib.h> 20 #include "pmHDU.h" 21 #include "pmFPA.h" 22 #include "pmFPAMaskWeight.h" 23 24 #include "pmTrend2D.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmSpan.h" 28 #include "pmFootprintSpans.h" 29 #include "pmFootprint.h" 30 #include "pmPeaks.h" 31 #include "pmMoments.h" 32 #include "pmModelFuncs.h" 33 #include "pmModel.h" 34 #include "pmModelUtils.h" 35 #include "pmModelClass.h" 36 #include "pmSourceMasks.h" 37 #include "pmSourceExtendedPars.h" 38 #include "pmSourceDiffStats.h" 39 #include "pmSource.h" 40 #include "pmSourceFitModel.h" 41 #include "pmPCMdata.h" 42 43 # define FACILITY "psModules.objects" 44 45 bool pmPCM_MinimizeChisq ( 5 46 psMinimization *min, 6 47 psImage *covar, 7 48 psVector *params, 8 psMinConstraint *constraint,9 49 pmSource *source, 10 const psKernel *psf, 11 psMinimizeLMChi2Func func) 50 pmPCMdata *pcm) 12 51 { 13 psTrace( "psphot", 3, "---- begin ----\n");52 psTrace(FACILITY, 3, "---- begin ----\n"); 14 53 PS_ASSERT_PTR_NON_NULL(min, false); 15 54 PS_ASSERT_VECTOR_NON_NULL(params, false); 16 55 PS_ASSERT_VECTOR_NON_EMPTY(params, false); 17 56 PS_ASSERT_VECTOR_TYPE(params, PS_TYPE_F32, false); 18 psVector *paramMask = NULL;19 if (constraint != NULL) {20 paramMask = constraint->paramMask;21 if (paramMask != NULL) {22 PS_ASSERT_VECTOR_TYPE(paramMask, PS_TYPE_VECTOR_MASK, false);23 PS_ASSERT_VECTORS_SIZE_EQUAL(params, paramMask, false);24 }25 }26 PS_ASSERT_PTR_NON_NULL(func, false);27 57 PS_ASSERT_PTR_NON_NULL(source, false); 28 29 psMinimizeLMLimitFunc checkLimits = NULL; 30 if (constraint) { 31 checkLimits = constraint->checkLimits; 32 } 58 PS_ASSERT_PTR_NON_NULL(pcm, false); 59 PS_ASSERT_VECTOR_TYPE(pcm->constraint->paramMask, PS_TYPE_VECTOR_MASK, false); 60 PS_ASSERT_VECTORS_SIZE_EQUAL(params, pcm->constraint->paramMask, false); 61 62 psVector *paramMask = pcm->constraint->paramMask; 63 64 psMinimizeLMLimitFunc checkLimits = pcm->constraint->checkLimits; 33 65 34 66 // this function has test values and current values for several things … … 54 86 psF32 dLinear = 0.0; 55 87 56 // generate PCM data storage structure57 pmPCMData *pcm = pmPCMDataAlloc (params, paramMask, source);58 59 88 // calculate initial alpha and beta, set chisq (min->value) 60 min->value = p sphotModelWithPSF_SetABX(alpha, beta, params, paramMask, pcm, source, psf, func);89 min->value = pmPCM_SetABX(alpha, beta, params, paramMask, pcm, source); 61 90 if (isnan(min->value)) { 62 91 min->iter = min->maxIter; … … 64 93 } 65 94 // dump some useful info if trace is defined 66 if (psTraceGetLevel( "psphot") >= 6) {95 if (psTraceGetLevel(FACILITY) >= 6) { 67 96 p_psImagePrint(psTraceGetDestination(), alpha, "alpha guess (0)"); 68 97 p_psVectorPrint(psTraceGetDestination(), beta, "beta guess (0)"); 69 98 } 70 if (psTraceGetLevel( "psphot") >= 5) {99 if (psTraceGetLevel(FACILITY) >= 5) { 71 100 p_psVectorPrint(psTraceGetDestination(), params, "params guess (0)"); 72 101 } 73 102 74 103 // iterate until the tolerance is reached, or give up 75 while ((min->iter < min->maxIter) && ((min->lastDelta > min->minTol) || !isfinite(min->lastDelta))) {76 psTrace("psphot", 5, "Iteration number %d. (max iterations is %d).\n", min->iter, min->maxIter);77 psTrace("ps phot", 5, "Last delta is %f. Min->minTol is %f.\n", min->lastDelta, min->minTol);78 104 bool done = (min->iter >= min->maxIter); 105 while (!done) { 106 psTrace("psModules.objects", 5, "Iteration number %d. (max iterations is %d).\n", min->iter, min->maxIter); 107 psTrace("psModules.objects", 5, "Last delta is %f. stop if < %f, accept if < %f\n", min->lastDelta, min->minTol, min->maxTol); 79 108 80 109 // set a new guess for Alpha, Beta, Params 81 110 if (!psMinLM_GuessABP(Alpha, Beta, Params, alpha, beta, params, paramMask, checkLimits, lambda, &dLinear)) { 82 111 min->iter ++; 112 if (min->iter >= min->maxIter) break; 83 113 lambda *= 10.0; 84 114 continue; … … 86 116 87 117 // dump some useful info if trace is defined 88 if (psTraceGetLevel( "psphot") >= 6) {118 if (psTraceGetLevel(FACILITY) >= 6) { 89 119 p_psImagePrint(psTraceGetDestination(), Alpha, "Alpha guess (1)"); 90 120 p_psVectorPrint(psTraceGetDestination(), Beta, "Beta guess (1)"); 91 121 p_psVectorPrint(psTraceGetDestination(), beta, "beta current (1)"); 92 122 } 93 if (psTraceGetLevel( "psphot") >= 5) {123 if (psTraceGetLevel(FACILITY) >= 5) { 94 124 p_psVectorPrint(psTraceGetDestination(), Params, "params guess (1)"); 95 125 } 96 126 97 127 // calculate Chisq for new guess, update Alpha & Beta 98 Chisq = p sphotModelWithPSF_SetABX(Alpha, Beta, Params, paramMask, pcm, source, psf, func);128 Chisq = pmPCM_SetABX(Alpha, Beta, Params, paramMask, pcm, source); 99 129 if (isnan(Chisq)) { 100 130 min->iter ++; 131 if (min->iter >= min->maxIter) break; 101 132 lambda *= 10.0; 102 133 continue; … … 109 140 psF32 rho = (min->value - Chisq) / dLinear; 110 141 111 psTrace("psphot", 5, "last chisq: %f, new chisq %f, delta: %f, rho: %f\n", min->value, 112 Chisq, min->lastDelta, rho); 142 psTrace(FACILITY, 5, "last chisq: %f, new chisq %f, delta: %f, rho: %f\n", min->value, Chisq, min->lastDelta, rho); 113 143 114 144 // dump some useful info if trace is defined 115 if (psTraceGetLevel( "psphot") >= 6) {145 if (psTraceGetLevel(FACILITY) >= 6) { 116 146 p_psImagePrint(psTraceGetDestination(), Alpha, "alpha guess (2)"); 117 147 p_psVectorPrint(psTraceGetDestination(), Beta, "beta guess (2)"); … … 119 149 120 150 /* if (Chisq < min->value) { */ 121 if (rho > 0.0) {151 if (rho >= -1e-6) { 122 152 min->lastDelta = (min->value - Chisq) / (source->pixels->numCols*source->pixels->numRows - params->n); 123 153 min->value = Chisq; … … 129 159 // save the new convolved model image 130 160 psFree (source->modelFlux); 131 source->modelFlux = pmPCM DataSaveImage(pcm);161 source->modelFlux = pmPCMdataSaveImage(pcm); 132 162 } else { 133 163 lambda *= 10.0; 134 164 } 135 165 min->iter++; 136 } 137 psTrace("psphot", 5, "chisq: %f, last delta: %f, Niter: %d\n", min->value, min->lastDelta, min->iter); 166 167 done = (min->iter >= min->maxIter); 168 169 // check for convergence: 170 float chisqDOF = Chisq / pcm->nDOF; 171 if (!isfinite(min->maxChisqDOF) || ((chisqDOF < min->maxChisqDOF) && isfinite(min->lastDelta))) { 172 done |= (min->lastDelta < min->minTol); 173 } 174 } 175 psTrace(FACILITY, 5, "chisq: %f, last delta: %f, Niter: %d\n", min->value, min->lastDelta, min->iter); 138 176 139 177 // construct & return the covariance matrix (if requested) 140 178 if (covar != NULL) { 141 179 if (!psMinLM_GuessABP(Alpha, Beta, Params, alpha, beta, params, paramMask, NULL, 0.0, NULL)) { 142 psTrace ( "psphot", 5, "failure to calculate covariance matrix\n");180 psTrace (FACILITY, 5, "failure to calculate covariance matrix\n"); 143 181 } 144 182 // set covar values which are not masked … … 164 202 psFree(Beta); 165 203 psFree(Params); 166 psFree(pcm);167 204 168 205 // if the last improvement was at least as good as maxTol, accept the fit: 169 206 if (min->lastDelta <= min->maxTol) { 170 psTrace( "psphot", 6, "---- end (true) ----\n");207 psTrace(FACILITY, 6, "---- end (true) ----\n"); 171 208 return(true); 172 209 } 173 psTrace( "psphot", 6, "---- end (false) ----\n");210 psTrace(FACILITY, 6, "---- end (false) ----\n"); 174 211 return(false); 175 212 } 176 213 177 psF32 p sphotModelWithPSF_SetABX(214 psF32 pmPCM_SetABX( 178 215 psImage *alpha, 179 216 psVector *beta, 180 217 const psVector *params, 181 218 const psVector *paramMask, 182 pmPCMData *pcm, 183 const pmSource *source, 184 const psKernel *psf, 185 psMinimizeLMChi2Func func) 219 pmPCMdata *pcm, 220 const pmSource *source) 186 221 { 187 222 // XXX: Check vector sizes. … … 208 243 psVector *coord = psVectorAlloc(2, PS_TYPE_F32); 209 244 210 psImageInit (pcm->model , 0.0);245 psImageInit (pcm->modelFlux, 0.0); 211 246 for (int n = 0; n < params->n; n++) { 212 if (!pcm->dmodels ->data[n]) continue;213 psImageInit (pcm->dmodels ->data[n], 0.0);247 if (!pcm->dmodelsFlux->data[n]) continue; 248 psImageInit (pcm->dmodelsFlux->data[n], 0.0); 214 249 } 215 250 … … 243 278 coord->data.F32[1] = (psF32) (i + source->pixels->row0); 244 279 245 pcm->model ->data.F32[i][j] = func (deriv, params, coord);280 pcm->modelFlux->data.F32[i][j] = pcm->modelConv->modelFunc (deriv, params, coord); 246 281 247 282 for (int n = 0; n < params->n; n++) { 248 283 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 249 psImage *dmodel = pcm->dmodels ->data[n];284 psImage *dmodel = pcm->dmodelsFlux->data[n]; 250 285 dmodel->data.F32[i][j] = deriv->data.F32[n]; 251 286 } … … 256 291 257 292 // convolve model and dmodel arrays with PSF 258 psImageConvolveDirect (pcm->modelConv , pcm->model,psf);259 for (int n = 0; n < pcm->dmodels ->n; n++) {260 if (pcm->dmodels ->data[n] == NULL) continue;261 psImage *dmodel = pcm->dmodels ->data[n];262 psImage *dmodelConv = pcm->dmodelsConv ->data[n];263 psImageConvolveDirect (dmodelConv, dmodel, p sf);293 psImageConvolveDirect (pcm->modelConvFlux, pcm->modelFlux, pcm->psf); 294 for (int n = 0; n < pcm->dmodelsFlux->n; n++) { 295 if (pcm->dmodelsFlux->data[n] == NULL) continue; 296 psImage *dmodel = pcm->dmodelsFlux->data[n]; 297 psImage *dmodelConv = pcm->dmodelsConvFlux->data[n]; 298 psImageConvolveDirect (dmodelConv, dmodel, pcm->psf); 264 299 } 265 300 266 301 // XXX TEST : SAVE IMAGES 267 302 # if (SAVE_IMAGES) 268 psphotSaveImage (NULL, p sf->image, "psf.fits");269 psphotSaveImage (NULL, pcm->model , "model.fits");270 psphotSaveImage (NULL, pcm->modelConv , "modelConv.fits");303 psphotSaveImage (NULL, pcm->psf->image, "psf.fits"); 304 psphotSaveImage (NULL, pcm->modelFlux, "model.fits"); 305 psphotSaveImage (NULL, pcm->modelConvFlux, "modelConv.fits"); 271 306 psphotSaveImage (NULL, source->pixels, "obj.fits"); 272 307 psphotSaveImage (NULL, source->maskObj, "mask.fits"); … … 297 332 } 298 333 299 float ymodel = pcm->modelConv ->data.F32[i][j];334 float ymodel = pcm->modelConvFlux->data.F32[i][j]; 300 335 float yweight = 1.0 / source->variance->data.F32[i][j]; 301 336 float delta = ymodel - source->pixels->data.F32[i][j]; … … 309 344 for (int n1 = 0, N1 = 0; n1 < params->n; n1++) { 310 345 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n1])) continue; 311 psImage *dmodel = pcm->dmodelsConv ->data[n1];346 psImage *dmodel = pcm->dmodelsConvFlux->data[n1]; 312 347 float weight = dmodel->data.F32[i][j] * yweight; 313 348 for (int n2 = 0, N2 = 0; n2 <= n1; n2++) { 314 349 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n2])) continue; 315 dmodel = pcm->dmodelsConv ->data[n2];350 dmodel = pcm->dmodelsConvFlux->data[n2]; 316 351 alpha->data.F32[N1][N2] += weight * dmodel->data.F32[i][j]; 317 352 N2++; -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmPCMdata.c
r28687 r28692 1 static void pmPCMDataFree (pmPCMData *pcm) { 1 /* @file pmPCMdata.c 2 * structures and functions to support PSF-convolved model fitting 3 * 4 * @author EAM, IfA 5 * 6 * @version $Revision: 1.29 $ 7 * @date $Date: 2009-02-16 22:30:50 $ 8 * Copyright 2010 Institute for Astronomy, University of Hawaii 9 */ 10 11 #ifdef HAVE_CONFIG_H 12 #include <config.h> 13 #endif 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include <strings.h> 19 #include <pslib.h> 20 #include "pmHDU.h" 21 #include "pmFPA.h" 22 #include "pmFPAMaskWeight.h" 23 24 #include "pmTrend2D.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmSpan.h" 28 #include "pmFootprintSpans.h" 29 #include "pmFootprint.h" 30 #include "pmPeaks.h" 31 #include "pmMoments.h" 32 #include "pmModelFuncs.h" 33 #include "pmModel.h" 34 #include "pmModelUtils.h" 35 #include "pmModelClass.h" 36 #include "pmSourceMasks.h" 37 #include "pmSourceExtendedPars.h" 38 #include "pmSourceDiffStats.h" 39 #include "pmSource.h" 40 #include "pmSourceFitModel.h" 41 #include "pmPCMdata.h" 42 43 static void pmPCMdataFree (pmPCMdata *pcm) { 2 44 3 45 if (pcm == NULL) return; 4 46 5 psFree (pcm->model); 47 psFree (pcm->modelFlux); 48 psFree (pcm->modelConvFlux); 49 psFree (pcm->dmodelsFlux); 50 psFree (pcm->dmodelsConvFlux); 51 6 52 psFree (pcm->modelConv); 7 psFree (pcm-> dmodels);8 psFree (pcm-> dmodelsConv);53 psFree (pcm->psf); 54 psFree (pcm->constraint); 9 55 return; 10 56 } 11 57 12 pmPCM Data *pmPCMDataAlloc (58 pmPCMdata *pmPCMdataAlloc ( 13 59 const psVector *params, 14 60 const psVector *paramMask, 15 61 pmSource *source) { 16 62 17 pmPCM Data *pcm = (pmPCMData *) psAlloc(sizeof(pmPCMData));18 psMemSetDeallocator(pcm, (psFreeFunc) pmPCM DataFree);63 pmPCMdata *pcm = (pmPCMdata *) psAlloc(sizeof(pmPCMdata)); 64 psMemSetDeallocator(pcm, (psFreeFunc) pmPCMdataFree); 19 65 20 66 // Allocate storage images for raw model and derivative images 21 pcm->model = psImageCopy (NULL, source->pixels, PS_TYPE_F32);22 pcm->dmodels = psArrayAlloc (params->n);67 pcm->modelFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 68 pcm->dmodelsFlux = psArrayAlloc (params->n); 23 69 for (psS32 n = 0; n < params->n; n++) { 24 pcm->dmodels ->data[n] = NULL;70 pcm->dmodelsFlux->data[n] = NULL; 25 71 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 26 pcm->dmodels ->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32);72 pcm->dmodelsFlux->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 27 73 } 28 74 29 75 // Allocate storage images for convolved model and derivative images 30 pcm->modelConv = psImageCopy (NULL, source->pixels, PS_TYPE_F32);31 pcm->dmodelsConv = psArrayAlloc (params->n);76 pcm->modelConvFlux = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 77 pcm->dmodelsConvFlux = psArrayAlloc (params->n); 32 78 for (psS32 n = 0; n < params->n; n++) { 33 pcm->dmodelsConv ->data[n] = NULL;79 pcm->dmodelsConvFlux->data[n] = NULL; 34 80 if ((paramMask != NULL) && (paramMask->data.PS_TYPE_VECTOR_MASK_DATA[n])) { continue; } 35 pcm->dmodelsConv->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 36 } 81 pcm->dmodelsConvFlux->data[n] = psImageCopy (NULL, source->pixels, PS_TYPE_F32); 82 } 83 84 pcm->modelConv = NULL; 85 pcm->psf = NULL; 86 pcm->constraint = NULL; 87 pcm->nDOF = 0; 37 88 38 89 return pcm; 39 90 } 40 91 41 psImage *pmPCM DataSaveImage (pmPCMData *pcm) {42 43 psImage *model = psImageCopy (NULL, pcm->modelConv , PS_TYPE_F32);92 psImage *pmPCMdataSaveImage (pmPCMdata *pcm) { 93 94 psImage *model = psImageCopy (NULL, pcm->modelConvFlux, PS_TYPE_F32); 44 95 45 96 return model; 46 97 } 47 98 99 psKernel *pmPCMkernelFromPSF (pmSource *source, int nPix) { 100 101 assert (source); 102 assert (source->psfImage); // XXX build if needed? 103 104 int x0 = source->peak->xf - source->psfImage->col0; 105 int y0 = source->peak->yf - source->psfImage->row0; 106 107 // need to decide on the size: dynamically? statically? 108 psKernel *psf = psKernelAlloc (-nPix, +nPix, -nPix, +nPix); 109 110 // XXX we should just re-construct a PSF at this location 111 // psModelAdd (psf->image, NULL, source->modelPSF, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM | PM_MODEL_OP_CENTER); 112 113 // if the realized PSF for this object does not cover the full kernel, give up for now 114 if (x0 + psf->xMin < 0) goto escape; 115 if (x0 + psf->xMax >= source->psfImage->numCols) goto escape; 116 if (y0 + psf->yMin < 0) goto escape; 117 if (y0 + psf->yMax >= source->psfImage->numRows) goto escape; 118 119 double sum = 0.0; 120 for (int j = psf->yMin; j <= psf->yMax; j++) { 121 for (int i = psf->xMin; i <= psf->xMax; i++) { 122 double value = source->psfImage->data.F32[y0 + j][x0 + i]; 123 psf->kernel[j][i] = value; 124 sum += value; 125 } 126 } 127 assert (sum > 0.0); 128 129 // psf must be normalized (integral = 1.0) 130 for (int i = 0; i < psf->image->numRows; i++) { 131 for (int j = 0; j < psf->image->numCols; j++) { 132 psf->image->data.F32[i][j] /= sum; 133 } 134 } 135 136 return psf; 137 138 escape: 139 psFree (psf); 140 return NULL; 141 } 142 143 pmPCMdata *pmPCMinit(pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, float psfSize) { 144 145 // make sure we savep a cached copy of the psf flux 146 pmSourceCachePSF (source, maskVal); 147 148 // convert the cached cached psf model for this source to a psKernel 149 psKernel *psf = pmPCMkernelFromPSF (source, psfSize); 150 if (!psf) return NULL; 151 152 # if (USE_DELTA_PSF) 153 psImageInit (psf->image, 0.0); 154 psf->image->data.F32[(int)(0.5*psf->image->numRows)][(int)(0.5*psf->image->numCols)] = 1.0; 155 # endif 156 157 // allocate the model 158 pmModel *modelConv = pmModelAlloc(modelType); 159 if (!modelConv) { 160 psFree (psf); 161 return NULL; 162 } 163 164 // count the number of unmasked pixels: 165 int nPix = 0; 166 for (psS32 i = 0; i < source->pixels->numRows; i++) { 167 for (psS32 j = 0; j < source->pixels->numCols; j++) { 168 // XXX are we doing the right thing with the mask? 169 // skip masked points 170 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[i][j]) { 171 continue; 172 } 173 // skip zero-variance points 174 if (source->variance->data.F32[i][j] == 0) { 175 continue; 176 } 177 // skip nan value points 178 if (!isfinite(source->pixels->data.F32[i][j])) { 179 continue; 180 } 181 nPix ++; 182 } 183 } 184 185 psVector *params = modelConv->params; 186 187 // create the minimization constraints 188 psMinConstraint *constraint = psMinConstraintAlloc(); 189 constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK); 190 constraint->checkLimits = modelConv->modelLimits; 191 192 // set parameter mask based on fitting mode 193 int nParams = 0; 194 switch (fitOptions->mode) { 195 case PM_SOURCE_FIT_NORM: 196 // NORM-only model fits only source normalization (Io) 197 nParams = 1; 198 psVectorInit (constraint->paramMask, 1); 199 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 200 break; 201 case PM_SOURCE_FIT_PSF: 202 // PSF model only fits x,y,Io 203 nParams = 3; 204 psVectorInit (constraint->paramMask, 1); 205 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 206 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_XPOS] = 0; 207 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_YPOS] = 0; 208 break; 209 case PM_SOURCE_FIT_EXT: 210 // EXT model fits all params (except sky) 211 nParams = params->n - 1; 212 psVectorInit (constraint->paramMask, 0); 213 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 214 break; 215 case PM_SOURCE_FIT_INDEX: 216 // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params 217 psVectorInit (constraint->paramMask, 1); 218 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_I0] = 0; 219 if (params->n == 7) { 220 nParams = 1; 221 } else { 222 nParams = 2; 223 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 0; 224 } 225 break; 226 case PM_SOURCE_FIT_NO_INDEX: 227 // PSF model only fits Io, index (PAR7) -- only Io for models with < 8 params 228 psVectorInit (constraint->paramMask, 0); 229 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 230 if (params->n == 7) { 231 nParams = params->n - 1; 232 } else { 233 nParams = params->n - 2; 234 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_7] = 1; 235 } 236 break; 237 default: 238 psAbort("invalid fitting mode"); 239 } 240 241 // generate PCM data storage structure 242 pmPCMdata *pcm = pmPCMdataAlloc (params, constraint->paramMask, source); 243 244 pcm->modelConv = modelConv; 245 pcm->psf = psf; 246 pcm->constraint = constraint; 247 248 if (nPix < nParams + 1) { 249 psTrace ("psModules.objects", 4, "insufficient valid pixels\n"); 250 pcm->modelConv->flags |= PM_MODEL_STATUS_BADARGS; 251 abort (); 252 // XXX This should not be an abort!! 253 } 254 pcm->nPix = nPix; 255 pcm->nDOF = nPix - nParams - 1; 256 257 return pcm; 258 } -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmPSFtryFitPSF.c
r28643 r28692 108 108 109 109 // This function calculates the psf and aperture magnitudes 110 status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal ); // raw PSF mag, AP mag110 status = pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal, markVal); // raw PSF mag, AP mag 111 111 if (!status || isnan(source->apMag)) { 112 112 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); // clear the circular mask -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourceFitPCM.c
r28687 r28692 1 # include "psphotInternal.h" 2 # define USE_DELTA_PSF 0 1 /* @file pmSourceFitPCM.c 2 * structures and functions to support PSF-convolved model fitting 3 * 4 * @author EAM, IfA 5 * 6 * @version $Revision: 1.29 $ 7 * @date $Date: 2009-02-16 22:30:50 $ 8 * Copyright 2010 Institute for Astronomy, University of Hawaii 9 */ 3 10 4 // save as static values so they may be set externally 5 static psF32 PM_SOURCE_FIT_MODEL_NUM_ITERATIONS = 15; 6 static psF32 PM_SOURCE_FIT_MODEL_MIN_TOL = 0.1; 7 static psF32 PM_SOURCE_FIT_MODEL_MAX_TOL = 2.0; 11 #ifdef HAVE_CONFIG_H 12 #include <config.h> 13 #endif 14 15 #include <stdio.h> 16 #include <math.h> 17 #include <string.h> 18 #include <strings.h> 19 #include <pslib.h> 20 #include "pmHDU.h" 21 #include "pmFPA.h" 22 #include "pmFPAMaskWeight.h" 23 24 #include "pmTrend2D.h" 25 #include "pmResiduals.h" 26 #include "pmGrowthCurve.h" 27 #include "pmSpan.h" 28 #include "pmFootprintSpans.h" 29 #include "pmFootprint.h" 30 #include "pmPeaks.h" 31 #include "pmMoments.h" 32 #include "pmModelFuncs.h" 33 #include "pmModel.h" 34 #include "pmModelUtils.h" 35 #include "pmModelClass.h" 36 #include "pmSourceMasks.h" 37 #include "pmSourceExtendedPars.h" 38 #include "pmSourceDiffStats.h" 39 #include "pmSource.h" 40 #include "pmSourceFitModel.h" 41 #include "pmPCMdata.h" 42 43 # define FACILITY "psModules.objects" 8 44 9 45 // input source has both modelPSF and modelEXT. on successful exit, we set the … … 11 47 // convolved model image. 12 48 13 // XXX need to generalize this -- number of fitted parameters must be flexible based on the fitOptions 14 15 pmModel *psphotPSFConvModel (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 49 bool pmSourceFitPCM (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 16 50 17 // maskVal is used to test for rejected pixels, and must include markVal 18 maskVal |= markVal; 19 20 // make sure we save a cached copy of the psf flux 21 pmSourceCachePSF (source, maskVal); 22 23 // convert the cached cached psf model for this source to a psKernel 24 psKernel *psf = psphotKernelFromPSF (source, psfSize); 25 if (!psf) return NULL; 26 27 # if (USE_DELTA_PSF) 28 psImageInit (psf->image, 0.0); 29 psf->image->data.F32[(int)(0.5*psf->image->numRows)][(int)(0.5*psf->image->numCols)] = 1.0; 30 # endif 31 32 // generate copy of the model 33 // XXX we could modify the parameter values or even the model 34 // here based on the observed seeing (some lookup table...) 35 36 // use the source moments, etc to guess basic model parameters 37 pmModel *modelConv = pmSourceModelGuess (source, modelType); 38 if (!modelConv) { 39 psFree (psf); 40 return NULL; 41 } 42 43 // adjust the pixels based on the footprint 44 float radius = psphotSetRadiusEXT (readout, source, markVal); 45 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false; 46 47 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 48 psEllipseShape psfShape; 49 psfShape.sx = source->modelPSF->params->data.F32[PM_PAR_SXX] / M_SQRT2; 50 psfShape.sxy = source->modelPSF->params->data.F32[PM_PAR_SXY]; 51 psfShape.sy = source->modelPSF->params->data.F32[PM_PAR_SYY] / M_SQRT2; 52 psEllipseAxes psfAxes = psEllipseShapeToAxes (psfShape, 20.0); 53 54 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 55 psEllipseShape extShape; 56 extShape.sx = modelConv->params->data.F32[PM_PAR_SXX] / M_SQRT2; 57 extShape.sxy = modelConv->params->data.F32[PM_PAR_SXY]; 58 extShape.sy = modelConv->params->data.F32[PM_PAR_SYY] / M_SQRT2; 59 psEllipseAxes extAxes = psEllipseShapeToAxes (extShape, 20.0); 60 61 // decrease the initial guess ellipse by psf_minor axis: 62 psEllipseAxes extAxesMod; 63 extAxesMod.major = sqrt (PS_MAX (1.0, PS_SQR(extAxes.major) - PS_SQR(psfAxes.minor))); 64 extAxesMod.minor = sqrt (PS_MAX (1.0, PS_SQR(extAxes.minor) - PS_SQR(psfAxes.minor))); 65 extAxesMod.theta = extAxes.theta; 66 67 psEllipseShape extShapeMod = psEllipseAxesToShape (extAxesMod); 68 modelConv->params->data.F32[PM_PAR_SXX] = extShapeMod.sx * M_SQRT2; 69 modelConv->params->data.F32[PM_PAR_SXY] = extShapeMod.sxy; 70 modelConv->params->data.F32[PM_PAR_SYY] = extShapeMod.sy * M_SQRT2; 71 72 // increase the initial guess central intensity by 2pi r^2: 73 modelConv->params->data.F32[PM_PAR_I0] *= (1.0 + PS_SQR(psfAxes.minor) / PS_SQR(extAxesMod.minor)); 74 75 psVector *params = modelConv->params; 76 psVector *dparams = modelConv->dparams; 77 78 // create the minimization constraints 79 psMinConstraint *constraint = psMinConstraintAlloc(); 80 constraint->paramMask = psVectorAlloc (params->n, PS_TYPE_VECTOR_MASK); 81 constraint->checkLimits = modelConv->modelLimits; 82 83 // set parameter mask based on fitting mode 84 // we fit a model without a floating sky term 85 int nParams = params->n - 1; 86 psVectorInit (constraint->paramMask, 0); 87 constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[PM_PAR_SKY] = 1; 51 psVector *params = pcm->modelConv->params; 52 psVector *dparams = pcm->modelConv->dparams; 88 53 89 54 // force the floating parameters to fall within the contraint ranges 90 55 for (int i = 0; i < params->n; i++) { 91 modelConv->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL);92 modelConv->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL);56 pcm->modelConv->modelLimits (PS_MINIMIZE_PARAM_MIN, i, params->data.F32, NULL); 57 pcm->modelConv->modelLimits (PS_MINIMIZE_PARAM_MAX, i, params->data.F32, NULL); 93 58 } 94 59 95 60 // set up the minimization process 96 psMinimization *myMin = psMinimizationAlloc ( PM_SOURCE_FIT_MODEL_NUM_ITERATIONS, PM_SOURCE_FIT_MODEL_MIN_TOL, PM_SOURCE_FIT_MODEL_MAX_TOL);61 psMinimization *myMin = psMinimizationAlloc (fitOptions->nIter, fitOptions->minTol, fitOptions->maxTol); 97 62 98 63 psImage *covar = psImageAlloc (params->n, params->n, PS_TYPE_F32); 99 64 100 bool fitStatus = p sphotModelWithPSF_LMM (myMin, covar, params, constraint, source, psf, modelConv->modelFunc);65 bool fitStatus = pmPCM_MinimizeChisq (myMin, covar, params, source, pcm); 101 66 for (int i = 0; i < dparams->n; i++) { 102 if (psTraceGetLevel("psphot") >= 4) { 103 fprintf (stderr, "%f ", params->data.F32[i]); 104 } 105 if ((constraint->paramMask != NULL) && constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) 67 if ((pcm->constraint->paramMask != NULL) && pcm->constraint->paramMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) 106 68 continue; 107 69 dparams->data.F32[i] = sqrt(covar->data.F32[i][i]); 70 psTrace ("psModules.objects", 4, "%f +/- %f", params->data.F32[i], dparams->data.F32[i]); 108 71 } 109 72 psTrace ("psphot", 4, "niter: %d, chisq: %f", myMin->iter, myMin->value); … … 118 81 119 82 // save the resulting chisq, nDOF, nIter 120 modelConv->chisq = myMin->value; 121 modelConv->nIter = myMin->iter; 122 123 // XXX I actually need to count the number of unmasked pixels here 124 modelConv->nDOF = source->pixels->numCols*source->pixels->numRows - nParams; 125 126 modelConv->flags |= PM_MODEL_STATUS_FITTED; 127 if (!fitStatus) modelConv->flags |= PM_MODEL_STATUS_NONCONVERGE; 83 pcm->modelConv->chisq = myMin->value; 84 pcm->modelConv->nIter = myMin->iter; 85 pcm->modelConv->nPix = pcm->nPix; 86 pcm->modelConv->nDOF = pcm->nDOF; 87 pcm->modelConv->chisqNorm = pcm->modelConv->chisq / pcm->modelConv->nDOF; 88 pcm->modelConv->flags |= PM_MODEL_STATUS_FITTED; 89 if (!fitStatus) pcm->modelConv->flags |= PM_MODEL_STATUS_NONCONVERGE; 128 90 129 91 // models can go insane: reject these … … 133 95 onPic &= (params->data.F32[PM_PAR_YPOS] >= source->pixels->row0); 134 96 onPic &= (params->data.F32[PM_PAR_YPOS] < source->pixels->row0 + source->pixels->numRows); 135 if (!onPic) modelConv->flags |= PM_MODEL_STATUS_OFFIMAGE;97 if (!onPic) pcm->modelConv->flags |= PM_MODEL_STATUS_OFFIMAGE; 136 98 137 99 source->mode |= PM_SOURCE_MODE_FITTED; // XXX is this needed? 138 100 139 psFree(psf);140 101 psFree(myMin); 141 102 psFree(covar); 142 psFree(constraint);143 103 144 return modelConv;104 return true; 145 105 } 106 107 bool pmSourceModelGuessPCM (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal) { 108 109 pcm->modelConv->modelGuess(pcm->modelConv, source); 110 111 // generate copy of the model 112 // XXX we could modify the parameter values or even the model 113 // here based on the observed seeing (some lookup table...) 114 115 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 116 psEllipseShape psfShape; 117 psfShape.sx = source->modelPSF->params->data.F32[PM_PAR_SXX] / M_SQRT2; 118 psfShape.sxy = source->modelPSF->params->data.F32[PM_PAR_SXY]; 119 psfShape.sy = source->modelPSF->params->data.F32[PM_PAR_SYY] / M_SQRT2; 120 psEllipseAxes psfAxes = psEllipseShapeToAxes (psfShape, 20.0); 121 122 // XXX test : modify the Io, SXX, SYY terms based on the psf SXX, SYY terms: 123 psEllipseShape extShape; 124 extShape.sx = pcm->modelConv->params->data.F32[PM_PAR_SXX] / M_SQRT2; 125 extShape.sxy = pcm->modelConv->params->data.F32[PM_PAR_SXY]; 126 extShape.sy = pcm->modelConv->params->data.F32[PM_PAR_SYY] / M_SQRT2; 127 psEllipseAxes extAxes = psEllipseShapeToAxes (extShape, 20.0); 128 129 // decrease the initial guess ellipse by psf_minor axis: 130 psEllipseAxes extAxesMod; 131 extAxesMod.major = sqrt (PS_MAX (1.0, PS_SQR(extAxes.major) - PS_SQR(psfAxes.minor))); 132 extAxesMod.minor = sqrt (PS_MAX (1.0, PS_SQR(extAxes.minor) - PS_SQR(psfAxes.minor))); 133 extAxesMod.theta = extAxes.theta; 134 135 psEllipseShape extShapeMod = psEllipseAxesToShape (extAxesMod); 136 pcm->modelConv->params->data.F32[PM_PAR_SXX] = extShapeMod.sx * M_SQRT2; 137 pcm->modelConv->params->data.F32[PM_PAR_SXY] = extShapeMod.sxy; 138 pcm->modelConv->params->data.F32[PM_PAR_SYY] = extShapeMod.sy * M_SQRT2; 139 140 // increase the initial guess central intensity by 2pi r^2: 141 pcm->modelConv->params->data.F32[PM_PAR_I0] *= (1.0 + PS_SQR(psfAxes.minor) / PS_SQR(extAxesMod.minor)); 142 143 return true; 144 } -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.c
r28687 r28692 76 76 77 77 // XXX masked region should be (optionally) elliptical 78 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal )78 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal) 79 79 { 80 80 PS_ASSERT_PTR_NON_NULL(source, false); … … 160 160 // measure the contribution of included pixels 161 161 if (mode & PM_SOURCE_PHOT_DIFFSTATS) { 162 pmSourceMeasureDiffStats (source, maskVal );162 pmSourceMeasureDiffStats (source, maskVal, markVal); 163 163 } 164 164 -
branches/eam_branches/ipp-20100621/psModules/src/objects/pmSourcePhotometry.h
r28440 r28692 52 52 53 53 bool pmSourceMagnitudesInit (psMetadata *config); 54 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal );54 bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psImageMaskType maskVal, psImageMaskType markVal); 55 55 bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *mask, psImageMaskType maskVal); 56 56 bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psImageMaskType maskVal, const float covarFactor); 57 57 58 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal );58 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal); 59 59 60 60 double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal); -
branches/eam_branches/ipp-20100621/psModules/src/psmodules.h
r28643 r28692 149 149 #include <pmSourceMatch.h> 150 150 #include <pmDetEff.h> 151 #include <pmPCMdata.h> 151 152 152 153 // The following headers are from random locations, here because they cross bounds -
branches/eam_branches/ipp-20100621/psphot/src/Makefile.am
r28683 r28692 168 168 psphotExtendedSourceFits.c \ 169 169 psphotKernelFromPSF.c \ 170 psphotPSFConvModel.c \171 170 psphotFitSet.c \ 172 171 psphotSourceFreePixels.c \ -
branches/eam_branches/ipp-20100621/psphot/src/psphot.h
r28643 r28692 12 12 13 13 #define PSPHOT_RECIPE_PSF_FAKE_ALLOW "PSF.FAKE.ALLOW" // Name for recipe component permitting fake PSFs 14 15 // pmPCMData : PSF Convolved Model data storage structure16 typedef struct {17 psImage *model;18 psArray *dmodels;19 psImage *modelConv;20 psArray *dmodelsConv;21 } pmPCMData;22 14 23 15 // top-level psphot functions … … 293 285 bool psphotRadialBins (psMetadata *recipe, pmSource *source, float radiusMax, float skynoise); 294 286 295 // structures & functions to support psf-convolved model fitting296 297 // psf-convolved model fitting298 bool psphotModelWithPSF_LMM (299 psMinimization *min,300 psImage *covar,301 psVector *params,302 psMinConstraint *constraint,303 pmSource *source,304 const psKernel *psf,305 psMinimizeLMChi2Func func);306 307 psF32 psphotModelWithPSF_SetABX(308 psImage *alpha,309 psVector *beta,310 const psVector *params,311 const psVector *paramMask,312 pmPCMData *pcm,313 const pmSource *source,314 const psKernel *psf,315 psMinimizeLMChi2Func func);316 317 pmPCMData *pmPCMDataAlloc (318 const psVector *params,319 const psVector *paramMask,320 pmSource *source);321 322 psImage *pmPCMDataSaveImage (pmPCMData *pcm);323 324 287 int psphotKapaOpen (void); 325 288 bool psphotKapaClose (void); … … 463 426 bool psphotStackObjectsUnifyPosition (psArray *objects); 464 427 428 bool psphotFitSersicIndexPCM (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal); 429 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize); 430 465 431 #endif -
branches/eam_branches/ipp-20100621/psphot/src/psphotApResid.c
r28405 r28692 459 459 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal); 460 460 461 bool status = pmSourceMagnitudes (source, psf, photMode, maskVal );461 bool status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 462 462 463 463 // clear the mask bit -
branches/eam_branches/ipp-20100621/psphot/src/psphotMagnitudes.c
r28405 r28692 186 186 psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, source->apRadius, "OR", markVal); 187 187 188 status = pmSourceMagnitudes (source, psf, photMode, maskVal ); // maskVal includes markVal188 status = pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 189 189 if (status && isfinite(source->apMag)) Nap ++; 190 190 -
branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c
r28687 r28692 8 8 static int NfitDBL = 0; 9 9 static int NfitEXT = 0; 10 static int NfitPCM = 0; 10 11 11 12 bool psphotFitInit (int nThreads) { … … 440 441 pmModel *psphotFitEXT (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) { 441 442 443 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 444 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 445 } 446 442 447 pmSourceFitOptions options = *fitOptions; 443 448 … … 456 461 } 457 462 458 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) {459 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy);460 }461 462 463 // for sersic models, use a grid search to choose an index, then float the params there 463 464 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { … … 476 477 } 477 478 478 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal) { 479 pmModel *psphotFitPCM (pmReadout *readout, pmSource *source, pmSourceFitOptions *fitOptions, pmModelType modelType, psImageMaskType maskVal, psImageMaskType markVal, int psfSize) { 480 481 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 482 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 483 } 484 485 float radius = psphotSetRadiusEXT (readout, source, markVal); 486 487 // XXX note that this changes the source moments that are published... 488 // recalculate the source moments using the larger extended-source moments radius 489 // at this stage, skip Gaussian windowing, and do not clip pixels by S/N 490 // this uses the footprint to judge both radius and aperture? 491 if (!pmSourceMoments (source, radius, 0.0, 0.0, maskVal)) return false; 479 492 480 493 pmSourceFitOptions options = *fitOptions; … … 487 500 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5); 488 501 489 // use the source moments, etc to guess basic model parameters 490 pmModel *EXT = pmSourceModelGuess (source, modelType); 491 if (!EXT) { 502 pmPCMdata *pcm = pmPCMinit (source, &options, modelType, maskVal, psfSize); 503 if (!pcm) { 492 504 psTrace ("psphot", 5, "failed to generate a model for source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy); 493 505 return NULL; 494 506 } 495 496 if ((source->moments->Mxx < 1e-3) || (source->moments->Myy < 1e-3)) { 497 psTrace ("psphot", 5, "problem source: moments: %f %f\n", source->moments->Mxx, source->moments->Myy);498 }507 // XXX check for nDOF too small 508 509 // use the source moments, etc to guess basic model parameters 510 pmSourceModelGuessPCM (pcm, source, maskVal, markVal); 499 511 500 512 // for sersic models, use a grid search to choose an index, then float the params there 501 513 if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) { 502 psphotFitSersicIndexPCM ( source, EXT, fitOptions, maskVal);514 psphotFitSersicIndexPCM (pcm, source, fitOptions, maskVal, markVal); 503 515 } 504 516 … … 508 520 options.mode = PM_SOURCE_FIT_EXT; 509 521 } 510 pmSourceFitPCM (source, EXT, &options, maskVal);522 pmSourceFitPCM (source, PCM, &options, maskVal); 511 523 512 524 // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0); 513 return ( EXT);525 return (PCM); 514 526 } 515 527 … … 520 532 // A sersic model is very sensitive to the index. attempt to find the index first by grid search in just the index 521 533 // for a sersic model, attempt to fit just the index and normalization with a modest number of iterations 522 bool psphotFitSersicIndex (pmSource *source, pmModel *model, pmSourceFitOptions *fitOptions, psImageMaskType maskVal) { 534 bool psphotFitSersicIndex (pmPCMdata *pcm, pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, psImageMaskType markVal) { 535 536 pmModel *model = pcm->modelConv; 523 537 524 538 assert (model->type == pmModelClassGetType("PS_MODEL_SERSIC")); … … 535 549 for (int i = 0; i < N_INDEX_GUESS; i++) { 536 550 model->params->data.F32[PM_PAR_7] = indexGuess[i]; 537 model->modelGuess(model, source); 538 pmSourceFitModel (source, model, &options, maskVal); 551 pmSourceModelGuessPCM (pcm, source, maskVal, markVal); 552 553 pmSourceFitPCM (pcm, source, &options, maskVal); 539 554 chiSquare[i] = model->chisq; 540 555 if (i == 0) { … … 570 585 float xMin, chiSquare[N_INDEX_GUESS]; 571 586 int iMin; 587 588 // XXX we probably cannot be calling model->modelGuess() : this does not include the psf sigma 572 589 573 590 for (int i = 0; i < N_INDEX_GUESS; i++) { -
branches/eam_branches/ipp-20100621/psphot/src/psphotSourceSize.c
r28677 r28692 191 191 192 192 // XXX can we test if psfMag is set and calculate only if needed? 193 pmSourceMagnitudes (source, psf, photMode, maskVal ); // maskVal includes markVal193 pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 194 194 195 195 // clear the mask bit … … 342 342 343 343 // XXX can we test if psfMag is set and calculate only if needed? 344 pmSourceMagnitudes (source, psf, photMode, maskVal ); // maskVal includes markVal344 pmSourceMagnitudes (source, psf, photMode, maskVal, markVal); 345 345 346 346 // clear the mask bit
Note:
See TracChangeset
for help on using the changeset viewer.
