Changeset 38 for trunk/src


Ignore:
Timestamp:
07/07/04 18:48:56 (20 years ago)
Author:
mmarquar
Message:

Added baseline and hanning functions. Also added copying of scanid and freqid.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r15 r38  
    2929//# $Id:
    3030//#---------------------------------------------------------------------------
     31#include <vector>
     32
    3133#include <aips/aips.h>
    3234#include <aips/Utilities/String.h>
    3335#include <aips/Arrays/IPosition.h>
    3436#include <aips/Arrays/Array.h>
     37#include <aips/Arrays/ArrayAccessor.h>
     38#include <aips/Arrays/Slice.h>
    3539#include <aips/Arrays/ArrayMath.h>
    3640#include <aips/Arrays/ArrayLogical.h>
     
    4347#include <aips/Tables/ArrayColumn.h>
    4448
     49#include <aips/Fitting.h>
     50#include <trial/Fitting/LinearFit.h>
     51#include <trial/Functionals/CompiledFunction.h>
     52#include <aips/Mathematics/AutoDiff.h>
     53#include <aips/Mathematics/AutoDiffMath.h>
     54
     55#include "MathUtils.h"
    4556#include "SDContainer.h"
    4657#include "SDMemTable.h"
     
    5667  ROScalarColumn<String> srcn(t, "SRCNAME");
    5768  ROScalarColumn<Double> integr(t, "INTERVAL");
     69  ROArrayColumn<uInt> freqidc(t, "FREQID");
    5870  IPosition ip = in->rowAsMaskedArray(0).shape();
    5971  Array<Float> outarr(ip); outarr =0.0;
     
    95107  String tstr; srcn.getScalar(0,tstr);// get sourcename of "mid" point
    96108  sc.sourcename = tstr;
     109  Vector<uInt> tvec;
     110  freqidc.get(0,tvec);
     111  sc.putFreqMap(tvec);
     112  sc.scanid = 0;
    97113  sc.putSpectrum(outarr);
    98114  sc.putFlags(outflags); 
     
    112128  ROScalarColumn<Double> integr(ton, "INTERVAL");
    113129  ROScalarColumn<String> srcn(ton, "SRCNAME");
     130  ROArrayColumn<uInt> freqidc(ton, "FREQID");
     131
    114132  MaskedArray<Float> mon(on->rowAsMaskedArray(0));
    115133  MaskedArray<Float> moff(off->rowAsMaskedArray(0));
     
    137155  integr.getScalar(0,tme);
    138156  sc.interval = tme;
     157  Vector<uInt> tvec;
     158  freqidc.get(0,tvec);
     159  sc.putFreqMap(tvec);
     160  sc.scanid = 0;
    139161  sc.putSpectrum(out);
    140162  sc.putFlags(outflags); 
     
    158180  return CountedPtr<SDMemTable>(sdmt);
    159181}
     182static std::vector<float> SDMath::baseline(const CountedPtr<SDMemTable>& in,
     183                                           const std::string& fitexpr) {
     184  cout << "Fitting: " << fitexpr << endl;
     185  Table t = in->table();
     186  LinearFit<Float> fitter;
     187  Vector<Float> y;
     188  in->getSpectrum(y, 0);
     189  Vector<Bool> m;
     190  in->getMask(m, 0);
     191  Vector<Float> x(y.nelements());
     192  indgen(x);
     193  CompiledFunction<AutoDiff<Float> > fn;
     194  fn.setFunction(String(fitexpr));
     195  fitter.setFunction(fn);
     196  Vector<Float> out,out1;
     197  out = fitter.fit(x,y,&m);
     198  out1 = y;
     199  fitter.residual(out1,x);
     200  cout << "solution =" << out << endl;
     201  std::vector<float> fitted;
     202  out1.tovector(fitted);
     203  return fitted;
     204}
     205
     206
     207static CountedPtr<SDMemTable>
     208SDMath::hanning(const CountedPtr<SDMemTable>& in) {
     209  IPosition ip = in->rowAsMaskedArray(0).shape();
     210  MaskedArray<Float> marr(in->rowAsMaskedArray(0));
     211
     212  Array<Float> arr = marr.getArray();
     213  Array<Bool> barr = marr.getMask();
     214  for (uInt i=0; i<in->nBeam();++i) {
     215    for (uInt j=0; j<in->nIF();++j) {
     216      for (uInt k=0; k<in->nPol();++k) {
     217        IPosition start(4,i,j,k,0);
     218        IPosition end(4,i,j,k,in->nChan()-1);
     219        Array<Float> subArr(arr(start,end));
     220        Array<Bool> subMask(barr(start,end));
     221        Vector<Float> outv;
     222        Vector<Bool> outm;
     223        Vector<Float> v(subArr.nonDegenerate());
     224        Vector<Bool> m(subMask.nonDegenerate());
     225        ::hanning(outv,outm,v,m);
     226        ArrayAccessor<Float, Axis<0> > aa0(outv);       
     227        ArrayAccessor<Bool, Axis<0> > ba0(outm);       
     228        ArrayAccessor<Bool, Axis<3> > ba(subMask);     
     229        for (ArrayAccessor<Float, Axis<3> > aa(subArr); aa != aa.end();++aa) {
     230          (*aa) = (*aa0);
     231          (*ba) = (*ba0);
     232          aa0++;
     233          ba0++;
     234          ba++;
     235        }
     236      }
     237    }
     238  }
     239  Array<uChar> outflags(barr.shape());
     240  convertArray(outflags,!barr);
     241  SDContainer sc = in->getSDContainer();
     242  sc.putSpectrum(arr);
     243  sc.putFlags(outflags);
     244  SDMemTable* sdmt = new SDMemTable(*in,True);
     245  sdmt->putSDContainer(sc);
     246  return CountedPtr<SDMemTable>(sdmt);
     247}
     248
    160249/*
    161250static Float SDMath::rms(const SDMemTable& in, uInt whichRow) {
  • trunk/src/SDMath.h

    r15 r38  
    3232#define _SDMATH_H_
    3333
     34#include <string>
     35#include <vector>
    3436#include <aips/Utilities/CountedPtr.h>
    3537
     
    4648                                         Float factor);
    4749 
     50  static std::vector<float> baseline(const CountedPtr<SDMemTable>& in,
     51                                     const std::string& fitexpr );
     52  static CountedPtr<SDMemTable> hanning(const CountedPtr<SDMemTable>& in);
    4853 
    4954};
    50 
    5155} // namespace
    5256
Note: See TracChangeset for help on using the changeset viewer.