Changeset 15814 for trunk/psModules/src/imcombine/pmPSFEnvelope.c
- Timestamp:
- Dec 13, 2007, 12:09:35 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/imcombine/pmPSFEnvelope.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmPSFEnvelope.c
r15764 r15814 72 72 float xOrigSpacing = (float)(numCols - 2 * radius) / (float)(instances - 1); // Spacing between instances 73 73 float yOrigSpacing = (float)(numRows - 2 * radius) / (float)(instances - 1); // Spacing between instances 74 //int fakeSpacing = 2 * radius + 1; // Spacing between instances (x and y) in the fake image75 //int fakeSize = instances * fakeSpacing; // Size of fake image74 int fakeSpacing = 2 * radius + 1; // Spacing between instances (x and y) in the fake image 75 int fakeSize = instances * fakeSpacing; // Size of fake image 76 76 77 77 // Generate list of fake sources (instances of the PSF) … … 82 82 for (int j = 0, index = 0; j < instances; j++) { 83 83 float yOrig = j * yOrigSpacing + radius; // Source position in original image 84 //float yFake = j * fakeSpacing + radius; // Position in fake image85 //int dy = yFake - yOrig; // Difference between fake and original position84 float yFake = j * fakeSpacing + radius; // Position in fake image 85 int dy = yFake - yOrig; // Difference between fake and original position 86 86 87 87 for (int i = 0; i < instances; i++, index++) { 88 88 float xOrig = i * xOrigSpacing + radius; // Source position in original image 89 //float xFake = i * fakeSpacing + radius; // Position in fake image90 //int dx = xFake - xOrig; // Difference between fake and original position89 float xFake = i * fakeSpacing + radius; // Position in fake image 90 int dx = xFake - xOrig; // Difference between fake and original position 91 91 92 92 pmSource *fake = pmSourceAlloc(); // Fake source 93 // fake->peak = pmPeakAlloc(xFake - dx, yFake - dy, PEAK_FLUX, PM_PEAK_LONE); 94 fake->peak = pmPeakAlloc(xOrig, yOrig, PEAK_FLUX, PM_PEAK_LONE); 93 fake->peak = pmPeakAlloc(xFake - dx, yFake - dy, PEAK_FLUX, PM_PEAK_LONE); 95 94 fake->type = PM_SOURCE_TYPE_STAR; 96 95 … … 104 103 105 104 fakes->data[index] = fake; 106 xOffset->data.S32[index] = 0; //dx;107 yOffset->data.S32[index] = 0; //dy;105 xOffset->data.S32[index] = dx; 106 yOffset->data.S32[index] = dy; 108 107 } 109 108 } 110 109 111 110 // Generate fake images with each PSF, and take the envelope 112 psImage *envelope = psImageAlloc( numCols, numRows, PS_TYPE_F32); // Image with envelope of PSFs111 psImage *envelope = psImageAlloc(fakeSize, fakeSize, PS_TYPE_F32); // Image with envelope of PSFs 113 112 psImageInit(envelope, 0.0); 114 113 pmReadout *fakeRO = pmReadoutAlloc(NULL); // Fake readout 115 114 for (int i = 0; i < inputs->n; i++) { 116 115 pmPSF *psf = inputs->data[i]; // PSF of interest 117 if (!pmReadoutFakeFromSources(fakeRO, numCols, numRows, fakes, xOffset, yOffset, psf, 118 NAN, radius)) { 116 pmResiduals *resid = psf->residuals;// PSF residuals 117 psf->residuals = NULL; 118 if (!pmReadoutFakeFromSources(fakeRO, fakeSize, fakeSize, fakes, xOffset, yOffset, psf, 119 NAN, radius, true)) { 119 120 psError(PS_ERR_UNKNOWN, false, "Unable to generate fake readout."); 120 121 psFree(envelope); … … 122 123 psFree(xOffset); 123 124 psFree(fakes); 125 psf->residuals = resid; 124 126 return NULL; 125 127 } 128 psf->residuals = resid; 126 129 127 130 // Need to renormalise sources so they all have the same peak. You would think they do have the same … … 159 162 } 160 163 164 165 161 166 #ifdef TESTING 162 167 { … … 183 188 #endif 184 189 185 // Reset the fake source pixels to the envelope pixels190 // Put the fake sources onto a full-size image 186 191 pmReadout *readout = pmReadoutAlloc(NULL); // Readout to contain envelope pixels 187 readout->image = envelope; 188 readout->weight = psImageAlloc(numCols, numRows, PS_TYPE_F32); 189 psImageInit(readout->weight, WEIGHT_VAL); 192 readout->image = psImageAlloc(numCols, numRows, PS_TYPE_F32); 193 psImageInit(readout->image, 0.0); 194 for (int i = 0; i < numFakes; i++) { 195 pmSource *source = fakes->data[i]; // Fake source 196 // Position of source on fake image 197 int xFake = source->peak->x + xOffset->data.S32[i]; 198 int yFake = source->peak->y + yOffset->data.S32[i]; 199 psRegion region = psRegionSet(xFake - radius, xFake + radius, 200 yFake - radius, yFake + radius); // PSF region 201 psImage *subImage = psImageSubset(envelope, region); // Subimage of fake PSF 202 203 // Position of source on "real" image 204 int x0 = source->peak->x - radius; 205 int y0 = source->peak->y - radius; 206 207 if (!psImageOverlaySection(readout->image, subImage, x0, y0, "=")) { 208 psError(PS_ERR_UNKNOWN, false, "Unable to overlay PSF"); 209 psFree(readout); 210 psFree(xOffset); 211 psFree(yOffset); 212 psFree(fakes); 213 return NULL; 214 } 215 } 216 readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(1.0, PS_TYPE_F32)); 190 217 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 191 218 psImageInit(readout->mask, 0); 192 219 220 #ifdef TESTING 221 { 222 // Write out the envelope 223 psFits *fits = psFitsOpen("psf_field_full.fits", "w"); 224 psFitsWriteImage(fits, NULL, readout->image, 0, NULL); 225 psFitsClose(fits); 226 } 227 #endif 228 193 229 for (int i = 0; i < numFakes; i++) { 194 230 pmSource *source = fakes->data[i]; // Fake source 195 float x = source->peak->xf + xOffset->data.S32[i]; // x coordinates of source 196 float y = source->peak->yf + yOffset->data.S32[i]; // y coordinates of source 231 float x = source->peak->xf;// + xOffset->data.S32[i]; // x coordinates of source 232 float y = source->peak->yf;// + yOffset->data.S32[i]; // y coordinates of source 233 234 psFree(source->pixels); 235 psFree(source->weight); 236 psFree(source->maskView); 237 psFree(source->maskObj); 238 source->pixels = NULL; 239 source->weight = NULL; 240 source->maskView = NULL; 241 source->maskObj = NULL; 197 242 198 243 if (!pmSourceDefinePixels(source, readout, x, y, (float)radius)) { … … 205 250 } 206 251 252 #if 0 253 // Need to do some magic so that pmSourceMoments behaves --- the only offsets it understands are the 254 // 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 #endif 267 207 268 if (!pmSourceMoments(source, radius)) { 208 269 psError(PS_ERR_UNKNOWN, false, "Unable to measure moments for source."); … … 213 274 return NULL; 214 275 } 215 } 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 216 289 217 290 pmPSFOptions *options = pmPSFOptionsAlloc(); // Options for fitting a PSF … … 224 297 options->radius = radius; 225 298 226 options->psfTrendMode = PM_TREND_ POLY_ORD;299 options->psfTrendMode = PM_TREND_MAP; 227 300 options->psfTrendNx = 1; 228 301 options->psfTrendNy = 1; … … 261 334 262 335 pmReadout *generated = pmReadoutAlloc(NULL); // Generated image 263 pmReadoutFakeFromSources(generated, numCols, numRows, fakes, xOffset, yOffset, psf, NAN, radius); 336 pmReadoutFakeFromSources(generated, numCols, numRows, fakes, xOffset, yOffset, psf, NAN, radius, 337 false); 264 338 { 265 339 psFits *fits = psFitsOpen("psf_field_model.fits", "w");
Note:
See TracChangeset
for help on using the changeset viewer.
