Changeset 26868
- Timestamp:
- Feb 10, 2010, 4:08:49 PM (16 years ago)
- Location:
- branches/eam_branches/20091201/psLib/src
- Files:
-
- 4 edited
-
fits/psFitsTable.c (modified) (1 diff)
-
imageops/psImageBackground.c (modified) (4 diffs)
-
imageops/psImageBackground.h (modified) (1 diff)
-
math/psStats.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/psLib/src/fits/psFitsTable.c
r24512 r26868 162 162 163 163 switch (typecode) { 164 // TBYTE and TSHORT fall though to read into psS32 164 165 case TBYTE: 165 166 case TSHORT: 166 case TLONGLONG:167 167 READ_TABLE_ROW_CASE(TLONG, long, S32, S32); 168 READ_TABLE_ROW_CASE(TLONGLONG, long, S64, S64); 168 169 READ_TABLE_ROW_CASE(TFLOAT, float, F32, F32); 169 170 READ_TABLE_ROW_CASE(TDOUBLE, double, F64, F64); -
branches/eam_branches/20091201/psLib/src/imageops/psImageBackground.c
r24481 r26868 15 15 #include "psRandom.h" 16 16 #include "psError.h" 17 18 static int nFailures = 0; 19 20 void psImageBackgroundInit() { 21 nFailures = 0; 22 return; 23 } 17 24 18 25 // XXX allow the user to choose the stats method? … … 91 98 } 92 99 if (n < 0.01*Nsubset) { 93 psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, 94 "Unable to measure image background: too few data points (%ld)", n); 100 if ((nFailures < 3) || (nFailures % 100 == 0)) { 101 psLogMsg("psLib.psImageBackground", PS_LOG_DETAIL, "Unable to measure image background: too few data points (%ld) (%d failures)", n, nFailures); 102 } 103 nFailures ++; 95 104 psFree(values); 96 105 return false; … … 108 117 109 118 if (!psVectorSort(values, values)) { 110 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.\n"); 119 if ((nFailures < 3) || (nFailures % 100 == 0)) { 120 psError(PS_ERR_UNKNOWN, false, "Unable to sort values.(%d failures)\n", nFailures); 121 } 122 nFailures ++; 111 123 psFree(values); 112 124 return false; … … 132 144 fclose (f); 133 145 } 134 psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background " 135 "(%dx%d, (row0,col0) = (%d,%d)", 136 image->numRows, image->numCols, image->row0, image->col0); 146 if ((nFailures < 3) || (nFailures % 100 == 0)) { 147 psError(PS_ERR_UNKNOWN, false, "Unable to measure statistics for image background " 148 "(%dx%d, (row0,col0) = (%d,%d) (%d failures)\n", 149 image->numRows, image->numCols, image->row0, image->col0, nFailures); 150 } 151 nFailures ++; 137 152 psFree(values); 138 153 return false; -
branches/eam_branches/20091201/psLib/src/imageops/psImageBackground.h
r21183 r26868 22 22 #include <psRandom.h> 23 23 24 void psImageBackgroundInit(); 25 24 26 // Get the background for an image 25 27 bool psImageBackground(psStats *stats, // desired measurement and options -
branches/eam_branches/20091201/psLib/src/math/psStats.c
r25884 r26868 749 749 // Iterate to get the best bin size; an iteration limit is enforced at the bottom of the loop. 750 750 for (int iterate = 1; iterate > 0; iterate++) { 751 psTrace(TRACE, 6, 752 "-------------------- Iterating on Bin size. Iteration number %d --------------------\n", 753 iterate); 751 psTrace(TRACE, 6, "-------------------- Iterating on Bin size. Iteration number %d --------------------\n", iterate); 752 753 if (iterate >= PS_ROBUST_MAX_ITERATIONS) { 754 // This occurs when a large number of the values are identical --- a bin size cannot be found 755 // that will spread out the distribution. Therefore, set what we can, and fall over 756 // gracefully. 757 COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS); 758 goto escape; 759 } 754 760 755 761 // Get the minimum and maximum values … … 791 797 psTrace(TRACE, 6, "Initial robust bin size is %.2f\n", binSize); 792 798 793 // ADD step 0: Construct the histogram with the specified bin size. NOTE: we can not specify the bin 794 // size precisely since the argument to psHistogramAlloc() is the number of bins, not the binSize. If 795 // we get here, we know that binSize != 0.0. 796 long numBins = (max - min) / binSize; // Number of bins 799 // ADD step 0: Construct the histogram with the specified bin size. NOTE: we can 800 // not specify the bin size precisely since the argument to psHistogramAlloc() is 801 // the number of bins, not the binSize. If we get here, we know that binSize != 802 // 0.0. We can also have a floating-point round-off error such that the last bin 803 // of the histogram does not correspond exactly with the value of 'max'. Let's be 804 // a bit generous and extend the histogram by two bins in either direction 805 long numBins = 4 + (max - min) / binSize; // Number of bins 797 806 psTrace(TRACE, 6, "Numbins is %ld\n", numBins); 798 807 psTrace(TRACE, 6, "Creating a robust histogram from data range (%.2f - %.2f)\n", min, max); 799 808 // Generate the histogram 800 histogram = psHistogramAlloc(min , max, numBins);809 histogram = psHistogramAlloc(min - 2.0*binSize, max + 2.0*binSize, numBins); 801 810 // XXXXX we need to consider this step if errors -> variance 802 811 if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) { … … 807 816 psFree(statsMinMax); 808 817 psFree(mask); 809 810 818 return false; 811 819 } … … 814 822 PS_VECTOR_PRINT_F32(histogram->nums); 815 823 } 824 825 // perversity check: if most of the values land in a single bin, then we probably 826 // have a perverse case (eg, small number of points at extremely large / small 827 // values; nearly bi-modal distribution). if so, keep only points within 5? 10? 828 // bins of that excess bin: 829 int nMaxBin = 0; 830 int iMaxBin = 0; 831 for (long i = 1; i < histogram->nums->n; i++) { 832 if (histogram->nums->data.F32[i] > nMaxBin) { 833 nMaxBin = histogram->nums->data.F32[i]; 834 iMaxBin = i; 835 } 836 } 837 if (nMaxBin > numValid / 2) { 838 float minKeep = histogram->bounds->data.F32[iMaxBin] - 10*binSize; 839 float maxKeep = histogram->bounds->data.F32[iMaxBin + 1] + 10*binSize; 840 int nInvalid = 0; 841 for (long i = 0; i < myVector->n; i++) { 842 // skip the already-masked values 843 if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskVal) continue; 844 bool invalid = false; 845 invalid |= (myVector->data.F32[i] <= minKeep); 846 invalid |= (myVector->data.F32[i] >= maxKeep); 847 invalid |= (!isfinite(myVector->data.F32[i])); 848 if (!invalid) continue; 849 mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal; 850 nInvalid ++; 851 } 852 853 if (nInvalid) { 854 psTrace(TRACE, 6, "data is concentrated in a single bin, masking %d extreme outliers and retrying\n", nInvalid); 855 psFree(histogram); 856 psFree(cumulative); 857 histogram = NULL; 858 cumulative = NULL; 859 continue; 860 } 861 // if we did not mask anything, give up. 862 } 816 863 817 864 // ADD step 1: Convert the specific histogram to a cumulative histogram … … 1007 1054 stats->robustN50 = N50; 1008 1055 psTrace(TRACE, 6, "The robustN50 is %ld.\n", N50); 1056 psTrace(TRACE, 6, "The robust median and stdev are %f, %f\n", stats->robustMedian, stats->robustStdev); 1009 1057 1010 1058 // Clean up
Note:
See TracChangeset
for help on using the changeset viewer.
