Changeset 15000 for trunk/psphot/src/psphotChoosePSF.c
- Timestamp:
- Sep 24, 2007, 11:27:58 AM (19 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotChoosePSF.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotChoosePSF.c
r14966 r15000 11 11 sources = psArraySort (sources, pmSourceSortBySN); 12 12 13 // structure to store user options defining the psf 14 pmPSFOptions *options = pmPSFOptionsAlloc (); 15 16 // load user options from the recipe. no need to check existence -- they are 13 17 // array to store candidate PSF stars 14 18 int NSTARS = psMetadataLookupS32 (&status, recipe, "PSF_MAX_NSTARS"); 15 PS_ASSERT (status, NULL);19 assert (status); 16 20 17 21 float PSF_MIN_DS = psMetadataLookupF32 (&status, recipe, "PSF_MIN_DS"); 18 PS_ASSERT (status, NULL);22 assert (status); 19 23 20 24 // supply the measured sky variance for optional constant errors (non-poissonian) 21 25 float SKY_SIG = psMetadataLookupF32 (&status, recipe, "SKY_SIG"); 22 PS_ASSERT (status, NULL);26 assert (status); 23 27 24 28 // use poissonian errors or local-sky errors 25 bool POISSON_ERRORS = psMetadataLookupBool (&status, recipe, "POISSON_ERRORS");26 PS_ASSERT (status, NULL);29 options->poissonErrorsPhotLMM = psMetadataLookupBool (&status, recipe, "POISSON.ERRORS.PHOT.LMM"); 30 assert (status); 27 31 28 32 // use poissonian errors or local-sky errors 29 bool PSF_PARAM_WEIGHTS = psMetadataLookupBool (&status, recipe, "PSF_PARAM_WEIGHTS"); 30 PS_ASSERT (status, NULL); 33 options->poissonErrorsPhotLin = psMetadataLookupBool (&status, recipe, "POISSON.ERRORS.PHOT.LIN"); 34 assert (status); 35 36 // use poissonian errors or local-sky errors 37 options->poissonErrorsParams = psMetadataLookupBool (&status, recipe, "POISSON.ERRORS.PARAMS"); 38 assert (status); 31 39 32 40 // how to model the PSF variations across the field 33 psMetadata *md = psMetadataLookupMetadata (&status, recipe, "PSF.TREND.MASK"); 34 PS_ASSERT (status, NULL); 41 options->psfTrendMode = pmTrend2DModeFromString (psMetadataLookupStr (&status, recipe, "PSF.TREND.MODE")); 42 assert (status); 43 44 options->psfTrendNx = psMetadataLookupS32 (&status, recipe, "PSF.TREND.NX"); 45 assert (status); 46 47 options->psfTrendNy = psMetadataLookupS32 (&status, recipe, "PSF.TREND.NY"); 48 assert (status); 35 49 36 50 // get the fixed PSF fit radius 37 51 // XXX check that PSF_FIT_RADIUS < SKY_OUTER_RADIUS 38 float RADIUS = psMetadataLookupF32 (&status, recipe, "PSF_FIT_RADIUS"); 39 PS_ASSERT (status, NULL); 40 41 pmSourceFitModelInit (15, 0.01, PS_SQR(SKY_SIG), POISSON_ERRORS); 42 43 psPolynomial2D *psfTrendMask = psPolynomial2DfromMetadata (md); 44 if (!psfTrendMask) { 45 psError(PSPHOT_ERR_PSF, true, "Unable to construct polynomial from PSF.TREND.MASK in the recipe"); 46 return NULL; 47 } 52 options->radius = psMetadataLookupF32 (&status, recipe, "PSF_FIT_RADIUS"); 53 assert (status); 54 55 options->stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); 56 57 // dimensions of the field for which the PSF is defined 58 options->psfFieldNx = readout->image->numCols; 59 options->psfFieldNy = readout->image->numRows; 60 options->psfFieldXo = readout->image->col0; 61 options->psfFieldYo = readout->image->row0; 62 63 pmSourceFitModelInit (15, 0.01, PS_SQR(SKY_SIG), options->poissonErrorsPhotLMM); 48 64 49 65 psArray *stars = psArrayAllocEmpty (sources->n); … … 66 82 psLogMsg ("psphot.choosePSF", PS_LOG_WARN, "Failed to find any PSF candidates"); 67 83 psFree (stars); 68 psFree (psfTrendMask);69 84 return NULL; 70 85 } … … 91 106 psMetadataItem *item = psListGetAndIncrement (iter); 92 107 char *modelName = item->data.V; 93 models->data[i] = pmPSFtryModel (stars, modelName, RADIUS, POISSON_ERRORS, psfTrendMask, PSF_PARAM_WEIGHTS, maskVal, mark);108 models->data[i] = pmPSFtryModel (stars, modelName, options, maskVal, mark); 94 109 } 95 110 … … 97 112 psFree (list); 98 113 psFree (stars); 99 psFree (psfTrendMask);100 114 101 115 // select the best of the models … … 128 142 if (psTraceGetLevel("psphot") >= 5) { 129 143 for (int i = PM_PAR_SXX; i < try->psf->params->n; i++) { 130 psPolynomial2D *poly = try->psf->params->data[i]; 131 for (int nx = 0; nx <= poly->nX; nx++) { 132 for (int ny = 0; ny <= poly->nY; ny++) { 133 if (poly->mask[nx][ny]) continue; 134 fprintf (stderr, "%g x^%d y^%d\n", poly->coeff[nx][ny], nx, ny); 135 } 136 } 144 // XXX re-write the output or some other status info 137 145 } 138 146 } … … 236 244 // use pmModelSub because modelFlux has not been generated 237 245 assert (source->maskObj); 238 psImageKeepCircle (source->maskObj, x, y, RADIUS, "OR", PM_MASK_MARK);246 psImageKeepCircle (source->maskObj, x, y, options->radius, "OR", PM_MASK_MARK); 239 247 pmModelSub (source->pixels, source->maskObj, source->modelPSF, PM_MODEL_OP_FULL, maskVal); 240 psImageKeepCircle (source->maskObj, x, y, RADIUS, "AND", PS_NOT_U8(PM_MASK_MARK));248 psImageKeepCircle (source->maskObj, x, y, options->radius, "AND", PS_NOT_U8(PM_MASK_MARK)); 241 249 } 242 250 … … 283 291 pmSourcesWritePSFs (try->sources, "psfstars.dat"); 284 292 pmSourcesWriteEXTs (try->sources, "extstars.dat", false); 285 psMetadata *psfData = pmPSFtoMetadata (NULL, try->psf); 286 psMetadataConfigWrite (psfData, "psfmodel.dat");287 psFree (psfData);293 // XXX need alternative output function 294 // psMetadata *psfData = pmPSFtoMetadata (NULL, try->psf); 295 // psMetadataConfigWrite (psfData, "psfmodel.dat"); 288 296 psLogMsg ("psphot.choosePSF", PS_LOG_INFO, "wrote out psf-subtracted image, psf data, exiting\n"); 289 297 exit (0); … … 306 314 psLogMsg ("psphot.pspsf", PS_LOG_INFO, "psf model %s, ApResid: %f +/- %f\n", modelName, psf->ApResid, psf->dApResid); 307 315 316 psFree (options); 308 317 return (psf); 309 318 }
Note:
See TracChangeset
for help on using the changeset viewer.
