Changeset 27838 for branches/tap_branches/psLib/src/fits/psFitsScale.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psLib
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/czw_branch/cleanup/psLib merged eligible /branches/pap/psLib merged eligible /trunk/psLib merged eligible /branches/eam_branches/20090522/psLib 24238-24573 /branches/eam_branches/20090715/psLib 24799-25750 /branches/eam_branches/20090820/psLib 25139-25874 /branches/pap_mops/psLib 25137-25255
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psLib/src/fits/psFitsScale.c
r25439 r27838 15 15 #include "psImage.h" 16 16 #include "psFits.h" 17 #include "psStats.h" 18 #include "psImageStats.h" 17 19 #include "psImageBackground.h" 18 #include "psStats.h"19 20 #include "psImageStructManip.h" 20 21 … … 29 30 #define MEAN_STAT PS_STAT_ROBUST_MEDIAN // Statistic to use for mean 30 31 #define STDEV_STAT PS_STAT_ROBUST_STDEV // Statistic to use for stdev 32 33 #define DESPERATE_MEAN_STAT PS_STAT_SAMPLE_MEDIAN // Statistic to use for mean when deperate 34 #define DESPERATE_STDEV_STAT PS_STAT_SAMPLE_QUARTILE // Statistic to use for stdev when desperate 31 35 32 36 … … 118 122 psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); 119 123 psStats *stats = psStatsAlloc(MEAN_STAT | STDEV_STAT); // Statistics object 124 double mean, stdev; // Mean and standard deviation 120 125 if (!psImageBackground(stats, NULL, image, mask, maskVal, rng)) { 121 psError(PS_ERR_UNKNOWN, false, "Unable to perform statistics on image"); 122 psFree(rng); 123 psFree(stats); 124 return false; 126 // It could be because the image is entirely masked, in which case we don't want to error 127 bool good = false; // Any good pixels? 128 129 130 // Find good pixels in an image, by image type 131 #define GOOD_PIXELS_CASE(TYPE) \ 132 case PS_TYPE_##TYPE: \ 133 for (int y = 0; y < image->numRows && !good; y++) { \ 134 for (int x = 0; x < image->numCols && !good; x++) { \ 135 if (mask && (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal)) { \ 136 continue; \ 137 } \ 138 if (!isfinite(image->data.TYPE[y][x])) { \ 139 continue; \ 140 } \ 141 good = true; \ 142 } \ 143 } \ 144 break; 145 146 switch (image->type.type) { 147 GOOD_PIXELS_CASE(F32); 148 GOOD_PIXELS_CASE(F64); 149 default: 150 psAbort("Unsupported case: %x", image->type.type); 151 } 152 153 if (!good) { 154 psLogMsg("psLib.fits", PS_LOG_DETAIL, "Image has no good pixels, setting BSCALE = 1, BZERO = 0"); 155 psErrorClear(); 156 *bscale = 1.0; 157 *bzero = 0.0; 158 psFree(rng); 159 psFree(stats); 160 return true; 161 } 162 163 // There are some good pixels in there somewhere; psImageBackground just didn't find them 164 psLogMsg("psLib.fits", PS_LOG_DETAIL, 165 "Couldn't measure background statistics for image quantisation; retrying."); 166 psErrorClear(); 167 // Retry using all the available pixels 168 stats->nSubsample = image->numCols * image->numRows + 1; 169 if (!psImageStats(stats, image, mask, maskVal)) { 170 psLogMsg("psLib.fits", PS_LOG_DETAIL, 171 "Couldn't measure background statistics for image quantisation (attempt 2); retrying."); 172 psErrorClear(); 173 // Retry with desperate statistic 174 stats->options = DESPERATE_MEAN_STAT | DESPERATE_STDEV_STAT; 175 if (!psImageStats(stats, image, mask, maskVal)) { 176 psError(PS_ERR_UNKNOWN, false, "Unable to measure background statistics for image"); 177 psFree(rng); 178 psFree(stats); 179 return false; 180 } else { 181 // Desperate retry 182 mean = psStatsGetValue(stats, DESPERATE_MEAN_STAT); 183 stdev = psStatsGetValue(stats, DESPERATE_STDEV_STAT); 184 } 185 } else { 186 // Retry with all available pixels 187 mean = psStatsGetValue(stats, MEAN_STAT); 188 stdev = psStatsGetValue(stats, STDEV_STAT); 189 } 190 } else { 191 // First attempt 192 mean = psStatsGetValue(stats, MEAN_STAT); 193 stdev = psStatsGetValue(stats, STDEV_STAT); 125 194 } 126 195 psFree(rng); 127 128 double mean = psStatsGetValue(stats, MEAN_STAT); // Mean129 double stdev = psStatsGetValue(stats, STDEV_STAT); // Standard deviation130 196 psFree(stats); 131 197 if (!isfinite(mean) || !isfinite(stdev)) { … … 318 384 } else { \ 319 385 value = (value - zero) * scale; \ 320 if (options->fuzz ) { \386 if (options->fuzz && (value - (int)value != 0.0)) { \ 321 387 /* Add random factor [-0.5,0.5): adds a variance of 1/12, */ \ 322 388 /* but preserves the expectation value */ \
Note:
See TracChangeset
for help on using the changeset viewer.
