Changeset 152


Ignore:
Timestamp:
12/26/04 20:51:14 (19 years ago)
Author:
kil064
Message:

function 'add' and 'multiply' now take arg. doAll to
indicate whether operation to be applied to
all spectral or cursor selection only.

Combine functions 'localMultiply' and 'localAdd' into
'localOperate'

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r146 r152  
    380380}
    381381
    382 
    383 
    384 void SDMath::multiplyInSitu(SDMemTable* pIn, Float factor)
    385 {
    386   SDMemTable* pOut = localMultiply (*pIn, factor);
     382void SDMath::multiplyInSitu(SDMemTable* pIn, Float factor, Bool doAll)
     383{
     384  const uInt what = 0;
     385  SDMemTable* pOut = localOperate (*pIn, factor, doAll, what);
    387386  *pIn = *pOut;
    388387   delete pOut;
     
    391390
    392391CountedPtr<SDMemTable>
    393 SDMath::multiply(const CountedPtr<SDMemTable>& in, Float factor)
    394 {
    395   return CountedPtr<SDMemTable>(localMultiply(*in,factor));
    396 }
     392SDMath::multiply(const CountedPtr<SDMemTable>& in, Float factor, Bool doAll)
     393{
     394  const uInt what = 0;
     395  return CountedPtr<SDMemTable>(localOperate (*in, factor, doAll, what));
     396}
     397
     398
     399void SDMath::addInSitu (SDMemTable* pIn, Float offset, Bool doAll)
     400{
     401  const uInt what = 1;
     402  SDMemTable* pOut = localOperate (*pIn, offset, doAll, what);
     403  *pIn = *pOut;
     404   delete pOut;
     405
     406
    397407
    398408CountedPtr<SDMemTable>
    399 SDMath::add(const CountedPtr<SDMemTable>& in, Float offset)
    400 //
    401 // Add offset to values
    402 //
    403 {
    404   SDMemTable* sdmt = new SDMemTable(*in,False);
    405   Table t = sdmt->table();
    406   ArrayColumn<Float> spec(t,"SPECTRA");
    407 
    408   for (uInt i=0; i < t.nrow(); i++) {
    409     MaskedArray<Float> marr(sdmt->rowAsMaskedArray(i));
    410     marr += offset;
    411     spec.put(i, marr.getArray());
    412   }
    413   return CountedPtr<SDMemTable>(sdmt);
     409SDMath::add(const CountedPtr<SDMemTable>& in, Float offset, Bool doAll)
     410{
     411  const uInt what = 1;
     412  return CountedPtr<SDMemTable>(localOperate(*in, offset, doAll, what));
    414413}
    415414
     
    657656// Specify cursor location
    658657
    659   uInt i = in->getBeam();
    660   uInt j = in->getIF();
    661   uInt k = in->getPol();
    662   IPosition start(4,i,j,k,0);
    663   IPosition end(4,i,j,k,in->nChan()-1);
     658  IPosition start, end;
     659  getCursorLocation (start, end, *in);
    664660
    665661// Loop over rows
     
    831827}
    832828
    833 SDMemTable* SDMath::localMultiply (const SDMemTable& in, Float factor)
    834 {
    835   SDMemTable* pOut = new SDMemTable(in,False);
    836   const Table& tOut = pOut->table();
    837   ArrayColumn<Float> spec(tOut,"SPECTRA"); 
    838 //
    839   for (uInt i=0; i < tOut.nrow(); i++) {
    840     MaskedArray<Float> marr(pOut->rowAsMaskedArray(i));
    841     marr *= factor;
    842     spec.put(i, marr.getArray());
    843   }
     829SDMemTable* SDMath::localOperate (const SDMemTable& in, Float val, Bool doAll,
     830                                  uInt what)
     831//
     832// what = 0   Multiply
     833//        1   Add
     834{
     835   SDMemTable* pOut = new SDMemTable(in,False);
     836   const Table& tOut = pOut->table();
     837   ArrayColumn<Float> spec(tOut,"SPECTRA"); 
     838//
     839   if (doAll) {
     840      for (uInt i=0; i < tOut.nrow(); i++) {
     841
     842// Get
     843
     844         MaskedArray<Float> marr(pOut->rowAsMaskedArray(i));
     845
     846// Operate
     847
     848         if (what==0) {
     849            marr *= val;
     850         } else if (what==1) {
     851            marr += val;
     852         }
     853
     854// Put
     855
     856         spec.put(i, marr.getArray());
     857      }
     858   } else {
     859
     860// Get cursor location
     861
     862      IPosition start, end;
     863      getCursorLocation (start, end, in);
     864//
     865      for (uInt i=0; i < tOut.nrow(); i++) {
     866
     867// Get
     868
     869         MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i));
     870
     871// Modify. More work than we would like to deal with the mask
     872
     873         Array<Float>& values = dataIn.getRWArray();
     874         Array<Bool> mask(dataIn.getMask());
     875//
     876         Array<Float> values2 = values(start,end);
     877         Array<Bool> mask2 = mask(start,end);
     878         MaskedArray<Float> t(values2,mask2);
     879         if (what==0) {
     880            t *= val;
     881         } else if (what==1) {
     882            t += val;
     883         }
     884         values(start, end) = t.getArray();     // Write back into 'dataIn'
     885
     886// Put
     887         spec.put(i, dataIn.getArray());
     888      }
     889   }
     890//
    844891   return pOut;
    845892}
    846893
    847894
     895
     896void SDMath::getCursorLocation (IPosition& start, IPosition& end,
     897                                const SDMemTable& in)
     898{
     899  const uInt nDim = 4;
     900  const uInt i = in.getBeam();
     901  const uInt j = in.getIF();
     902  const uInt k = in.getPol();
     903  const uInt n = in.nChan();
     904//
     905  IPosition s(nDim,i,j,k,0);
     906  IPosition e(nDim,i,j,k,n-1);
     907//
     908  start.resize(nDim);
     909  start = s;
     910  end.resize(nDim);
     911  end = e;
     912}
  • trunk/src/SDMath.h

    r146 r152  
    4242
    4343namespace SDMath {
    44   //public:
     44
     45// Quotient
     46
    4547  casa::CountedPtr<SDMemTable> quotient(const casa::CountedPtr<SDMemTable>& on,
    4648                                         const casa::CountedPtr<SDMemTable>& off);
    47 //
    48   void multiplyInSitu(SDMemTable* in, casa::Float factor);
     49
     50// Multiply
     51
     52  void multiplyInSitu(SDMemTable* in, casa::Float factor, casa::Bool all);
    4953  casa::CountedPtr<SDMemTable> multiply(const casa::CountedPtr<SDMemTable>& in,
    50                                         casa::Float factor);
    51 //
     54                                        casa::Float factor, casa::Bool all);
     55
     56// Addition
     57
     58  void addInSitu (SDMemTable* in, casa::Float offset, casa::Bool all);
    5259  casa::CountedPtr<SDMemTable> add(const casa::CountedPtr<SDMemTable>& in,
    53                              casa::Float offset);
    54  
     60                                   casa::Float offset, casa::Bool all);
     61
     62//  Hanning
     63
    5564  casa::CountedPtr<SDMemTable> hanning(const casa::CountedPtr<SDMemTable>& in);
     65
     66// Bin up
     67
     68  casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in,
     69                             casa::Int width);
     70
     71// Average in time
    5672
    5773  casa::CountedPtr<SDMemTable>
     
    6076           bool scanAverage, const std::string& weightStr);
    6177
     78// Average polarizations
     79
    6280  casa::CountedPtr<SDMemTable>
    6381  averagePol(const casa::CountedPtr<SDMemTable>& in, const casa::Vector<casa::Bool>& mask);
    6482
     83// Statistics
     84
    6585  std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in,
    6686                                const std::vector<bool>& mask, const std::string& which);
    67  
    68   casa::CountedPtr<SDMemTable> bin(const casa::CountedPtr<SDMemTable>& in,
    69                              casa::Int width);
    7087
    7188// private (not actually...)
    7289
     90// Weighting type for time averaging
     91
    7392  enum weightType {NONE,VAR,TSYS};
     93
     94// Function to use accumulate data during time averaging
    7495
    7596  void accumulate (casa::Double& timeSum, casa::Double& intSum, casa::Int& nAccum,
     
    82103                   casa::Bool useMask, weightType wtType);
    83104
     105// Function to fill Scan Container when averaging in time
     106
    84107  void fillSDC (SDContainer& sc, const casa::Array<casa::Bool>& mask,
    85108                const casa::Array<casa::Float>& data,
     
    89112                const casa::Vector<casa::uInt>& freqID);
    90113
    91   SDMemTable* localMultiply (const SDMemTable& in, casa::Float factor);
     114// Function to normalize data when averaging in time
    92115
    93116  void normalize (casa::MaskedArray<casa::Float>& data,
     
    95118                  const casa::Array<casa::Float>& nPts,
    96119                  weightType wtType, casa::Int axis, casa::Int nAxes);
     120
     121// Functions for simple mathematical operations.  what=0 (mul) or 1 (add)
     122
     123  SDMemTable* localOperate (const SDMemTable& in, casa::Float offset,
     124                            casa::Bool doAll, casa::uInt what);
     125
     126// Function to get the current cursor location
     127   void getCursorLocation (casa::IPosition& start, casa::IPosition& end,
     128                           const SDMemTable& in);
    97129};
    98130
Note: See TracChangeset for help on using the changeset viewer.