Changeset 25302
- Timestamp:
- Sep 8, 2009, 6:24:00 PM (17 years ago)
- Location:
- branches/pap/psphot/src
- Files:
-
- 5 edited
-
psphot.h (modified) (3 diffs)
-
psphotFake.c (modified) (8 diffs)
-
psphotFitSourcesLinear.c (modified) (1 diff)
-
psphotMagnitudes.c (modified) (2 diffs)
-
psphotReadout.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/psphot/src/psphot.h
r25260 r25302 49 49 bool psphotPSFstats (pmReadout *readout, psMetadata *recipe, pmPSF *psf); 50 50 bool psphotMomentsStats (pmReadout *readout, psMetadata *recipe, psArray *sources); 51 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe,pmPSF *psf, bool final);51 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, const psMetadata *recipe, const pmPSF *psf, bool final); 52 52 bool psphotReplaceUnfitSources (psArray *sources, psImageMaskType maskVal); 53 53 … … 64 64 bool psphotGuessModel_Threaded (psThreadJob *job); 65 65 66 bool psphotMagnitudes (pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf);66 bool psphotMagnitudes (pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, const pmPSF *psf); 67 67 bool psphotMagnitudes_Threaded (psThreadJob *job); 68 68 … … 76 76 bool psphotExtendedSourceAnalysis (pmReadout *readout, psArray *sources, psMetadata *recipe); 77 77 bool psphotExtendedSourceFits (pmReadout *readout, psArray *sources, psMetadata *recipe); 78 bool psphotFake(pm Readout *readout, const pmPSF *psf, psMetadata *recipe, const psArray *realSources);78 bool psphotFake(pmConfig *config, pmReadout *readout, const pmFPAview *view, const pmPSF *psf, psMetadata *recipe, const psArray *realSources); 79 79 80 80 // thread-related: -
branches/pap/psphot/src/psphotFake.c
r25278 r25302 21 21 PM_ASSERT_READOUT_NON_NULL(ro, false); 22 22 PM_ASSERT_READOUT_VARIANCE(ro, false); 23 assert(magLim); 24 assert(radius); 23 25 24 26 psKernel *kernel = psImageSmoothKernel(smoothSigma, smoothNsigma); // Kernel used for smoothing … … 52 54 psFree(normModel); 53 55 54 if (magLim) { 55 // The signal-to-noise of the smoothed image is: S/N ~ I_smooth / sqrt(variance * factor) 56 57 // since the variance factor tells us the variance in the smoothed image. Now, the trick is working 58 // out what the intensity in the smoothed image is, and how it is related to the flux. We are 59 // convolving Io G_* with G_PSF/2pi.w^2, where G_* is the approximately-Gaussian PSF of the star, 60 // G_PSF is the pretty-close-matching Gaussian of the convolution kernel, Io is the peak flux in the 61 // unsmoothed image, and w is the width of the Gaussian. Now, a normalised 2D Gaussian convolved 62 // with itself has a normalisation of 1/2pi(w^2+w^2) = 1/4pi.w^2. Therefore: 63 // I_smooth = Flux / 2*norm. 64 float peakLim = thresh * sqrtf(meanVar * factor); // Limiting peak value in smoothed image 65 float fluxLim = 2.0 * norm * peakLim; // Limiting flux in original 66 *magLim = -2.5 * log10f(fluxLim); 67 psTrace("psphot.fake", 1, "Limiting peak: %f\n", peakLim); 68 psTrace("psphot.fake", 1, "Limiting flux: %f\n", fluxLim); 69 psTrace("psphot.fake", 1, "Limiting mag: %f\n", *magLim); 70 } 71 if (radius) { 72 *radius = smoothSigma * smoothNsigma; 73 } 56 // The signal-to-noise of the smoothed image is: S/N ~ I_smooth / sqrt(variance * factor) 57 // since the variance factor tells us the variance in the smoothed image. Now, the trick is working 58 // out what the intensity in the smoothed image is, and how it is related to the flux. We are 59 // convolving Io G_* with G_PSF/2pi.w^2, where G_* is the approximately-Gaussian PSF of the star, 60 // G_PSF is the pretty-close-matching Gaussian of the convolution kernel, Io is the peak flux in the 61 // unsmoothed image, and w is the width of the Gaussian. Now, a normalised 2D Gaussian convolved 62 // with itself has a normalisation of 1/2pi(w^2+w^2) = 1/4pi.w^2. Therefore: 63 // I_smooth = Flux / 2*norm. 64 float peakLim = thresh * sqrtf(meanVar * factor); // Limiting peak value in smoothed image 65 float fluxLim = 2.0 * norm * peakLim; // Limiting flux in original 66 *magLim = -2.5 * log10f(fluxLim); 67 psTrace("psphot.fake", 1, "Limiting peak: %f\n", peakLim); 68 psTrace("psphot.fake", 1, "Limiting flux: %f\n", fluxLim); 69 psTrace("psphot.fake", 1, "Limiting mag: %f\n", *magLim); 70 71 *radius = smoothSigma * smoothNsigma; 74 72 75 73 return true; … … 90 88 PS_ASSERT_VECTOR_NON_NULL(magOffsets, false); 91 89 PS_ASSERT_VECTOR_TYPE(magOffsets, PS_TYPE_F32, false); 90 assert(xSrc); 91 assert(ySrc); 92 92 93 93 int numBins = magOffsets->n; // Number of bins … … 140 140 141 141 // *** in this section, perform the photometry for fake sources *** 142 bool psphotFake(pmReadout *readout, const pmPSF *psf, psMetadata *recipe, const psArray *realSources) 142 bool psphotFake(pmConfig *config, pmReadout *readout, const pmFPAview *view, const pmPSF *psf, 143 psMetadata *recipe, const psArray *realSources) 143 144 { 144 145 PM_ASSERT_READOUT_NON_NULL(readout, false); … … 201 202 } 202 203 204 // XXX Could speed this up significantly by only convolving the central pixels of each fake source 203 205 psImage *significance = psphotSignificanceImage(readout, recipe, 2, maskVal); 204 206 if (!significance) { … … 213 215 int numBins = magOffsets->n; // Number of bins 214 216 int numCols = readout->image->numCols, numRows = readout->image->numRows; // Size of image 215 psVector *frac = psVectorAlloc(numBins, PS_TYPE_F32); // Fraction of sources in each bin 217 psVector *count = psVectorAlloc(numBins, PS_TYPE_S32); // Number of sources found in each bin 218 psArray *fakeSources = psArrayAllocEmpty(numSources * numBins); // Fake sources 219 psVector *fakeEnd = psVectorAllocEmpty(numSources * numBins, PS_TYPE_S32); // End index of each bin 220 long numFound = 0; // Number of sources found 216 221 for (int i = 0; i < numBins; i++) { 217 int num Found= 0; // Number found222 int num = 0; // Number found 218 223 for (int j = 0; j < numSources; j++) { 219 224 // Coordinates of interest … … 221 226 float y = PS_MIN(yFake->data.F32[i][j] + 0.5, numRows - 1); 222 227 int xPix = x, yPix = y; // Pixel coordinates 223 if (significance->data.F32[yPix][xPix] > thresh) { 228 float sig = significance->data.F32[yPix][xPix]; // Significance of pixel 229 if (sig > thresh) { 230 pmSource *source = pmSourceAlloc(); // Fake source 231 source->peak = pmPeakAlloc(x, y, NAN, PM_PEAK_LONE); 232 if (!pmSourceDefinePixels(source, readout, x, y, radius)) { 233 psErrorClear(); 234 continue; 235 } 236 source->modelPSF = pmModelFromPSFforXY(psf, x, y, 2.0 * sqrtf(sig)); 237 source->type = PM_SOURCE_TYPE_STAR; 238 239 num++; 240 241 fakeSources->data[numFound] = source; 224 242 numFound++; 225 243 } 226 244 } 227 frac->data.F32[i] = (float)numFound / (float)numSources; 228 } 245 count->data.S32[i] = num; 246 fakeEnd->data.S32[i] = numFound; 247 } 248 fakeSources->n = numFound; 229 249 230 250 psFree(xFake); … … 232 252 psFree(significance); 233 253 254 if (!psphotFitSourcesLinear(readout, fakeSources, recipe, psf, true)) { 255 psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources."); 256 psFree(fakeSources); 257 psFree(fakeEnd); 258 psFree(count); 259 return false; 260 } 261 if (!psphotMagnitudes(config, readout, view, fakeSources, psf)) { 262 psError(PS_ERR_UNKNOWN, false, "Unable to measure magnitudes of fake sources."); 263 psFree(fakeSources); 264 psFree(fakeEnd); 265 psFree(count); 266 return false; 267 } 268 269 psVector *magErrMean = psVectorAlloc(numBins, PS_TYPE_F32); // Mean error in magnitude for each bin 270 psVector *magErrStdev = psVectorAlloc(numBins, PS_TYPE_F32); // Stdev of error in magnitude for each bin 271 psVector *magErr = psVectorAlloc(numSources, PS_TYPE_F32); // Magnitude errors 272 psVector *magMask = psVectorAlloc(numSources, PS_TYPE_VECTOR_MASK); // Mask for magnitude errors 273 psStats *magStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); // Statistics 274 for (int i = 0, index = 0; i < numBins; i++) { 275 psStatsInit(magStats); 276 psVectorInit(magMask, 0); 277 278 float magRef = magLim + magOffsets->data.F32[i]; // Reference magnitude 279 for (int j = 0; index < fakeEnd->data.S32[i]; j++, index++) { 280 pmSource *source = fakeSources->data[index]; // Source of interest 281 if (!source || !isfinite(source->psfMag)) { 282 magMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xFF; 283 continue; 284 } 285 magErr->data.F32[j] = source->psfMag - magRef; 286 } 287 if (!psVectorStats(magStats, magErr, NULL, magMask, 0xFF)) { 288 // Probably because we don't have enough sources 289 psErrorClear(); 290 } 291 magErrMean->data.F32[i] = magStats->sampleMean; 292 magErrStdev->data.F32[i] = magStats->sampleStdev; 293 } 294 psFree(magStats); 295 psFree(magMask); 296 psFree(magErr); 297 298 psFree(fakeSources); 299 psFree(fakeEnd); 300 234 301 // XXX How do we get the results out? 235 302 psMetadata *stats = psMetadataAlloc(); 236 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.EFF", PS_META_REPLACE, 237 "Efficiency fractions", frac); 303 psMetadataAddS32(stats, PS_LIST_TAIL, "FAKE.NUM", PS_META_REPLACE, 304 "Number of sources per bin", numSources); 305 psMetadataAddF32(stats, PS_LIST_TAIL, "FAKE.REF", PS_META_REPLACE, 306 "Efficiency reference magnitude", magLim); 238 307 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.MAG", PS_META_REPLACE, 239 308 "Efficiency magnitudes", magOffsets); 240 psMetadataAddF32(stats, PS_LIST_TAIL, "FAKE.REF", PS_META_REPLACE, 241 "Efficiency reference magnitude", magLim); 309 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.COUNTS", PS_META_REPLACE, 310 "Number of sources retrieved", count); 311 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.ERR", PS_META_REPLACE, 312 "Mean magnitude differences", magErrMean); 313 psMetadataAddVector(stats, PS_LIST_TAIL, "FAKE.RMS", PS_META_REPLACE, 314 "Stdev in magnitude differences", magErrStdev); 242 315 psMetadataConfigWrite(stats, "fake.stats"); 243 316 psFree(stats); 244 317 245 psFree(frac); 318 psFree(count); 319 psFree(magErrMean); 320 psFree(magErrStdev); 246 321 247 322 return true; -
branches/pap/psphot/src/psphotFitSourcesLinear.c
r23445 r25302 12 12 static bool SetBorderMatrixElements (psSparseBorder *border, pmReadout *readout, psArray *sources, bool constant_weights, int SKY_FIT_ORDER, psImageMaskType markVal); 13 13 14 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, psMetadata *recipe,pmPSF *psf, bool final) {14 bool psphotFitSourcesLinear (pmReadout *readout, psArray *sources, const psMetadata *recipe, const pmPSF *psf, bool final) { 15 15 16 16 bool status; -
branches/pap/psphot/src/psphotMagnitudes.c
r23349 r25302 1 1 # include "psphotInternal.h" 2 2 3 bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, pmPSF *psf) {3 bool psphotMagnitudes(pmConfig *config, pmReadout *readout, const pmFPAview *view, psArray *sources, const pmPSF *psf) { 4 4 5 5 bool status = false; … … 64 64 65 65 psArrayAdd(job->args, 1, cells->data[j]); // sources 66 psArrayAdd(job->args, 1, psf);66 psArrayAdd(job->args, 1, (pmPSF*)psf); // Casting away const 67 67 psArrayAdd(job->args, 1, binning); 68 68 psArrayAdd(job->args, 1, backModel); -
branches/pap/psphot/src/psphotReadout.c
r25246 r25302 224 224 psphotMagnitudes(config, readout, view, sources, psf); 225 225 226 if (!psphotFake( readout, psf, recipe, sources)) {226 if (!psphotFake(config, readout, view, psf, recipe, sources)) { 227 227 psErrorStackPrint(stderr, "Unable to determine detection efficiencies from fake sources"); 228 228 psErrorClear();
Note:
See TracChangeset
for help on using the changeset viewer.
