Changeset 15836 for trunk/psModules/src/imcombine/pmPSFEnvelope.c
- Timestamp:
- Dec 14, 2007, 3:09:53 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmPSFEnvelope.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmPSFEnvelope.c
r15814 r15836 32 32 33 33 #define TESTING // Enable test output 34 #define PEAK_FLUX 1.0e3 // peak flux for each source 34 #define PEAK_FLUX 1.0e3 // Peak flux for each source 35 #define SKY_VALUE 0.0e0 // Sky value for fake image 35 36 #define WEIGHT_VAL 1.0e0 // Weighting for image 36 #define PSF_STATS PS_STAT_ ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV // Statistics options for measuring PSF37 #define PSF_STATS PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV // Statistics options for measuring PSF 37 38 38 39 39 40 40 41 // XXX To do: 41 //42 // * PSF representation doesn't normalise (x,y) positions in polynomials: need to find out how I can have a43 // star at (x1,y1) in the image that is "really" supposed to be at (x2,y2).44 42 // 45 43 // * PSF variation when only a portion of the image is present (e.g., the edge of an FPA overlapping a … … 60 58 int instances, // Number of instances per dimension 61 59 int radius, // Radius of each PSF 62 const char *modelName // Name of PSF model to use 60 const char *modelName,// Name of PSF model to use 61 int xOrder, int yOrder // Order for PSF variation fit 63 62 ) 64 63 { … … 69 68 PS_ASSERT_INT_POSITIVE(radius, NULL); 70 69 PS_ASSERT_STRING_NON_EMPTY(modelName, NULL); 70 PS_ASSERT_INT_NONNEGATIVE(xOrder, NULL); 71 PS_ASSERT_INT_NONNEGATIVE(yOrder, NULL); 71 72 72 73 float xOrigSpacing = (float)(numCols - 2 * radius) / (float)(instances - 1); // Spacing between instances … … 110 111 // Generate fake images with each PSF, and take the envelope 111 112 psImage *envelope = psImageAlloc(fakeSize, fakeSize, PS_TYPE_F32); // Image with envelope of PSFs 112 psImageInit(envelope, 0.0);113 psImageInit(envelope, SKY_VALUE); 113 114 pmReadout *fakeRO = pmReadoutAlloc(NULL); // Fake readout 114 115 for (int i = 0; i < inputs->n; i++) { … … 135 136 float y = source->peak->yf + yOffset->data.S32[j]; // y coordinate of source 136 137 137 #if 0138 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR,139 fakeRO->image, NULL, NULL, 0,140 0.0, 0.0, 1, 0, 0.0);141 double flux; // Flux of peak142 if (!psImageInterpolate(&flux, NULL, NULL, x, y, interp)) {143 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate source image.");144 psFree(envelope);145 psFree(yOffset);146 psFree(xOffset);147 psFree(fakes);148 return NULL;149 }150 #else151 138 double flux = fakeRO->image->data.F32[(int)y][(int)x]; 152 #endif153 154 139 float norm = PEAK_FLUX / flux; // Normalisation for source 155 140 psRegion region = psRegionSet(x - radius, x + radius, y - radius, y + radius); // PSF region … … 161 146 psFree(subEnv); 162 147 } 163 164 165 148 166 149 #ifdef TESTING … … 214 197 } 215 198 } 199 psFree(xOffset); 200 psFree(yOffset); 201 216 202 readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(1.0, PS_TYPE_F32)); 217 203 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); … … 227 213 #endif 228 214 215 // Reset the sources to point to the new pixels, and measure the moments in preparation for PSF fitting 229 216 for (int i = 0; i < numFakes; i++) { 230 217 pmSource *source = fakes->data[i]; // Fake source 231 float x = source->peak->xf; // + xOffset->data.S32[i];// x coordinates of source232 float y = source->peak->yf; // + yOffset->data.S32[i];// y coordinates of source218 float x = source->peak->xf; // x coordinates of source 219 float y = source->peak->yf; // y coordinates of source 233 220 234 221 psFree(source->pixels); … … 244 231 psError(PS_ERR_UNKNOWN, false, "Unable to define pixels for source."); 245 232 psFree(readout); 246 psFree(yOffset);247 psFree(xOffset);248 233 psFree(fakes); 249 234 return NULL; 250 235 } 251 252 #if 0253 // Need to do some magic so that pmSourceMoments behaves --- the only offsets it understands are the254 // col0,row0 in the psImage.255 int oldCol0 = source->pixels->col0;256 int oldRow0 = source->pixels->row0;257 int col0 = oldCol0 - xOffset->data.S32[i];258 int row0 = oldRow0 - yOffset->data.S32[i];259 260 P_PSIMAGE_SET_COL0(source->pixels, col0);261 P_PSIMAGE_SET_ROW0(source->pixels, row0);262 P_PSIMAGE_SET_COL0(source->weight, col0);263 P_PSIMAGE_SET_ROW0(source->weight, row0);264 P_PSIMAGE_SET_COL0(source->maskObj, col0);265 P_PSIMAGE_SET_ROW0(source->maskObj, row0);266 #endif267 236 268 237 if (!pmSourceMoments(source, radius)) { 269 238 psError(PS_ERR_UNKNOWN, false, "Unable to measure moments for source."); 270 239 psFree(readout); 271 psFree(yOffset);272 psFree(xOffset);273 240 psFree(fakes); 274 241 return NULL; 275 242 } 276 277 #if 0 278 P_PSIMAGE_SET_COL0(source->pixels, oldCol0); 279 P_PSIMAGE_SET_ROW0(source->pixels, oldRow0); 280 P_PSIMAGE_SET_COL0(source->weight, oldCol0); 281 P_PSIMAGE_SET_ROW0(source->weight, oldRow0); 282 P_PSIMAGE_SET_COL0(source->maskObj, oldCol0); 283 P_PSIMAGE_SET_ROW0(source->maskObj, oldRow0); 284 #endif 285 } 286 287 psMemCheckCorruption(stderr, true); 288 289 243 } 244 245 // Don't assume Poisson errors 290 246 pmPSFOptions *options = pmPSFOptionsAlloc(); // Options for fitting a PSF 291 // Don't assume Poisson errors --- our fake system isn't Poisson.292 247 options->poissonErrorsPhotLMM = false; 293 248 options->poissonErrorsPhotLin = false; 294 249 options->poissonErrorsParams = false; 295 250 options->stats = psStatsAlloc(PSF_STATS); 296 297 251 options->radius = radius; 298 299 252 options->psfTrendMode = PM_TREND_MAP; 300 options->psfTrendNx = 1; 301 options->psfTrendNy = 1; 302 253 options->psfTrendNx = xOrder; 254 options->psfTrendNy = yOrder; 303 255 options->psfFieldNx = numCols; 304 256 options->psfFieldNy = numRows; … … 313 265 psError(PS_ERR_UNKNOWN, false, "Unable to fit PSF model to PSF envelope."); 314 266 psFree(readout); 315 psFree(yOffset);316 psFree(xOffset);317 267 psFree(fakes); 318 268 return NULL; … … 334 284 335 285 pmReadout *generated = pmReadoutAlloc(NULL); // Generated image 336 pmReadoutFakeFromSources(generated, numCols, numRows, fakes, xOffset, yOffset, psf, NAN, radius,286 pmReadoutFakeFromSources(generated, numCols, numRows, fakes, NULL, NULL, psf, NAN, radius, 337 287 false); 338 288 { … … 341 291 psFitsClose(fits); 342 292 } 343 psBinaryOp(generated->image, generated->image, "-", envelope);293 psBinaryOp(generated->image, generated->image, "-", readout->image); 344 294 { 345 295 psFits *fits = psFitsOpen("psf_field_resid.fits", "w"); … … 352 302 353 303 psFree(yOffset); 354 psFree(xOffset);355 psFree(fakes);356 304 psFree(readout); 305 357 306 return psf; 358 307 }
Note:
See TracChangeset
for help on using the changeset viewer.
