Changeset 349 for trunk/src


Ignore:
Timestamp:
02/02/05 13:11:28 (20 years ago)
Author:
kil064
Message:

rewrite setSpectrum, setFLags and setTsys using Array(start,end)
slice and VectorIterator for access, replacing the ArrayAccessor stuff which
is harder to read. I wouldn't have bothered, but to my surprise,
the new implementation is about 10-20% faster. Need to do the get* methods
too.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDContainer.cc

    r336 r349  
    2929//# $Id:
    3030//#---------------------------------------------------------------------------
     31
    3132#include <casa/aips.h>
    3233#include <casa/iostream.h>
    3334#include <casa/iomanip.h>
    3435#include <casa/Exceptions.h>
     36#include <casa/Utilities/Assert.h>
    3537#include <tables/Tables/Table.h>
    3638#include <casa/Arrays/IPosition.h>
    3739#include <casa/Arrays/Matrix.h>
     40#include <casa/Arrays/VectorIter.h>
    3841#include <casa/Arrays/ArrayAccessor.h>
    3942#include <casa/BasicMath/Math.h>
    4043#include <casa/Quanta/MVTime.h>
     44
    4145
    4246
     
    124128
    125129Bool SDContainer::setSpectrum(const Matrix<Float>& spec,
    126                               uInt whichBeam, uInt whichIF) {
    127 
    128   ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(spectrum_);
    129   aa0.reset(aa0.begin(whichBeam));
    130   ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
    131   aa1.reset(aa1.begin(whichIF));
    132  
    133   //Vector<Float> pols(nPol);
    134   ArrayAccessor<Float, Axis<asap::IFAxis> > j(spec);
    135   IPosition shp0 = spectrum_.shape();
    136   IPosition shp1 = spec.shape();
    137   if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
    138     throw(AipsError("Arrays not conformant"));
    139     return False;
    140   }
    141   // assert dimensions are the same....
    142   for (ArrayAccessor<Float, Axis<asap::PolAxis> > i(aa1);i != i.end(); ++i) {
    143     ArrayAccessor<Float, Axis<asap::BeamAxis> > jj(j);
    144     for (ArrayAccessor<Float, Axis<asap::ChanAxis> > ii(i);ii != ii.end(); ++ii) {
    145       (*ii) = (*jj);
    146       jj++;
    147     }
    148     j++;
    149   }
     130                              uInt whichBeam, uInt whichIF)
     131//
     132// spec is [nChan,nPol]
     133// spectrum_ is [,,,nChan]
     134// How annoying.
     135//
     136{
     137
     138// Get slice and check dim
     139
     140  IPosition start, end;
     141  setSlice (start, end, spec.shape(), spectrum_.shape(),
     142            whichBeam, whichIF, False);
     143
     144// Get a reference to the Pol/Chan slice we are interested in
     145
     146  Array<Float> subArr = spectrum_(start,end);
     147
     148// Iterate through it and fill
     149
     150  ReadOnlyVectorIterator<Float> inIt(spec,0);
     151  VectorIterator<Float> outIt(subArr,asap::ChanAxis);
     152  while (!inIt.pastEnd()) {
     153     outIt.vector() = inIt.vector();
     154//
     155     inIt.next();
     156     outIt.next();
     157  }
     158
    150159  // unset flags for this spectrum, they might be set again by the
    151160  // setFlags method
    152161
    153   IPosition shp = flags_.shape();
    154   IPosition start(4,whichBeam,whichIF,0,0);
    155   IPosition end(4,whichBeam,whichIF,shp(2)-1,shp(3)-1);
    156162  Array<uChar> arr(flags_(start,end));
    157163  arr = uChar(0);
     
    160166}
    161167
    162 Bool SDContainer::setFlags(const Matrix<uChar>& flag,
    163                            uInt whichBeam, uInt whichIF) {
    164 
    165   ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(flags_);
    166   aa0.reset(aa0.begin(whichBeam));
    167   ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
    168   aa1.reset(aa1.begin(whichIF));
    169  
    170   ArrayAccessor<uChar, Axis<asap::IFAxis> > j(flag);
    171   IPosition shp0 = flags_.shape();
    172   IPosition shp1 = flag.shape();
    173   if ( (shp0(2) != shp1(1)) || (shp0(3) != shp1(0)) ) {
    174     cerr << "Arrays not conformant" << endl;     
    175     return False;
    176   }
    177 
    178   // assert dimensions are the same....
    179   for (ArrayAccessor<uChar, Axis<asap::PolAxis> > i(aa1);i != i.end(); ++i) {
    180     ArrayAccessor<uChar, Axis<asap::BeamAxis> > jj(j);
    181     for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > ii(i);ii != ii.end(); ++ii) {
    182       (*ii) = (*jj);
    183       jj++;
    184     }
    185     j++;
    186   }
    187   return True;
    188 }
     168
     169Bool SDContainer::setFlags (const Matrix<uChar>& flags,
     170                            uInt whichBeam, uInt whichIF)
     171//
     172// flags is [nChan,nPol]
     173// flags_ is [,,,nChan]
     174// How annoying.
     175//
     176{
     177// Get slice and check dim
     178
     179  IPosition start, end;
     180  setSlice (start, end, flags.shape(), flags_.shape(),
     181            whichBeam, whichIF, False);
     182
     183// Get a reference to the Pol/Chan slice we are interested in
     184
     185  Array<uChar> subArr = flags_(start,end);
     186
     187// Iterate through it and fill
     188
     189  ReadOnlyVectorIterator<uChar> inIt(flags,0);
     190  VectorIterator<uChar> outIt(subArr,asap::ChanAxis);
     191  while (!inIt.pastEnd()) {
     192     outIt.vector() = inIt.vector();
     193//
     194     inIt.next();
     195     outIt.next();
     196  }
     197//
     198  return True;
     199}
     200
    189201
    190202Bool SDContainer::setTsys(const Vector<Float>& tsys,
    191                           uInt whichBeam, uInt whichIF) {
    192   ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(tsys_);
    193   aa0.reset(aa0.begin(whichBeam));
    194   ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
    195   aa1.reset(aa1.begin(whichIF));
    196   // assert dimensions are the same....
    197   for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa1);i != i.end(); ++i) {   
    198     ArrayAccessor<Float, Axis<asap::BeamAxis> > j(tsys);
    199     for (ArrayAccessor<Float, Axis<asap::PolAxis> > ii(i);ii != ii.end(); ++ii) {
    200       (*ii) = (*j);
    201       j++;
    202     }
     203                          uInt whichBeam, uInt whichIF)
     204//
     205// Tsys does not depend upon channel but is replicated
     206// for simplicity of use
     207//
     208{
     209
     210// Get slice and check dim
     211
     212  IPosition start, end;
     213  setSlice (start, end, tsys.shape(), tsys_.shape(),
     214            whichBeam, whichIF, True);
     215
     216// Get a reference to the Pol/Chan slice we are interested in
     217
     218  Array<Float> subArr = tsys_(start,end);
     219
     220// Iterate through it and fill
     221
     222  VectorIterator<Float> outIt(subArr,asap::ChanAxis);
     223  uInt i=0;
     224  while (!outIt.pastEnd()) {
     225     outIt.vector() = tsys(i++);
     226     outIt.next();
    203227  }
    204228}
     
    361385}
    362386
     387void SDContainer::setSlice (IPosition& start, IPosition& end,
     388                            const IPosition& shpIn, const IPosition& shpOut,
     389                            uInt whichBeam, uInt whichIF, Bool tSys) const
     390//
     391// tSYs
     392//   shpIn [nPol]
     393// else
     394//   shpIn [nCHan,nPol]
     395//
     396{
     397  AlwaysAssert(asap::nAxes==4,AipsError);
     398  if (tSys) {
     399     AlwaysAssert(shpOut(asap::PolAxis)==shpIn(0),AipsError);     // pol
     400  } else {
     401     AlwaysAssert(shpOut(asap::ChanAxis)==shpIn(0),AipsError);    // chan
     402     AlwaysAssert(shpOut(asap::PolAxis)==shpIn(1),AipsError);     // pol
     403  }
     404//
     405  start.resize(asap::nAxes);
     406  start = 0;
     407  start(asap::BeamAxis) = whichBeam;
     408  start(asap::IFAxis) = whichIF;
     409//
     410  end.resize(asap::nAxes);
     411  end = shpOut-1;
     412  end(asap::BeamAxis) = whichBeam;
     413  end(asap::IFAxis) = whichIF;
     414}
     415
     416
     417
     418// SDFrequenctTable
     419
     420
    363421Int SDFrequencyTable::addFrequency(Double refPix, Double refVal, Double inc) {
    364422  Int idx = -1;
     
    415473
    416474
     475
     476// SDDataDesc
     477
    417478uInt SDDataDesc::addEntry (const String& source, uInt freqID, const MDirection& dir)
    418479{
     
    451512}
    452513
     514
  • trunk/src/SDContainer.h

    r326 r349  
    186186  casa::Array<casa::Double>   direction_;
    187187  casa::Vector<casa::String> history_;
    188 
     188  void setSlice (casa::IPosition& start, casa::IPosition& end,
     189                 const casa::IPosition& shpIn, const casa::IPosition& shpOut,
     190                 casa::uInt whichBeam, casa::uInt whichIF, casa::Bool checkPol) const;
    189191};
    190192
     
    221223//
    222224  SDDataDesc(const SDDataDesc& other);
    223 };
    224 
     225
     226};
    225227
    226228} // namespace
Note: See TracChangeset for help on using the changeset viewer.