Changeset 248 for trunk/src


Ignore:
Timestamp:
01/21/05 15:34:59 (20 years ago)
Author:
kil064
Message:

remove function 'quotient' and put its functionality into
function 'binaryOperate'

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r247 r248  
    100100CountedPtr<SDMemTable> SDMath::average(const Block<CountedPtr<SDMemTable> >& in,
    101101                                       const Vector<Bool>& mask, Bool scanAv,
    102                                        const String& weightStr) const
    103 //Bool alignVelocity)
     102                                       const String& weightStr, Bool alignVelocity) const
    104103//
    105104// Weighted averaging of spectra from one or more Tables.
    106105//
    107106{
    108    Bool alignVelocity = False;
    109107
    110108// Convert weight type
     
    367365
    368366
    369 CountedPtr<SDMemTable> SDMath::quotient(const CountedPtr<SDMemTable>& on,
    370                                         const CountedPtr<SDMemTable>& off,
    371                                         Bool preserveContinuum)  const
    372 {
    373   const uInt nRowOn = on->nRow();
    374   const uInt nRowOff = off->nRow();
    375   Bool ok = (nRowOff==1&&nRowOn>0) ||
    376             (nRowOff>=1&&nRowOn==nRowOff);
    377   if (!ok) {
    378      throw (AipsError("The reference Scan Table can have one row or the same number of rows as the source Scan Table"));
    379   }
    380 
    381 // Input Tables and columns
    382 
    383   Table tabOn = on->table();
    384   Table tabOff = off->table();
    385   ROArrayColumn<Float> tSysOn(tabOn, "TSYS");
    386   ROArrayColumn<Float> tSysOff(tabOff, "TSYS");
    387 
    388 // Output Table cloned from input
    389 
    390   SDMemTable* pTabOut = new SDMemTable(*on, True);
    391 
    392 // Loop over rows
    393 
    394   MaskedArray<Float>* pMOff = new MaskedArray<Float>(off->rowAsMaskedArray(0));
    395   IPosition shpOff = pMOff->shape();
    396 //
    397   Array<Float> tSysOnArr, tSysOffArr;
    398   tSysOn.get(0, tSysOnArr);
    399   tSysOff.get(0, tSysOffArr);
    400 //
    401   for (uInt i=0; i<nRowOn; i++) {
    402      MaskedArray<Float> mOn(on->rowAsMaskedArray(i));
    403      IPosition shpOn = mOn.shape();
    404      tSysOn.get(i, tSysOnArr);
    405 //
    406      if (nRowOff>1) {
    407         delete pMOff;
    408         pMOff = new MaskedArray<Float>(off->rowAsMaskedArray(i));
    409         shpOff = pMOff->shape();
    410         tSysOff.get(i, tSysOffArr);
    411      }
    412 
    413 // Conformance
    414 
    415      if (!shpOn.isEqual(shpOff)) {
    416         throw(AipsError("on/off data are not conformant"));
    417      }
    418      if (!tSysOnArr.shape().isEqual(tSysOffArr.shape())) {
    419         throw(AipsError("on/off Tsys data are not conformant"));
    420      }
    421      if (!shpOn.isEqual(tSysOnArr.shape())) {
    422         throw(AipsError("Correlation and Tsys data are not conformant"));
    423      }
    424 
    425 // Get container
    426 
    427      SDContainer sc = on->getSDContainer(i);
    428 
    429 // Compute and put quotient into container
    430 
    431      if (preserveContinuum) {     
    432         MaskedArray<Float> tmp = (tSysOffArr * mOn / *pMOff) - tSysOffArr;
    433         putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    434      } else {
    435         MaskedArray<Float> tmp = (tSysOffArr * mOn / *pMOff) - tSysOnArr;
    436         putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    437      }
    438      sc.putTsys(tSysOffArr);
    439      sc.scanid = i;
    440 
    441 // Put new row in output Table
    442  
    443      pTabOut->putSDContainer(sc);
    444   }
    445   if (pMOff) delete pMOff;
    446 //
    447   return CountedPtr<SDMemTable>(pTabOut);
    448 }
    449 
    450 
    451 CountedPtr<SDMemTable> SDMath::simpleBinaryOperate (const CountedPtr<SDMemTable>& left,
    452                                                     const CountedPtr<SDMemTable>& right,
    453                                                     const String& op)  const
    454 //
    455 // Simple binary Table operators. add, subtract, multiply, divide (what=0,1,2,3)
    456 //
    457 {
    458 
    459 // CHeck operator
     367CountedPtr<SDMemTable> SDMath::binaryOperate (const CountedPtr<SDMemTable>& left,
     368                                              const CountedPtr<SDMemTable>& right,
     369                                              const String& op, Bool preserve)  const
     370{
     371
     372// Check operator
    460373
    461374  String op2(op);
     
    470383  } else if (op2=="DIV") {
    471384     what = 3;
     385  } else if (op2=="QUOTIENT") {
     386     what = 4;
    472387  } else {
    473     throw AipsError("Unrecognized operation");
     388    throw( AipsError("Unrecognized operation"));
    474389  }
    475390
    476391// Check rows
    477392
    478   const uInt nRows = left->nRow();
    479   if (right->nRow() != nRows) {
    480      throw (AipsError("Input Scan Tables must have the same number of rows"));
    481   }
    482 
    483 // Input Tables and columns
     393  const uInt nRowLeft = left->nRow();
     394  const uInt nRowRight = right->nRow();
     395  Bool ok = (nRowRight==1&&nRowLeft>0) ||
     396            (nRowRight>=1&&nRowLeft==nRowRight);
     397  if (!ok) {
     398     throw (AipsError("The right Scan Table can have one row or the same number of rows as the left Scan Table"));
     399  }
     400
     401// Input Tables
    484402
    485403  const Table& tLeft = left->table();
    486404  const Table& tRight = right->table();
    487 //
     405
     406// TSys columns
     407
    488408  ROArrayColumn<Float> tSysLeft(tLeft, "TSYS");
    489409  ROArrayColumn<Float> tSysRight(tRight, "TSYS");
    490410
    491 // Output Table cloned from input
     411// First row for right
     412
     413  Array<Float> tSysLeftArr, tSysRightArr;
     414  tSysRight.get(0, tSysRightArr);
     415  MaskedArray<Float>* pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(0));
     416  IPosition shpRight = pMRight->shape();
     417
     418// Output Table cloned from left
    492419
    493420  SDMemTable* pTabOut = new SDMemTable(*left, True);
     
    495422// Loop over rows
    496423
    497   for (uInt i=0; i<nRows; i++) {
     424  for (uInt i=0; i<nRowLeft; i++) {
    498425
    499426// Get data
     427
    500428     MaskedArray<Float> mLeft(left->rowAsMaskedArray(i));
    501      MaskedArray<Float> mRight(right->rowAsMaskedArray(i));
    502 //
    503429     IPosition shpLeft = mLeft.shape();
    504      IPosition shpRight = mRight.shape();
    505      if (!shpLeft.isEqual(shpRight)) {
    506        throw(AipsError("left/right Scan Tables are not conformant"));
     430     tSysLeft.get(i, tSysLeftArr);
     431//
     432     if (nRowRight>1) {
     433        delete pMRight;
     434        pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(i));
     435        shpRight = pMRight->shape();
     436        tSysRight.get(i, tSysRightArr);
    507437     }
    508 
    509 // Get TSys
    510 
    511      Array<Float> tSysLeftArr, tSysRightArr;
    512      tSysLeft.get(i, tSysLeftArr);
    513      tSysRight.get(i, tSysRightArr);
     438//
     439     if (!shpRight.isEqual(shpLeft)) {
     440        throw(AipsError("left and right scan tables are not conformant"));
     441     }
     442     if (!tSysRightArr.shape().isEqual(tSysRightArr.shape())) {
     443        throw(AipsError("left and right Tsys data are not conformant"));
     444     }
     445     if (!shpRight.isEqual(tSysRightArr.shape())) {
     446        throw(AipsError("left and right scan tables are not conformant"));
     447     }
    514448
    515449// Make container
     
    520454
    521455     if (what==0) {                               
    522         MaskedArray<Float> tmp = mLeft + mRight;
     456        MaskedArray<Float> tmp = mLeft + *pMRight;
    523457        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    524458        sc.putTsys(tSysLeftArr+tSysRightArr);
    525459     } else if (what==1) {
    526         MaskedArray<Float> tmp = mLeft - mRight;
     460        MaskedArray<Float> tmp = mLeft - *pMRight;
    527461        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    528462        sc.putTsys(tSysLeftArr-tSysRightArr);
    529463     } else if (what==2) {
    530         MaskedArray<Float> tmp = mLeft * mRight;
     464        MaskedArray<Float> tmp = mLeft * *pMRight;
    531465        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    532466        sc.putTsys(tSysLeftArr*tSysRightArr);
    533467     } else if (what==3) {
    534         MaskedArray<Float> tmp = mLeft / mRight;
     468        MaskedArray<Float> tmp = mLeft / *pMRight;
    535469        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    536470        sc.putTsys(tSysLeftArr/tSysRightArr);
     471     } else if (what==4) {
     472        if (preserve) {     
     473           MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysRightArr;
     474           putDataInSDC(sc, tmp.getArray(), tmp.getMask());
     475        } else {
     476           MaskedArray<Float> tmp = (tSysRightArr * mLeft / *pMRight) - tSysLeftArr;
     477           putDataInSDC(sc, tmp.getArray(), tmp.getMask());
     478        }
     479        sc.putTsys(tSysRightArr);
    537480     }
    538481
     
    541484     pTabOut->putSDContainer(sc);
    542485  }
     486  if (pMRight) delete pMRight;
    543487//
    544488  return CountedPtr<SDMemTable>(pTabOut);
     
    666610}
    667611
    668 SDMemTable* SDMath::simpleOperate(const SDMemTable& in, Float val, Bool doAll,
    669                                   uInt what) const
     612SDMemTable* SDMath::unaryOperate(const SDMemTable& in, Float val, Bool doAll,
     613                                 uInt what) const
    670614//
    671615// what = 0   Multiply
     
    1014958     sh.fluxunit = "Jy";
    1015959  } else {
    1016      throw AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K");
     960     throw(AipsError("Unrecognized brightness units in Table - must be consistent with Jy or K"));
    1017961  }
    1018962  pTabOut->putSDHeader(sh);
     
    10921036  const uInt nC = coeffs.nelements();
    10931037  if (fileName.length()>0 && nC>0) {
    1094      throw AipsError("You must choose either polynomial coefficients or an ascii file, not both");
     1038     throw(AipsError("You must choose either polynomial coefficients or an ascii file, not both"));
    10951039  }
    10961040
     
    11301074        pPoly->setCoefficients(coeff);
    11311075     } else {
    1132         throw AipsError("There is no known gain-el polynomial known for this instrument");
     1076        throw(AipsError("There is no known gain-el polynomial known for this instrument"));
    11331077     }
    11341078//
  • trunk/src/SDMath.h

    r234 r248  
    6060   ~SDMath();
    6161
    62 // Quotient
    63    casa::CountedPtr<SDMemTable> quotient(const casa::CountedPtr<SDMemTable>& on,
    64                                          const casa::CountedPtr<SDMemTable>& off,
    65                                          casa::Bool preserveContinuum=casa::True) const;
    66 
    67 // Simple binary Table operators. add, subtract, multiply, divide (what=0,1,2,3)
    68    casa::CountedPtr<SDMemTable> simpleBinaryOperate (const casa::CountedPtr<SDMemTable>& left,
    69                                                      const casa::CountedPtr<SDMemTable>& right,
    70                                                      const casa::String& op) const;
     62// Binary Table operators. op=ADD, SUB, MUL, DIV, QUOTIENT
     63   casa::CountedPtr<SDMemTable> binaryOperate (const casa::CountedPtr<SDMemTable>& left,
     64                                               const casa::CountedPtr<SDMemTable>& right,
     65                                               const casa::String& op, casa::Bool preserve) const;
    7166
    7267// Average in time
     
    7469                                         const casa::Vector<casa::Bool>& mask,
    7570                                         casa::Bool scanAverage,
    76                                          const casa::String& weightStr) const;
    77 //                                         casa::Bool alignVelocity) const;
     71                                         const casa::String& weightStr,
     72                                         casa::Bool alignVelocity=casa::False) const;
    7873
    7974// Statistics. If row<0, all rows are done otherwise, just the
     
    10297   SDMemTable* opacity (const SDMemTable& in, casa::Float tau, casa::Bool doAll) const;
    10398
    104 // Simple mathematical operations.  what=0 (mul) or 1 (add)
    105    SDMemTable* simpleOperate(const SDMemTable& in, casa::Float offset,
    106                              casa::Bool doAll, casa::uInt what) const;
     99// Simple unary mathematical operations.  what=0 (mul) or 1 (add)
     100   SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset,
     101                            casa::Bool doAll, casa::uInt what) const;
    107102
    108103// Average polarizations
Note: See TracChangeset for help on using the changeset viewer.