Changeset 15000 for trunk/psphot
- Timestamp:
- Sep 24, 2007, 11:27:58 AM (19 years ago)
- Location:
- trunk/psphot
- Files:
-
- 8 edited
-
doc/psfmodel.txt (modified) (1 diff)
-
src/models/pmModel_STRAIL.c (modified) (2 diffs)
-
src/models/pmModel_TEST1.c (modified) (2 diffs)
-
src/psphot.h (modified) (1 diff)
-
src/psphotApResid.c (modified) (14 diffs)
-
src/psphotChoosePSF.c (modified) (8 diffs)
-
src/psphotRoughClass.c (modified) (2 diffs)
-
src/psphotSourcePlots.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/doc/psfmodel.txt
r9772 r15000 1 2 2007.09.21 3 4 there are three places where we can choose to use errors in the fits or not: 5 6 * non-linear fitting of the models to the pixel flux distribution (poissonErrorsPhotLMM) 7 * linear fitting of the models to the pixel flux distribution (poissonErrorsPhotLin) 8 * fitting of the 2D variations in the psf parameters (poissonErrorsParams) 9 * fitting of the 2D variations in the aperture residuals 10 11 2007.09.20 12 13 I am upgrading the PSF model to allow the parameter variation to be 14 modeled with pmTrend2D instead of just polynomials. I am making a 15 list of places to modify the code: 16 17 pmPSFAlloc : need a method beyong psfTrendMask to carry in the psf 18 options 19 20 pmPSF_ModelToFit : no need to change these 21 22 update pmPSFBuildSimple to set the parameters of the pmTrend, which 23 ever is used. 24 25 pmPSFtry.c: some significant re-work! 26 27 28 29 pmPSF_IO : need new functions to save / load the trend (psImages) 1 30 2 31 2006.10.27 -
trunk/psphot/src/models/pmModel_STRAIL.c
r14655 r15000 530 530 531 531 for (int i = 4; i < 7; i++) { 532 p sPolynomial2D *poly= psf->params->data[i-4];533 out[i] = p sPolynomial2DEval (poly, out[2], out[3]);532 pmTrend2D *trend = psf->params->data[i-4]; 533 out[i] = pmTrend2DEval (trend, out[2], out[3]); 534 534 } 535 535 return(true); … … 554 554 for (int i = 0; i < psf->params->n; i++) { 555 555 if (i == PM_PAR_SKY) continue; 556 psPolynomial2D *poly = psf->params->data[i]; 557 assert (poly); 558 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 556 pmTrend2D *trend = psf->params->data[i]; 557 PAR[i] = pmTrend2DEval(trend, Xo, Yo); 559 558 } 560 559 -
trunk/psphot/src/models/pmModel_TEST1.c
r14655 r15000 217 217 out[i] = in[i]; 218 218 } else { 219 p sPolynomial2D *poly= psf->params->data[i];220 out[i] = p sPolynomial2DEval(poly, in[PM_PAR_XPOS], in[PM_PAR_YPOS]);219 pmTrend2D *trend = psf->params->data[i]; 220 out[i] = pmTrend2DEval(trend, in[PM_PAR_XPOS], in[PM_PAR_YPOS]); 221 221 } 222 222 } … … 246 246 for (int i = 0; i < psf->params->n; i++) { 247 247 if (i == PM_PAR_SKY) continue; 248 psPolynomial2D *poly = psf->params->data[i]; 249 assert (poly); 250 PAR[i] = psPolynomial2DEval(poly, Xo, Yo); 248 pmTrend2D *trend = psf->params->data[i]; 249 PAR[i] = pmTrend2DEval(trend, Xo, Yo); 251 250 } 252 251 -
trunk/psphot/src/psphot.h
r14963 r15000 47 47 bool psphotReplaceAll (psArray *sources, psMaskType maskVal); 48 48 bool psphotApResid (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal, psMaskType mark); 49 bool psphotMagErrorScale (float *errorScale, float *errorFloor, psVector *dMag, psVector *dap, int nGroup);49 bool psphotMagErrorScale (float *errorScale, float *errorFloor, psVector *dMag, psVector *dap, psVector *mask, int nGroup); 50 50 bool psphotApResidTrend (pmReadout *readout, pmPSF *psf, int Npsf, int scale, float *errorScale, float *errorFloor, psVector *mask, psVector *xPos, psVector *yPos, psVector *apResid, psVector *dMag); 51 51 bool psphotMagnitudes (psArray *sources, psMetadata *recipe, pmPSF *psf, pmReadout *background, psMaskType maskVal, psMaskType mark); -
trunk/psphot/src/psphotApResid.c
r14965 r15000 1 1 # include "psphotInternal.h" 2 2 3 # define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; } 3 4 // measure the aperture residual statistics and 2D variations 4 5 bool psphotApResid (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf, psMaskType maskVal, psMaskType mark) … … 63 64 model = source->modelPSF; 64 65 65 if (source->type != PM_SOURCE_TYPE_STAR) continue;66 if (source->mode & PM_SOURCE_MODE_SATSTAR) continue;67 if (source->mode & PM_SOURCE_MODE_BLEND) continue;68 if (source->mode & PM_SOURCE_MODE_FAIL) continue;69 if (source->mode & PM_SOURCE_MODE_POOR) continue;66 if (source->type != PM_SOURCE_TYPE_STAR) SKIPSTAR ("NOT STAR"); 67 if (source->mode & PM_SOURCE_MODE_SATSTAR) SKIPSTAR ("SATSTAR"); 68 if (source->mode & PM_SOURCE_MODE_BLEND) SKIPSTAR ("BLEND"); 69 if (source->mode & PM_SOURCE_MODE_FAIL) SKIPSTAR ("FAIL STAR"); 70 if (source->mode & PM_SOURCE_MODE_POOR) SKIPSTAR ("POOR STAR"); 70 71 71 72 // get growth-corrected, apTrend-uncorrected magnitudes in scaled apertures … … 73 74 if (!pmSourceMagnitudes (source, psf, photMode, maskVal, mark)) { 74 75 Nskip ++; 76 psTrace ("psphot", 3, "skip : bad source mag"); 75 77 continue; 76 78 } 77 79 78 if (!isfinite(source->apMag) || !isfinite(source-> apMag)) {80 if (!isfinite(source->apMag) || !isfinite(source->psfMag)) { 79 81 Nfail ++; 82 psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag); 80 83 continue; 81 84 } … … 87 90 if ((MAX_AP_OFFSET > 0) && (fabs(dap) > MAX_AP_OFFSET)) { 88 91 Nfail ++; 92 psTrace ("psphot", 3, "fail : bad dap %f %f", dap, MAX_AP_OFFSET); 89 93 continue; 90 94 } … … 99 103 dMag->data.F32[Npsf] = model->dparams->data.F32[PM_PAR_I0] / model->params->data.F32[PM_PAR_I0]; 100 104 105 psVectorExtend (mag, 100, 1); 101 106 psVectorExtend (mask, 100, 1); 102 107 psVectorExtend (xPos, 100, 1); … … 146 151 } 147 152 153 // XXX catch error condition 148 154 psphotApResidTrend (readout, psf, Npsf, entryMin, &errorScale, &errorFloor, mask, xPos, yPos, apResid, dMag); 149 155 … … 152 158 psVector *apResidRes = (psVector *) psBinaryOp (NULL, (void *) apResid, "-", (void *) apResidFit); 153 159 psVector *dMagSys = (psVector *) psBinaryOp (NULL, (void *) dMag, "*", (void *) psScalarAlloc(errorScale, PS_TYPE_F32)); 154 155 psphotSaveImage (NULL, psf->ApTrend->map->map, "apresid.map.fits");156 160 157 161 if (psTraceGetLevel("psphot") >= 5) { … … 170 174 float xc = 0.5*readout->image->numCols + readout->image->col0 + 0.5; 171 175 float yc = 0.5*readout->image->numRows + readout->image->row0 + 0.5; 176 172 177 psf->ApResid = pmTrend2DEval (psf->ApTrend, xc, yc); // ap-fit at chip center 173 178 psf->dApResid = errorFloor; … … 206 211 */ 207 212 208 bool psphotMagErrorScale (float *errorScale, float *errorFloor, psVector *dMag, psVector *dap, int nGroup) {213 bool psphotMagErrorScale (float *errorScale, float *errorFloor, psVector *dMag, psVector *dap, psVector *mask, int nGroup) { 209 214 210 215 psStats *statsS = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); … … 225 230 psVector *dMSubset = psVectorAllocEmpty (nGroup, PS_TYPE_F32); 226 231 psVector *dASubset = psVectorAllocEmpty (nGroup, PS_TYPE_F32); 232 psVector *mkSubset = psVectorAllocEmpty (nGroup, PS_TYPE_U8); 227 233 228 234 int n = 0; … … 233 239 dMSubset->data.F32[j] = dMag->data.F32[N]; 234 240 dASubset->data.F32[j] = dap->data.F32[N]; 241 mkSubset->data.U8[j] = mask->data.U8[N]; 235 242 } 236 243 dMSubset->n = j; 237 244 dASubset->n = j; 245 mkSubset->n = j; 238 246 239 247 psStatsInit (statsS); 240 248 psStatsInit (statsM); 241 249 242 psVectorStats (statsS, dASubset, NULL, NULL, 0xff);243 psVectorStats (statsM, dMSubset, NULL, NULL, 0xff);250 psVectorStats (statsS, dASubset, NULL, mkSubset, 0xff); 251 psVectorStats (statsM, dMSubset, NULL, mkSubset, 0xff); 244 252 245 253 dSo->data.F32[i] = statsS->robustStdev; … … 250 258 psFree (dMSubset); 251 259 psFree (dASubset); 260 psFree (mkSubset); 252 261 253 262 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN); … … 286 295 } 287 296 297 // the mask marks the values not used to calculate the ApTrend 298 psVectorInit (mask, 0); 299 288 300 // XXX stats structure for use by ApTrend : make parameters user setable 289 301 psStats *stats = psStatsAlloc (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV); … … 305 317 // XXX this is a bit arbitrary, but it forces ~3 stars from the bright bin per spatial bin 306 318 int nGroup = PS_MAX (3*Nx*Ny, 10); 307 psphotMagErrorScale (errorScale, errorFloor, dMag, apResidRes, nGroup);319 psphotMagErrorScale (errorScale, errorFloor, dMag, apResidRes, mask, nGroup); 308 320 309 321 psLogMsg ("psphot.apresid", PS_LOG_INFO, "result of %d x %d grid (%d stars per bin)\n", Nx, Ny, nGroup); -
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 } -
trunk/psphot/src/psphotRoughClass.c
r14760 r15000 1 1 # include "psphotInternal.h" 2 # define CHECK_STATUS(S,MSG) { \ 3 if (!status) { \ 4 psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \ 5 return false; \ 6 } } 2 7 3 8 // 2006.02.02 : no leaks 4 9 bool psphotRoughClass (psArray *sources, psMetadata *recipe, const bool havePSF, psMaskType maskSat) { 5 10 6 static pmPSFClump psfClump; 11 bool status; 12 static pmPSFClump psfClump; 7 13 8 14 psTimerStart ("psphot"); … … 11 17 // determine the PSF parameters from the source moment values 12 18 psfClump = pmSourcePSFClump (sources, recipe); 19 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.X", 0, "psf clump center", psfClump.X); 20 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.Y", 0, "psf clump center", psfClump.Y); 21 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.DX", 0, "psf clump center", psfClump.dX); 22 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.DY", 0, "psf clump center", psfClump.dY); 13 23 } else { 14 24 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y 15 bool status_x, status_y, status_a; 16 float FWHM_X = psMetadataLookupF32 (&status_x, recipe, "FWHM_X"); 17 float FWHM_Y = psMetadataLookupF32 (&status_y, recipe, "FWHM_Y"); 18 float ANGLE = psMetadataLookupF32 (&status_a, recipe, "ANGLE"); 19 if (!status_x | !status_y | !status_a) { 20 psError(PSPHOT_ERR_CONFIG, false, "FWHM_X, FWHM_Y, or ANGLE not defined"); 21 return false; 22 } 23 24 psEllipseAxes axes; 25 axes.major = FWHM_X / (2.0*sqrt(2.0*log(2.0))); 26 axes.minor = FWHM_Y / (2.0*sqrt(2.0*log(2.0))); 27 axes.theta = ANGLE; 28 psEllipseShape shape = psEllipseAxesToShape (axes); 29 30 psfClump.X = shape.sx; 31 psfClump.Y = shape.sy; 32 psfClump.dX = 0.1*shape.sx; 33 psfClump.dY = 0.1*shape.sy; 34 // dX,dY are somewhat crudely defined, but only used to select PSF candidates. 35 // if we already have a PSF, this is not actually used... 25 psfClump.X = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.X"); CHECK_STATUS (status, "PSF.CLUMP.X"); 26 psfClump.Y = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.Y"); CHECK_STATUS (status, "PSF.CLUMP.Y"); 27 psfClump.dX = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.DX"); CHECK_STATUS (status, "PSF.CLUMP.DX"); 28 psfClump.dY = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.DY"); CHECK_STATUS (status, "PSF.CLUMP.DY"); 36 29 } 37 30 -
trunk/psphot/src/psphotSourcePlots.c
r13900 r15000 20 20 int dY = 0; // height of row so far 21 21 int NX = 20*DX; // full width of output image 22 int NY = 0; // total height of output image22 int NY = DY; // total height of output image so far 23 23 24 // first, examine the PSF and SAT stars: 25 // - determine bounding boxes for summary image 24 // first, examine the PSF and SAT stars to set output image size: 25 // - add stamp widths until we exceed output image width, 26 // - then start a new row offset by max height 26 27 for (int i = 0; i < sources->n; i++) { 27 28 … … 31 32 keep |= (source->mode & PM_SOURCE_MODE_PSFSTAR); 32 33 keep |= (source->mode & PM_SOURCE_MODE_SATSTAR); 33 if (!keep) continue; 34 if (!keep) { 35 psTrace ("psphot", 4, "not plotting star %d: %x", i, source->mode); 36 continue; 37 } 34 38 35 39 // how does this subimage get placed into the output image? … … 57 61 } 58 62 63 if (NY == 0) { 64 psWarning ("no PSF or SAT stars to plot? skipping.\n"); 65 return false; 66 } 67 59 68 // allocate output image 60 69 psImage *outpos = psImageAlloc (NX, NY, PS_TYPE_F32); 61 70 psImage *outsub = psImageAlloc (NX, NY, PS_TYPE_F32); 71 72 psImageInit (outpos, 0.0); 73 psImageInit (outsub, 0.0); 62 74 63 75 int Xo = 0; // starting corner of next box … … 142 154 psFree (outpos); 143 155 psFree (outsub); 144 return (sources);156 return true; 145 157 } 146 158
Note:
See TracChangeset
for help on using the changeset viewer.
