- Timestamp:
- Sep 24, 2013, 12:09:27 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130904/psphot/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
psphotGalaxyShape.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130904/psphot/src
- Property svn:ignore
-
old new 24 24 psphotModelTest 25 25 psphotMinimal 26 psphotFullForce
-
- Property svn:ignore
-
branches/eam_branches/ipp-20130904/psphot/src/psphotGalaxyShape.c
r36146 r36148 1 1 # include "psphotInternal.h" 2 2 3 bool psphotGalaxyShape (pmConfig *config, const pmFPAview *view, const char *filerule , int pass)3 bool psphotGalaxyShape (pmConfig *config, const pmFPAview *view, const char *filerule) 4 4 { 5 5 bool status = true; … … 38 38 // psAssert (psf, "missing psf?"); 39 39 40 if (!psphotGalaxyShapeReadout (config, recipe, view, filerule, readout, sources, psf , i, pass)) {40 if (!psphotGalaxyShapeReadout (config, recipe, view, filerule, readout, sources, psf)) { 41 41 psError (PSPHOT_ERR_CONFIG, false, "failed to measure magnitudes for %s entry %d", filerule, i); 42 42 return false; … … 46 46 } 47 47 48 bool psphotGalaxyShapeReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf , int index, int pass) {48 bool psphotGalaxyShapeReadout(pmConfig *config, psMetadata *recipe, const pmFPAview *view, const char * filerule, pmReadout *readout, psArray *sources, pmPSF *psf) { 49 49 50 50 bool status = false; … … 55 55 } 56 56 57 psTimerStart ("psphot. kron");57 psTimerStart ("psphot.galaxy"); 58 58 59 59 // determine the number of allowed threads … … 63 63 } 64 64 65 bool KRON_APPLY_WEIGHT = psMetadataLookupBool (&status, recipe, "KRON_APPLY_WEIGHT");66 if (!status) {67 KRON_APPLY_WEIGHT = true;68 }69 70 bool KRON_APPLY_WINDOW = psMetadataLookupBool (&status, recipe, "KRON_APPLY_WINDOW");71 if (!status) {72 KRON_APPLY_WINDOW = false;73 }74 75 65 // bit-masks to test for good/bad pixels 76 66 psImageMaskType maskVal = psMetadataLookupImageMask(&status, recipe, "MASK.PSPHOT"); … … 83 73 // maskVal is used to test for rejected pixels, and must include markVal 84 74 maskVal |= markVal; 75 76 // what fraction of the PSF is used? (radius in pixels : 2 -> 5x5 box) 77 int psfSize = psMetadataLookupS32 (&status, recipe, "PCM_BOX_SIZE"); 78 assert (status); 79 80 // source fitting parameters for extended source fits 81 int fitIter = psMetadataLookupS32(&status, recipe, "EXT_FIT_ITER"); // Max number of fit iterations 82 assert (status && fitIter > 0); 83 84 float fitMinTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MIN_TOL"); // Fit tolerance 85 if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) { 86 fitMinTol = psMetadataLookupF32 (&status, recipe, "PSF_FIT_TOL"); // Fit tolerance 87 if (!status || !isfinite(fitMinTol) || fitMinTol <= 0) { 88 psAbort("PSF_FIT_MIN_TOL (and PSF_FIT_TOL) not defined or positive"); 89 } 90 } 91 92 float fitMaxTol = psMetadataLookupF32 (&status, recipe, "EXT_FIT_MAX_TOL"); // Fit tolerance 93 if (!status || !isfinite(fitMaxTol) || fitMaxTol <= 0) { 94 fitMaxTol = 1.0; 95 } 96 97 bool chisqConvergence = psMetadataLookupBool (&status, recipe, "LMM_FIT_CHISQ_CONVERGENCE"); // Fit tolerance 98 if (!status) { 99 // default to the old method (chisqConvergence) 100 chisqConvergence = true; 101 } 102 103 int gainFactorMode = psMetadataLookupS32 (&status, recipe, "LMM_FIT_GAIN_FACTOR_MODE"); // Fit tolerance 104 if (!status) { 105 // default to the old method (chisqConvergence) 106 gainFactorMode = 0; 107 } 108 109 // perform full extended source non-linear fits? 110 bool isInteractive = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_FITS_INTERACTIVE"); 111 if (!status) isInteractive = false; 112 113 // Define source fitting parameters for extended source fits 114 pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc(); 115 fitOptions->mode = PM_SOURCE_FIT_EXT_AND_SKY; 116 fitOptions->saveCovariance = true; // XXX make this a user option? 117 fitOptions->covarFactor = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix 118 fitOptions->nIter = fitIter; 119 fitOptions->minTol = fitMinTol; 120 fitOptions->maxTol = fitMaxTol; 121 122 fitOptions->gainFactorMode = gainFactorMode; 123 fitOptions->chisqConvergence = chisqConvergence; 124 fitOptions->isInteractive = isInteractive; 85 125 86 126 // source analysis is done in S/N order (brightest first) … … 105 145 106 146 // allocate a job -- if threads are not defined, this just runs the job 107 psThreadJob *job = psThreadJobAlloc ("PSPHOT_ KRON_ITERATE");147 psThreadJob *job = psThreadJobAlloc ("PSPHOT_GALAXY_SHAPES"); 108 148 109 149 psArrayAdd(job->args, 1, readout); 110 150 psArrayAdd(job->args, 1, cells->data[j]); // sources 111 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 112 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 113 PS_ARRAY_ADD_SCALAR(job->args, pass, PS_TYPE_S32); 151 psArrayAdd(job->args, 1, fitOptions); 152 PS_ARRAY_ADD_SCALAR(job->args, markVal, PS_TYPE_IMAGE_MASK); 153 PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK); 154 PS_ARRAY_ADD_SCALAR(job->args, psfSize, PS_TYPE_S32); 114 155 115 156 // set this to 0 to run without threading … … 146 187 psFree (cellGroups); 147 188 148 psLogMsg ("psphot. kron", PS_LOG_WARN, "measure kron fluxes : %f sec for %ld objects\n", psTimerMark ("psphot.kron"), sources->n);189 psLogMsg ("psphot.galaxy", PS_LOG_WARN, "measure galaxy shapes : %f sec for %ld objects\n", psTimerMark ("psphot.galaxy"), sources->n); 149 190 return true; 150 191 } … … 152 193 bool psphotGalaxyShape_Threaded (psThreadJob *job) { 153 194 154 pmReadout *readout = job->args->data[0]; 155 psArray *sources = job->args->data[2]; 156 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA); 157 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[5],PS_TYPE_IMAGE_MASK_DATA); 195 pmReadout *readout = job->args->data[0]; 196 psArray *sources = job->args->data[1]; 197 pmSourceFitOptions *fitOptions = job->args->data[2]; 198 psImageMaskType markVal = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA); 199 psImageMaskType maskVal = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA); 200 int psfSize = PS_SCALAR_VALUE(job->args->data[5],S32); 158 201 159 202 for (int i = 0; i < sources->n; i++) { 160 161 // XXX what do i need for the kron flux (given a supplied kron radius?)162 203 163 204 pmSource *source = sources->data[i]; … … 184 225 185 226 // re-allocate image, weight, mask arrays for each peak with box big enough to fit BIG_RADIUS 186 bool extend =pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2);227 pmSourceRedefinePixels (source, readout, source->peak->x, source->peak->y, windowRadius + 2); 187 228 psAssert (source->pixels, "WTF?"); 188 229 189 230 // this function populates moments->Mrf,GalaxyShape,GalaxyShapeErr 190 231 // do the following for a set of shapes (Ex,Ey) 191 psphotGalaxyShape Source (source, maskVal);232 psphotGalaxyShapeGrid (source, fitOptions, maskVal, psfSize); 192 233 psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal)); 193 234 … … 198 239 } 199 240 200 bool psphotGalaxyShapeGrid (pmSource *source, psImageMaskType maskVal, float psfSize) { 201 202 pmPCMdata *pcm = pmPCMinit (source, &options, model, maskVal, psfSize); 203 204 // I have some source guess (e0, e1, e2) 205 psEllipsePol guessPol; 206 207 // I am going to retain the value of e0, and grid search around e1,e2 208 // I need to study a valid range (and distribution?) for e1,e2) 209 210 for (float de1 = -0.2; de1 <= +0.2; de1 += 0.1) { 211 for (float de2 = -0.2; de2 <= +0.2; de2 += 0.1) { 241 bool psphotGalaxyShapeGrid (pmSource *source, pmSourceFitOptions *fitOptions, psImageMaskType maskVal, int psfSize) { 242 243 // allocate the model 244 // XXX need to figure out how to get the model into the program 245 pmModelType modelType = pmModelClassGetType ("PS_MODEL_EXP"); 246 247 pmModel *model = pmModelAlloc(modelType); 248 if (!model) { 249 return NULL; 250 } 251 252 pmPCMdata *pcm = pmPCMinit (source, fitOptions, model, maskVal, psfSize); 253 254 psF32 *PAR = pcm->modelConv->params->data.F32; 255 256 // I have some source guess (e0, e1, e2) 257 psEllipsePol guessPol; 258 259 // I am going to retain the value of e0, and grid search around e1,e2 260 // I need to study a valid range (and distribution?) for e1,e2) 261 262 for (float de1 = -0.2; de1 <= +0.2; de1 += 0.1) { 263 for (float de2 = -0.2; de2 <= +0.2; de2 += 0.1) { 212 264 213 psEllipsePol testPol = guessPol; 214 testPol.e1 += de1; 215 testPol.e2 += de2; 216 217 psEllipseShape shape; 218 psEllipsePolToShape (&shape, testPol); 219 220 PAR[PM_PAR_SXX] = shape.sxx; 221 PAR[PM_PAR_SXY] = shape.sxy; 222 PAR[PM_PAR_SYY] = shape.syy; 223 224 // where do the results go?? 225 psphotGalaxyShapeSource (pcm, source, maskVal); 226 } 227 } 228 229 return true; 265 psEllipsePol testPol = guessPol; 266 testPol.e1 += de1; 267 testPol.e2 += de2; 268 269 psEllipseAxes axes = psEllipsePolToAxes (testPol, 0.1); 270 271 pmPSF_AxesToModel (PAR, axes, modelType); 272 273 // where do the results go?? 274 psphotGalaxyShapeSource (pcm, source, maskVal, psfSize); 275 } 276 } 277 278 return true; 230 279 } 231 280 232 281 // fit the given model to the source and find chisq & normalization 233 282 // XXX is this a single-component model? sersic with a supplied index, Reff, axis ratio, and theta? 234 bool psphotGalaxyShapeSource (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal ) {283 bool psphotGalaxyShapeSource (pmPCMdata *pcm, pmSource *source, psImageMaskType maskVal, int psfSize) { 235 284 236 285 PS_ASSERT_PTR_NON_NULL(source, false); 237 286 PS_ASSERT_PTR_NON_NULL(source->peak, false); 238 287 PS_ASSERT_PTR_NON_NULL(source->pixels, false); 239 240 psF32 *PAR = pcm->modelConv->params->data.F32;241 288 242 289 // generate the modelFlux … … 249 296 250 297 for (int iy = 0; iy < source->pixels->numRows; iy++) { 251 for (int ix = 0; ix < source->pixels->numCols; ix++) { 252 // skip masked points 253 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) { 254 continue; 298 for (int ix = 0; ix < source->pixels->numCols; ix++) { 299 // skip masked points 300 if (source->maskObj->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix]) { 301 continue; 302 } 303 // skip zero-variance points 304 if (source->variance->data.F32[iy][ix] == 0) { 305 continue; 306 } 307 // skip nan value points 308 if (!isfinite(source->pixels->data.F32[iy][ix])) { 309 continue; 310 } 311 312 float fy = source->pixels->data.F32[iy][ix]; 313 float fm = source->modelFlux->data.F32[iy][ix]; 314 float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0; 315 316 YY += PS_SQR(fy) * wt; 317 YM += fm * fy * wt; 318 MM += PS_SQR(fm) * wt; 255 319 } 256 // skip zero-variance points257 if (source->variance->data.F32[iy][ix] == 0) {258 continue;259 }260 // skip nan value points261 if (!isfinite(source->pixels->data.F32[iy][ix])) {262 continue;263 }264 265 float fy = source->pixels->data.F32[iy][ix];266 float fm = source->modelFlux->data.F32[iy][ix];267 float wt = (usePoisson) ? 1.0 / source->variance->data.F32[iy][ix] : 1.0;268 269 YY += PS_SQR(fy) * wt;270 YM += fm * fy * wt;271 MM += PS_SQR(fm) * wt;272 }273 320 } 274 321 … … 276 323 float Chisq = YY - 2 * Io * YM + Io * Io * MM; 277 324 278 return true; 279 } 325 fprintf (stderr, "Io: %f, Chisq: %f\n", Io, Chisq); 326 327 return true; 328 }
Note:
See TracChangeset
for help on using the changeset viewer.
