Changeset 2186 for trunk/src/STMath.cpp
- Timestamp:
- 06/07/11 23:49:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STMath.cpp
r2177 r2186 49 49 #include <atnf/PKSIO/SrcType.h> 50 50 51 #include "MathUtils.h"52 51 #include "RowAccumulator.h" 53 52 #include "STAttr.h" … … 2827 2826 std::vector<float> res; 2828 2827 Table tab = in->table(); 2829 ArrayColumn<Float> specCol(tab, "SPECTRA"); 2830 ArrayColumn<uChar> flagCol(tab, "FLAGTRA"); 2831 FFTServer<Float,Complex> ffts; 2828 std::vector<bool> mask; 2832 2829 2833 2830 if (whichrow.size() < 1) { // for all rows (by default) 2834 2831 int nrow = int(tab.nrow()); 2835 2832 for (int i = 0; i < nrow; ++i) { 2836 Vector<Float> spec = specCol(i); 2837 Vector<uChar> flag = flagCol(i); 2838 doFFT(res, ffts, getRealImag, spec, flag); 2833 res = in->execFFT(i, mask, getRealImag); 2839 2834 } 2840 2835 } else { // for specified rows 2841 2836 for (uInt i = 0; i < whichrow.size(); ++i) { 2842 Vector<Float> spec = specCol(whichrow[i]); 2843 Vector<uChar> flag = flagCol(whichrow[i]); 2844 doFFT(res, ffts, getRealImag, spec, flag); 2837 res = in->execFFT(i, mask, getRealImag); 2845 2838 } 2846 2839 } … … 2849 2842 } 2850 2843 2851 void asap::STMath::doFFT( std::vector<float>& out,2852 FFTServer<Float,Complex>& ffts,2853 bool getRealImag,2854 Vector<Float>& spec,2855 Vector<uChar>& flag )2856 {2857 doZeroOrderInterpolation(spec, flag);2858 2859 Vector<Complex> fftout;2860 ffts.fft0(fftout, spec);2861 2862 float norm = float(2.0/double(spec.size()));2863 if (getRealImag) {2864 for (uInt j = 0; j < fftout.size(); ++j) {2865 out.push_back(real(fftout[j])*norm);2866 out.push_back(imag(fftout[j])*norm);2867 }2868 } else {2869 for (uInt j = 0; j < fftout.size(); ++j) {2870 out.push_back(abs(fftout[j])*norm);2871 out.push_back(arg(fftout[j]));2872 }2873 }2874 2875 }2876 2877 void asap::STMath::doZeroOrderInterpolation( Vector<Float>& spec,2878 Vector<uChar>& flag )2879 {2880 int fstart = -1;2881 int fend = -1;2882 for (uInt i = 0; i < flag.nelements(); ++i) {2883 if (flag[i] > 0) {2884 fstart = i;2885 while (flag[i] > 0 && i < flag.nelements()) {2886 fend = i;2887 i++;2888 }2889 }2890 2891 // execute interpolation as the following criteria:2892 // (1) for a masked region inside the spectrum, replace the spectral2893 // values with the mean of those at the two channels just outside2894 // the both edges of the masked region.2895 // (2) for a masked region at the spectral edge, replace the values2896 // with the one at the nearest non-masked channel.2897 // (ZOH, but bilateral)2898 Float interp = 0.0;2899 if (fstart-1 > 0) {2900 interp = spec[fstart-1];2901 if (fend+1 < Int(spec.nelements())) {2902 interp = (interp + spec[fend+1]) / 2.0;2903 }2904 } else {2905 interp = spec[fend+1];2906 }2907 if (fstart > -1 && fend > -1) {2908 for (int j = fstart; j <= fend; ++j) {2909 spec[j] = interp;2910 }2911 }2912 2913 fstart = -1;2914 fend = -1;2915 }2916 }2917 2844 2918 2845 CountedPtr<Scantable> … … 2939 2866 Vector<Float> spec = specCol(i); 2940 2867 Vector<uChar> flag = flagCol(i); 2941 doZeroOrderInterpolation(spec, flag); 2868 std::vector<bool> mask; 2869 for (uInt j = 0; j < flag.nelements(); ++j) { 2870 mask.push_back(!(flag[j]>0)); 2871 } 2872 mathutil::doZeroOrderInterpolation(spec, mask); 2942 2873 2943 2874 Vector<Complex> lags;
Note: See TracChangeset
for help on using the changeset viewer.