Changeset 2186 for trunk/src/STMath.cpp


Ignore:
Timestamp:
06/07/11 23:49:53 (13 years ago)
Author:
WataruKawasaki
Message:

New Development: Yes

JIRA Issue: Yes CAS-3149

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: scantable.*sinusoid_baseline() params

Test Programs:

Put in Release Notes: Yes

Module(s):

Description: (1) Implemented an automated sinusoidal fitting functionality

(2) FFT available with scantable.fft()
(3) fixed a bug of parsing 'edge' param used by linefinder.
(4) a function to show progress status for row-based iterations.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STMath.cpp

    r2177 r2186  
    4949#include <atnf/PKSIO/SrcType.h>
    5050
    51 #include "MathUtils.h"
    5251#include "RowAccumulator.h"
    5352#include "STAttr.h"
     
    28272826  std::vector<float> res;
    28282827  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;
    28322829
    28332830  if (whichrow.size() < 1) {          // for all rows (by default)
    28342831    int nrow = int(tab.nrow());
    28352832    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);
    28392834    }
    28402835  } else {                           // for specified rows
    28412836    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);
    28452838    }
    28462839  }
     
    28492842}
    28502843
    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 spectral
    2893     //     values with the mean of those at the two channels just outside
    2894     //     the both edges of the masked region.
    2895     // (2) for a masked region at the spectral edge, replace the values
    2896     //     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 }
    29172844
    29182845CountedPtr<Scantable>
     
    29392866      Vector<Float> spec = specCol(i);
    29402867      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);
    29422873
    29432874      Vector<Complex> lags;
Note: See TracChangeset for help on using the changeset viewer.