Changeset 1373 for trunk/src/STMath.cpp


Ignore:
Timestamp:
07/12/07 11:43:56 (17 years ago)
Author:
mar637
Message:

Added running median to smooth. This addresses Ticket #115

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STMath.cpp

    r1336 r1373  
    10071007}
    10081008
     1009CountedPtr< Scantable > STMath::smoothOther( const CountedPtr< Scantable >& in,
     1010                                             const std::string& kernel,
     1011                                             float width )
     1012{
     1013  CountedPtr< Scantable > out = getScantable(in, false);
     1014  Table& table = out->table();
     1015  ArrayColumn<Float> specCol(table, "SPECTRA");
     1016  ArrayColumn<uChar> flagCol(table, "FLAGTRA");
     1017  Vector<Float> spec;
     1018  Vector<uChar> flag;
     1019  for ( uInt i=0; i<table.nrow(); ++i) {
     1020    specCol.get(i, spec);
     1021    flagCol.get(i, flag);
     1022    Vector<Bool> mask(flag.nelements());
     1023    convertArray(mask, flag);
     1024    Vector<Float> specout;
     1025    Vector<Bool> maskout;
     1026    if ( kernel == "hanning" ) {
     1027      mathutil::hanning(specout, maskout, spec , !mask);
     1028      convertArray(flag, !maskout);
     1029    } else if (  kernel == "rmedian" ) {
     1030      mathutil::runningMedian(specout, maskout, spec , mask, width);
     1031      convertArray(flag, maskout);
     1032    }
     1033    flagCol.put(i, flag);
     1034    specCol.put(i, specout);
     1035  }
     1036  return out;
     1037}
     1038
    10091039CountedPtr< Scantable > STMath::smooth( const CountedPtr< Scantable >& in,
    10101040                                        const std::string& kernel, float width )
    10111041{
     1042  if (kernel == "rmedian"  || kernel == "hanning") {
     1043    return smoothOther(in, kernel, width);
     1044  }
    10121045  CountedPtr< Scantable > out = getScantable(in, false);
    10131046  Table& table = out->table();
     
    10321065      convertArray(mask, flag);
    10331066      Vector<Float> specout;
    1034       if ( type == VectorKernel::HANNING ) {
    1035         Vector<Bool> maskout;
    1036         mathutil::hanning(specout, maskout, spec , !mask);
    1037         convertArray(flag, !maskout);
    1038         flagCol.put(i, flag);
    1039         specCol.put(i, specout);
    1040      } else {
    1041         mathutil::replaceMaskByZero(specout, mask);
    1042         conv.linearConv(specout, spec);
    1043         specCol.put(i, specout);
    1044       }
     1067      mathutil::replaceMaskByZero(specout, mask);
     1068      conv.linearConv(specout, spec);
     1069      specCol.put(i, specout);
    10451070    }
    10461071    ++iter;
Note: See TracChangeset for help on using the changeset viewer.