- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/simtest_nebulous_branches/psModules/src/imcombine/pmPSFEnvelope.c
r24622 r27840 34 34 35 35 // #define TESTING // Enable test output 36 // #define PEAK_NORM // Normalise peaks? 36 37 #define PEAK_FLUX 1.0e4 // Peak flux for each source 37 38 #define SKY_VALUE 0.0e0 // Sky value for fake image … … 64 65 int radius, // Radius of each PSF 65 66 const char *modelName,// Name of PSF model to use 66 int xOrder, int yOrder // Order for PSF variation fit 67 int xOrder, int yOrder, // Order for PSF variation fit 68 psImageMaskType maskVal 67 69 ) 68 70 { … … 122 124 continue; 123 125 } 126 127 if (psTraceGetLevel("psModules.imcombine") >= 1) { 128 psString string = NULL; // String with values 129 psStringAppend(&string, "PSF %d: ", i); 130 float x = numCols / 2.0, y = numRows / 2.0; // Coordinates of interest 131 for (int j = 4; j < psf->params->n; j++) { 132 pmTrend2D *trend = psf->params->data[j]; // Trend of interest 133 double val = pmTrend2DEval(trend, x, y); 134 double err; 135 switch (trend->mode) { 136 case PM_TREND_POLY_ORD: 137 case PM_TREND_POLY_CHEB: 138 err = NAN; 139 break; 140 case PM_TREND_MAP: 141 err = psImageUnbinPixel(x, y, trend->map->error, trend->map->binning); 142 break; 143 default: 144 psAbort("Unsupported mode: %x", trend->mode); 145 } 146 psStringAppend(&string, "%lf %lf ", val, err); 147 } 148 psTrace("psModules.imcombine", 1, "%s\n", string); 149 psFree(string); 150 } 151 152 // Test PSF 153 { 154 bool goodPSF = false; // Is there a PSF that we can use? 155 int xNum = PS_MAX(psf->trendNx, 1), yNum = PS_MAX(psf->trendNy, 1); // Number of positions to check 156 for (int j = 0; j < yNum && !goodPSF; j++) { 157 float y = ((float)j + 0.5) / (float)yNum * numRows; // Position on image 158 for (int i = 0; i < xNum && !goodPSF; i++) { 159 float x = ((float)i + 0.5) / (float)xNum * numCols; // Position on image 160 pmModelClassSetLimits(PM_MODEL_LIMITS_IGNORE); 161 pmModel *model = pmModelFromPSFforXY(psf, x, y, PEAK_FLUX); // Test model 162 if (!model) { 163 continue; 164 } 165 model->modelSetLimits(PM_MODEL_LIMITS_MODERATE); 166 bool limits = true; // Model within limits? 167 for (int j = 0; j < model->params->n && limits; j++) { 168 if (!model->modelLimits(PS_MINIMIZE_PARAM_MIN, j, model->params->data.F32, NULL) || 169 !model->modelLimits(PS_MINIMIZE_PARAM_MAX, j, model->params->data.F32, NULL)) { 170 limits = false; 171 } 172 } 173 psFree(model); 174 if (limits) { 175 goodPSF = true; 176 } 177 } 178 } 179 if (!goodPSF) { 180 psWarning("PSF %d is completely bad --- not including in envelope calculation.", i); 181 continue; 182 } 183 } 184 124 185 pmResiduals *resid = psf->residuals;// PSF residuals 125 186 psf->residuals = NULL; 126 if (!pmReadoutFakeFromSources(fakeRO, fakeSize, fakeSize, fakes, xOffset, yOffset, psf, 127 NAN, radius, true, true)) { 187 pmModelClassSetLimits(PM_MODEL_LIMITS_MODERATE); 188 if (!pmReadoutFakeFromSources(fakeRO, fakeSize, fakeSize, fakes, 0, xOffset, yOffset, psf, 189 NAN, radius, true, false)) { 128 190 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake readout."); 129 191 psFree(envelope); … … 144 206 float y = source->peak->yf + yOffset->data.S32[j]; // y coordinate of source 145 207 146 double flux = fakeRO->image->data.F32[(int)y][(int)x]; 208 #ifdef PEAK_NORM 209 // Perhaps I'm being paranoid, but specify a range to check 210 int uMax = PS_MIN(x + radius, numCols - 1), uMin = PS_MAX(x - radius, 0); 211 int vMax = PS_MIN(y + radius, numRows - 1), vMin = PS_MAX(y - radius, 0); 212 213 double flux = -INFINITY; // Peak flux 214 for (int v = vMin; v <= vMax; v++) { 215 for (int u = uMin; u <= uMax; u++) { 216 if (fakeRO->image->data.F32[v][u] > flux) { 217 flux = fakeRO->image->data.F32[v][u]; 218 } 219 } 220 } 147 221 if (!isfinite(flux) || flux < 0) { 148 222 continue; 149 223 } 150 224 float norm = PEAK_FLUX / flux; // Normalisation for source 225 #endif 151 226 psRegion region = psRegionSet(x - radius, x + radius, y - radius, y + radius); // PSF region 152 227 psImage *subImage = psImageSubset(fakeRO->image, region); // Subimage of fake PSF 153 228 psImage *subEnv = psImageSubset(envelope, region); // Subimage of envelope 229 #ifdef PEAK_NORM 154 230 psBinaryOp(subImage, subImage, "*", psScalarAlloc(norm, PS_TYPE_F32)); 231 #endif 155 232 psBinaryOp(subEnv, subEnv, "MAX", subImage); 156 233 psFree(subImage); … … 163 240 } 164 241 float srcRadius = model->modelRadius(model->params, PS_SQR(VARIANCE_VAL)); // Radius for source 242 psFree(model); 165 243 if (srcRadius == 0) { 166 244 continue; … … 298 376 } 299 377 300 // measure the source moments: tophat windowing, no pixel S/N cutoff 301 if (!pmSourceMoments(source, maxRadius, 0.0, 1.0)) { 378 // measure the source moments: tophat windowing, no pixel S/N cutoff 379 // XXX probably should be passing the maskVal to this function so we can pass it along here... 380 if (!pmSourceMoments(source, maxRadius, 0.0, 1.0, maskVal)) { 302 381 // Can't do anything about it; limp along as best we can 303 382 psErrorClear(); … … 320 399 options->poissonErrorsParams = true; 321 400 options->stats = psStatsAlloc(PSF_STATS); 322 options->radius = maxRadius; 401 options->fitRadius = maxRadius; 402 options->apRadius = maxRadius; // XXX need to decide if aperture mags need a different radius 323 403 options->psfTrendMode = PM_TREND_MAP; 324 404 options->psfTrendNx = xOrder; … … 331 411 332 412 pmSourceFitModelInit(SOURCE_FIT_ITERATIONS, 0.01, VARIANCE_VAL, true); 413 pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); // Important for getting a good stack target PSF 333 414 334 415 pmPSFtry *try = pmPSFtryModel(fakes, modelName, options, 0, 0xff); … … 343 424 pmPSF *psf = psMemIncrRefCounter(try->psf); // Output PSF 344 425 psFree(try); 426 427 if (psTraceGetLevel("psModules.imcombine") >= 1) { 428 psString string = NULL; // String with values 429 psStringAppend(&string, "Envelope PSF: "); 430 float x = numCols / 2.0, y = numRows / 2.0; // Coordinates of interest 431 for (int j = 4; j < psf->params->n; j++) { 432 pmTrend2D *trend = psf->params->data[j]; // Trend of interest 433 double val = pmTrend2DEval(trend, x, y); 434 double err; 435 switch (trend->mode) { 436 case PM_TREND_POLY_ORD: 437 case PM_TREND_POLY_CHEB: 438 err = NAN; 439 break; 440 case PM_TREND_MAP: 441 err = psImageUnbinPixel(x, y, trend->map->error, trend->map->binning); 442 break; 443 default: 444 psAbort("Unsupported mode: %x", trend->mode); 445 } 446 psStringAppend(&string, "%lf %lf ", val, err); 447 } 448 psTrace("psModules.imcombine", 1, "%s\n", string); 449 psFree(string); 450 } 345 451 346 452 #ifdef TESTING … … 357 463 358 464 pmReadout *generated = pmReadoutAlloc(NULL); // Generated image 359 pmReadoutFakeFromSources(generated, numCols, numRows, fakes, NULL, NULL, psf, NAN, radius,465 pmReadoutFakeFromSources(generated, numCols, numRows, fakes, 0, NULL, NULL, psf, NAN, radius, 360 466 false, true); 361 467 {
Note:
See TracChangeset
for help on using the changeset viewer.
