Changeset 25025
- Timestamp:
- Aug 7, 2009, 2:44:49 PM (17 years ago)
- File:
-
- 1 edited
-
branches/pap/psphot/src/psphotFake.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap/psphot/src/psphotFake.c
r24013 r25025 7 7 #define MIN_FLUX 0.1 // Minimum flux for faint sources 8 8 #endif 9 10 11 // Calculate the limiting flux for an image 12 // 13 // We limit ourselves to calculating the peak flux in the smoothed image, which should be close (modulo 14 // non-Gaussian PSF) to the limiting flux in the un-smoothed original image. 15 static float fakeLimit(const pmReadout *ro, // Readout of interest 16 const psMetadata *recipe // psphot recipe 17 ); 18 { 19 PM_ASSERT_READOUT_NON_NULL(ro, NAN); 20 PM_ASSERT_READOUT_VARIANCE(ro, NAN); 21 PS_ASSERT_METADATA_NON_NULL(recipe, NAN); 22 23 float xFWHM = psMetadataLookupF32(NULL, recipe, "FWHM_X"); 24 float yFWHM = psMetadataLookupF32(NULL, recipe, "FWHM_Y"); 25 if (!isfinite(xFWHM) || !isfinite(yFWHM)) { 26 psError(PSPHOT_ERR_CONFIG, false, "Unable to find FWHM_X and FWHM_Y"); 27 return NAN; 28 } 29 30 float smoothSigma = 0.5*(FWHM_X + FWHM_Y) / (2.0*sqrtf(2.0*log(2.0))); 31 float smoothNsigma = psMetadataLookupF32(NULL, recipe, "PEAKS_SMOOTH_NSIGMA"); 32 if (!isfinite(smoothSigma) || !isfinite(smoothNsigma)) { 33 psError(PSPHOT_ERR_CONFIG, false, "Unable to set smoothing parameters"); 34 return NAN; 35 } 36 37 psKernel *kernel = psImageSmoothKernel(smoothSigma, smoothNsigma); // Kernel used for smoothing 38 psKernel *newCovar = psImageCovarianceCalculate(kernel, readout->covariance); // Covariance matrix 39 psFree(kernel); 40 float factor = psImageCovarianceFactor(newCovar); // Variance factor 41 psFree(newCovar); 42 43 psImageMaskType maskVal = psMetadataLookupImageMask(NULL, recipe, "MASK.PSPHOT"); // Value to mask 44 45 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics for variance 46 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator 47 if (!psImageBackground(stats, NULL, ro->variance, ro->mask, maskVal, rng) || 48 !isfinite(stats->robustMedian)) { 49 psError(PSPHOT_ERR_DATA, false, "Unable to determine mean variance"); 50 psFree(stats); 51 psFree(rng); 52 return NAN; 53 } 54 psFree(rng); 55 float meanVar = stats->robustMedian; // Mean variance 56 psFree(stats); 57 58 float thresh = psMetadataLookupF32(NULL, recipe, "PEAKS_NSIGMA_LIMIT_2"); 59 if (!isfinite(thresh)) { 60 psError(PSPHOT_ERR_CONFIG, false, "Unable to find threshold"); 61 return NAN; 62 } 63 64 return thresh * sqrtf(meanVar * factor); // Limiting peak flux in smoothed image 65 } 9 66 10 67
Note:
See TracChangeset
for help on using the changeset viewer.
