Changeset 167


Ignore:
Timestamp:
12/27/04 22:14:55 (19 years ago)
Author:
kil064
Message:

Reimplement 'bin' with insitu version as well

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r166 r167  
    8989        return
    9090       
    91 def bin(scan, binwidth=5):
     91def bin(scan, width=5, insitu=False):
    9292    """
     93    Return a scan where all spectra have been binned up
     94        width        The bin width (default=5) in pixels
     95        insitu:      if False (default) a new scantable is returned.
     96                     Otherwise, the addition is done in-situ
    9397    """
    94     from asap._asap import bin as _bin
    95     return scantable(_bin(scan, binwidth))
     98    if not insitu:
     99        from asap._asap import bin as _bin
     100        return scantable(_bin(scan, width))
     101    else:
     102        from asap._asap import bin_insitu as _bin
     103        _bin(scan, width)
     104        return
    96105
    97106def average_pol(scan, mask=None, insitu=False):
  • trunk/src/SDMath.cc

    r165 r167  
    462462}
    463463
    464 CountedPtr<SDMemTable> SDMath::bin(const CountedPtr<SDMemTable>& in,
    465                                    Int width)
    466 {
    467   SDHeader sh = in->getSDHeader();
    468   SDMemTable* sdmt = new SDMemTable(*in,True);
    469 
    470 // Bin up SpectralCoordinates
    471 
    472   IPosition factors(1);
    473   factors(0) = width;
    474   for (uInt j=0; j<in->nCoordinates(); ++j) {
    475     CoordinateSystem cSys;
    476     cSys.addCoordinate(in->getCoordinate(j));
    477     CoordinateSystem cSysBin =
    478       CoordinateUtil::makeBinnedCoordinateSystem (factors, cSys, False);
    479 //
    480     SpectralCoordinate sCBin = cSysBin.spectralCoordinate(0);
    481     sdmt->setCoordinate(sCBin, j);
    482   }
    483 
    484 // Use RebinLattice to find shape
    485 
    486   IPosition shapeIn(1,sh.nchan);
    487   IPosition shapeOut = RebinLattice<Float>::rebinShape (shapeIn, factors);
    488   sh.nchan = shapeOut(0);
    489   sdmt->putSDHeader(sh);
    490 
    491 
    492 // Loop over rows and bin along channel axis
    493  
    494   const uInt axis = 3;
    495   for (uInt i=0; i < in->nRow(); ++i) {
    496     SDContainer sc = in->getSDContainer(i);
    497 //
    498     Array<Float> tSys(sc.getTsys());                           // Get it out before sc changes shape
    499 
    500 // Bin up spectrum
    501 
    502     MaskedArray<Float> marr(in->rowAsMaskedArray(i));
    503     MaskedArray<Float> marrout;
    504     LatticeUtilities::bin(marrout, marr, axis, width);
    505 
    506 // Put back the binned data and flags
    507 
    508     IPosition ip2 = marrout.shape();
    509     sc.resize(ip2);
    510 //
    511     putDataInSDC (sc, marrout.getArray(), marrout.getMask());
    512 
    513 // Bin up Tsys. 
    514 
    515     Array<Bool> allGood(tSys.shape(),True);
    516     MaskedArray<Float> tSysIn(tSys, allGood, True);
    517 //
    518     MaskedArray<Float> tSysOut;   
    519     LatticeUtilities::bin(tSysOut, tSysIn, axis, width);
    520     sc.putTsys(tSysOut.getArray());
    521 //
    522     sdmt->putSDContainer(sc);
    523   }
    524   return CountedPtr<SDMemTable>(sdmt);
    525 }
     464
     465void SDMath::binInSitu (SDMemTable* pIn, int width)
     466{
     467  const uInt what = 1;
     468  SDMemTable* pOut = localBin (*pIn, Int(width));
     469  *pIn = *pOut;
     470   delete pOut;
     471
     472
     473
     474CountedPtr<SDMemTable> SDMath::bin (const CountedPtr<SDMemTable>& in, int width)
     475{
     476  const uInt what = 1;
     477  return CountedPtr<SDMemTable>(localBin(*in, Int(width)));
     478}
     479
    526480
    527481
     
    866820//
    867821  const Bool useMask = (mask.nelements() == shapeIn(chanAxis));
    868 cerr << "nEl=" << mask.nelements() << endl;
    869 cerr << "useMask=" << useMask << endl;
    870822
    871823// Loop over rows
     
    962914  return pTabOut;
    963915}
     916
     917SDMemTable* SDMath::localBin (const SDMemTable& in, Int width)
     918{
     919  SDHeader sh = in.getSDHeader();
     920  SDMemTable* pTabOut = new SDMemTable(in, True);
     921
     922// Bin up SpectralCoordinates
     923
     924  IPosition factors(1);
     925  factors(0) = width;
     926  for (uInt j=0; j<in.nCoordinates(); ++j) {
     927    CoordinateSystem cSys;
     928    cSys.addCoordinate(in.getCoordinate(j));
     929    CoordinateSystem cSysBin =
     930      CoordinateUtil::makeBinnedCoordinateSystem (factors, cSys, False);
     931//
     932    SpectralCoordinate sCBin = cSysBin.spectralCoordinate(0);
     933    pTabOut->setCoordinate(sCBin, j);
     934  }
     935
     936// Use RebinLattice to find shape
     937
     938  IPosition shapeIn(1,sh.nchan);
     939  IPosition shapeOut = RebinLattice<Float>::rebinShape (shapeIn, factors);
     940  sh.nchan = shapeOut(0);
     941  pTabOut->putSDHeader(sh);
     942
     943
     944// Loop over rows and bin along channel axis
     945 
     946  const uInt axis = 3;
     947  for (uInt i=0; i < in.nRow(); ++i) {
     948    SDContainer sc = in.getSDContainer(i);
     949//
     950    Array<Float> tSys(sc.getTsys());                           // Get it out before sc changes shape
     951
     952// Bin up spectrum
     953
     954    MaskedArray<Float> marr(in.rowAsMaskedArray(i));
     955    MaskedArray<Float> marrout;
     956    LatticeUtilities::bin(marrout, marr, axis, width);
     957
     958// Put back the binned data and flags
     959
     960    IPosition ip2 = marrout.shape();
     961    sc.resize(ip2);
     962//
     963    putDataInSDC (sc, marrout.getArray(), marrout.getMask());
     964
     965// Bin up Tsys. 
     966
     967    Array<Bool> allGood(tSys.shape(),True);
     968    MaskedArray<Float> tSysIn(tSys, allGood, True);
     969//
     970    MaskedArray<Float> tSysOut;   
     971    LatticeUtilities::bin(tSysOut, tSysIn, axis, width);
     972    sc.putTsys(tSysOut.getArray());
     973//
     974    pTabOut->putSDContainer(sc);
     975  }
     976  return pTabOut;
     977}
     978
     979
  • trunk/src/SDMath.h

    r165 r167  
    6666// Bin up
    6767
    68   casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in,
    69                                   casa::Int width);
     68  void binInSitu (SDMemTable* in, casa::Int width);
     69  casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in, casa::Int width);
    7070
    7171// Average in time
     
    144144
    145145  SDMemTable* localAveragePol(const SDMemTable& in, const casa::Vector<casa::Bool>& mask);
     146
     147// Function to bin up spectra
     148
     149  SDMemTable* localBin (const SDMemTable& in, casa::Int width);
    146150};
    147151
  • trunk/src/SDMathWrapper.h

    r165 r167  
    5656  void scaleInSitu(SDMemTableWrapper& in, casa::Float factor, casa::Bool all)
    5757  {
    58     SDMemTable* sdmt = in.getPtr();
    5958    SDMath::multiplyInSitu(in.getPtr(),factor, all);
    6059  }
     
    6968  void addInSitu(SDMemTableWrapper& in, casa::Float offset, casa::Bool all)
    7069  {
    71     SDMemTable* sdmt = in.getPtr();
    7270    SDMath::addInSitu(in.getPtr(), offset, all);
    7371  }
     
    8583// Bin up
    8684
    87   SDMemTableWrapper bin(const SDMemTableWrapper& in,
    88                         int width) {
    89     return SDMath::bin(in.getCP(), width);
     85  void binInSitu (SDMemTableWrapper& in, int width)
     86  {
     87    SDMath::binInSitu (in.getPtr(), width);
     88  }
     89  SDMemTableWrapper bin(const SDMemTableWrapper& in, int width)
     90  {
     91    return SDMemTableWrapper(SDMath::bin(in.getCP(), width));
    9092  }
    9193
  • trunk/src/python_SDMath.cc

    r165 r167  
    6262    void python_SDMath() {
    6363      def("quotient", &SDMathWrapper::quotient);
     64//
    6465      def("scale", &SDMathWrapper::scale);
    6566      def("scale_insitu", &SDMathWrapper::scaleInSitu);
     67//
    6668      def("add", &SDMathWrapper::add);
    6769      def("add_insitu", &SDMathWrapper::addInSitu);
     70//
    6871      def("hanning", &SDMathWrapper::hanning);
     72//
    6973      def("average", &SDMathWrapper::average);
     74//
    7075      def("averagepol", &SDMathWrapper::averagePol);
    7176      def("averagepol_insitu", &SDMathWrapper::averagePolInSitu);
     77//
    7278      def("bin", &SDMathWrapper::bin);
     79      def("bin_insitu", &SDMathWrapper::binInSitu);
     80//
    7381      def("stats", &SDMathWrapper::statistic);
    7482    };
Note: See TracChangeset for help on using the changeset viewer.