Changeset 177


Ignore:
Timestamp:
01/07/05 11:18:33 (19 years ago)
Author:
kil064
Message:

remove function 'hanning'
add function 'smooth' (includes hanning)

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r175 r177  
    4242#include <casa/Arrays/MaskArrMath.h>
    4343#include <casa/Arrays/MaskArrLogi.h>
     44#include <casa/Utilities/Assert.h>
    4445#include <casa/Exceptions.h>
     46
     47#include <scimath/Mathematics/VectorKernel.h>
     48#include <scimath/Mathematics/Convolver.h>
    4549
    4650#include <tables/Tables/Table.h>
     
    8488
    8589CountedPtr<SDMemTable> SDMath::average (const Block<CountedPtr<SDMemTable> >& in,
    86                                         const Vector<Bool>& mask, bool scanAv,
     90                                        const Vector<Bool>& mask, Bool scanAv,
    8791                                        const std::string& weightStr)
    8892//
     
    391395
    392396
    393 SDMemTable* SDMath::hanning(const SDMemTable& in, Bool doAll)
    394 //
    395 // Hanning smooth each row
    396 // Should Tsys be smoothed ?
    397 //
    398 {
    399 
    400 // New Table
    401 
    402   SDMemTable* pTabOut = new SDMemTable(in,True);
    403 
    404 // Get cursor location
    405          
    406   IPosition start, end;
    407   getCursorLocation (start, end, in);
    408 //
    409   const uInt chanAxis = 3;                    // Spectrum axis
    410   IPosition shapeOut(4,1);
    411 
    412 // Loop over rows in Table
    413 
    414   for (uInt ri=0; ri < in.nRow(); ++ri) {
    415 
    416 // Get copy of data
    417    
    418     const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri));
    419     Array<Float> valuesIn = dataIn.getArray();
    420     Array<Bool> maskIn = dataIn.getMask();
    421 
    422 // Smooth along the channels axis
    423 
    424     Vector<Float> outValues;
    425     Vector<Bool> outMask;
    426     if (doAll) {
    427        uInt axis = 3;
    428        VectorIterator<Float> itValues(valuesIn, axis);
    429        VectorIterator<Bool> itMask(maskIn, axis);
    430        while (!itValues.pastEnd()) {
    431           mathutil::hanning(outValues, outMask, itValues.vector(), itMask.vector());
    432           itValues.vector() = outValues;
    433           itMask.vector() = outMask;
    434 //
    435           itValues.next();
    436           itMask.next();
    437        }
    438     } else {
    439 
    440 // Set multi-dim Vector shape
    441 
    442        shapeOut(chanAxis) = valuesIn.shape()(chanAxis);
    443 
    444 // Stuff about with shapes so that we don't have conformance run-time errors
    445 
    446        Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate();
    447        Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate();
    448        mathutil::hanning(outValues, outMask, valuesIn2, maskIn2);
    449 
    450 // Write back
    451 
    452        valuesIn(start,end) = outValues.reform(shapeOut);
    453        maskIn(start,end) = outMask.reform(shapeOut);
    454     }
    455 
    456 // Create and put back
    457 
    458     SDContainer sc = in.getSDContainer(ri);
    459     putDataInSDC (sc, valuesIn, maskIn);
    460 //
    461     pTabOut->putSDContainer(sc);
    462   }
    463 //
    464   return pTabOut;
    465 }
    466 
    467 
    468 
    469 
    470397std::vector<float> SDMath::statistic (const CountedPtr<SDMemTable>& in,
    471                                        const std::vector<bool>& mask,
    472                                        const std::string& which)
     398                                      const std::vector<bool>& mask,
     399                                      const String& which)
    473400//
    474401// Perhaps iteration over pol/beam/if should be in here
     
    779706  return pTabOut;
    780707}
     708
     709
     710SDMemTable* SDMath::smooth (const SDMemTable& in, const casa::String& kernelType,
     711                            casa::Float width, Bool doAll)
     712{
     713
     714// Number of channels
     715
     716   const uInt chanAxis = 3;                                     // Spectral axis
     717   SDHeader sh = in.getSDHeader();
     718   const uInt nChan = sh.nchan;
     719
     720// Generate Kernel
     721
     722   VectorKernel::KernelTypes type = VectorKernel::toKernelType (kernelType);
     723   Vector<Float> kernel = VectorKernel::make(type, width, nChan, True, False);
     724
     725// Generate Convolver
     726
     727   IPosition shape(1,nChan);
     728   Convolver<Float> conv(kernel, shape);
     729
     730// New Table
     731
     732   SDMemTable* pTabOut = new SDMemTable(in,True);
     733
     734// Get cursor location
     735         
     736  IPosition start, end;
     737  getCursorLocation (start, end, in);
     738//
     739  IPosition shapeOut(4,1);
     740
     741// Output Vectors
     742
     743  Vector<Float> valuesOut(nChan);
     744  Vector<Bool> maskOut(nChan);
     745
     746// Loop over rows in Table
     747
     748  for (uInt ri=0; ri < in.nRow(); ++ri) {
     749
     750// Get copy of data
     751   
     752    const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri));
     753    AlwaysAssert(dataIn.shape()(chanAxis)==nChan, AipsError);
     754//
     755    Array<Float> valuesIn = dataIn.getArray();
     756    Array<Bool> maskIn = dataIn.getMask();
     757
     758// Branch depending on whether we smooth all locations or just
     759// those pointed at by the current selection cursor
     760
     761    if (doAll) {
     762       uInt axis = 3;
     763       VectorIterator<Float> itValues(valuesIn, axis);
     764       VectorIterator<Bool> itMask(maskIn, axis);
     765       while (!itValues.pastEnd()) {
     766
     767// Smooth
     768          if (kernelType==VectorKernel::HANNING) {
     769             mathutil::hanning(valuesOut, maskOut, itValues.vector(), itMask.vector());
     770             itMask.vector() = maskOut;
     771          } else {
     772             mathutil::replaceMaskByZero(itValues.vector(), itMask.vector());
     773             conv.linearConv(valuesOut, itValues.vector());
     774          }
     775//
     776          itValues.vector() = valuesOut;
     777//
     778          itValues.next();
     779          itMask.next();
     780       }
     781    } else {
     782
     783// Set multi-dim Vector shape
     784
     785       shapeOut(chanAxis) = valuesIn.shape()(chanAxis);
     786
     787// Stuff about with shapes so that we don't have conformance run-time errors
     788
     789       Vector<Float> valuesIn2 = valuesIn(start,end).nonDegenerate();
     790       Vector<Bool> maskIn2 = maskIn(start,end).nonDegenerate();
     791
     792// Smooth
     793
     794       if (kernelType==VectorKernel::HANNING) {
     795          mathutil::hanning(valuesOut, maskOut, valuesIn2, maskIn2);
     796          maskIn(start,end) = maskOut.reform(shapeOut);
     797       } else {
     798          mathutil::replaceMaskByZero(valuesIn2, maskIn2);
     799          conv.linearConv(valuesOut, valuesIn2);
     800       }
     801//
     802       valuesIn(start,end) = valuesOut.reform(shapeOut);
     803    }
     804
     805// Create and put back
     806
     807    SDContainer sc = in.getSDContainer(ri);
     808    putDataInSDC (sc, valuesIn, maskIn);
     809//
     810    pTabOut->putSDContainer(sc);
     811  }
     812//
     813  return pTabOut;
     814}
     815
    781816
    782817
     
    9671002    sc.putFlags(outflags);
    9681003}
    969 
    970 
  • trunk/src/SDMath.h

    r175 r177  
    6161   casa::CountedPtr<SDMemTable>  average(const casa::Block<casa::CountedPtr<SDMemTable> >& in,
    6262                                         const casa::Vector<casa::Bool>& mask,
    63                                          bool scanAverage, const std::string& weightStr);
     63                                         casa::Bool scanAverage, const std::string& weightStr);
    6464
    6565// Statistics
    6666   std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in,
    67                                 const std::vector<bool>& mask, const std::string& which);
    68 
    69 // Hanning
    70    SDMemTable* hanning(const SDMemTable& in, casa::Bool doAll);
     67                                const std::vector<bool>& mask, const casa::String& which);
    7168
    7269// Bin up spectra
    7370   SDMemTable* bin(const SDMemTable& in, casa::Int width);
     71
     72// Smooth
     73   SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel,
     74                       casa::Float width, casa::Bool doAll);
    7475
    7576// Simple mathematical operations.  what=0 (mul) or 1 (add)
     
    124125
    125126   void convertWeightString (WeightType& wt, const std::string& weightStr);
    126 
    127127};
    128128
Note: See TracChangeset for help on using the changeset viewer.