Changeset 1310


Ignore:
Timestamp:
12/14/06 11:21:48 (17 years ago)
Author:
mar637
Message:

merge from trunk, to get binary operator changes

Location:
branches/Release2.1.2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/Release2.1.2/python/scantable.py

    r1295 r1310  
    14131413            return s
    14141414
    1415     def scale(self, factor, tsys=True, insitu=None, ):
     1415    def scale(self, factor, tsys=True, insitu=None):
    14161416        """
    14171417        Return a scan where all spectra are scaled by the give 'factor'
     
    15191519        s = None
    15201520        if isinstance(other, scantable):
    1521             print "scantable + scantable NYI"
    1522             return
     1521            s = scantable(self._math._binaryop(self, other, "ADD"))
    15231522        elif isinstance(other, float):
    15241523            s = scantable(self._math._unaryop(self, other, "ADD", False))
     
    15361535        s = None
    15371536        if isinstance(other, scantable):
    1538             print "scantable - scantable NYI"
    1539             return
     1537            s = scantable(self._math._binaryop(self, other, "SUB"))
    15401538        elif isinstance(other, float):
    15411539            s = scantable(self._math._unaryop(self, other, "SUB", False))
     
    15531551        s = None
    15541552        if isinstance(other, scantable):
    1555             print "scantable * scantable NYI"
    1556             return
     1553            s = scantable(self._math._binaryop(self, other, "MUL"))
    15571554        elif isinstance(other, float):
    15581555            s = scantable(self._math._unaryop(self, other, "MUL", False))
     
    15711568        s = None
    15721569        if isinstance(other, scantable):
    1573             print "scantable / scantable NYI"
    1574             return
     1570            s = scantable(self._math._binaryop(self, other, "DIV"))
    15751571        elif isinstance(other, float):
    15761572            if other == 0.0:
  • branches/Release2.1.2/src/STMath.cpp

    r1259 r1310  
    281281                                              bool tsys )
    282282{
    283   // modes are "ADD" and "MUL"
    284283  CountedPtr< Scantable > out = getScantable(in, false);
    285284  Table& tab = out->table();
     
    291290    specCol.get(i, spec);
    292291    tsysCol.get(i, ts);
    293     if (mode == "MUL") {
     292    if (mode == "MUL" || mode == "DIV") {
     293      if (mode == "DIV") val = 1.0/val;
    294294      spec *= val;
    295295      specCol.put(i, spec);
     
    298298        tsysCol.put(i, ts);
    299299      }
    300     } else if ( mode == "ADD" ) {
     300    } else if ( mode == "ADD"  || mode == "SUB") {
     301      if (mode == "SUB") val *= -1.0;
    301302      spec += val;
    302303      specCol.put(i, spec);
     
    309310  return out;
    310311}
     312
     313CountedPtr<Scantable> STMath::binaryOperate(const CountedPtr<Scantable>& left,
     314                                            const CountedPtr<Scantable>& right,
     315                                            const std::string& mode)
     316{
     317  bool insitu = insitu_;
     318  if ( ! left->conformant(*right) ) {
     319    throw(AipsError("'left' and 'right' scantables are not conformant."));
     320  }
     321  setInsitu(false);
     322  CountedPtr< Scantable > out = getScantable(left, false);
     323  setInsitu(insitu);
     324  Table& tout = out->table();
     325  Block<String> coln(5);
     326  coln[0] = "SCANNO";  coln[1] = "CYCLENO";  coln[2] = "BEAMNO";
     327  coln[3] = "IFNO";  coln[4] = "POLNO";
     328  Table tmpl = tout.sort(coln);
     329  Table tmpr = right->table().sort(coln);
     330  ArrayColumn<Float> lspecCol(tmpl,"SPECTRA");
     331  ROArrayColumn<Float> rspecCol(tmpr,"SPECTRA");
     332  ArrayColumn<uChar> lflagCol(tmpl,"FLAGTRA");
     333  ROArrayColumn<uChar> rflagCol(tmpr,"FLAGTRA");
     334
     335  for (uInt i=0; i<tout.nrow(); ++i) {
     336    Vector<Float> lspecvec, rspecvec;
     337    Vector<uChar> lflagvec, rflagvec;
     338    lspecvec = lspecCol(i);    rspecvec = rspecCol(i);
     339    lflagvec = lflagCol(i);    rflagvec = rflagCol(i);
     340    MaskedArray<Float> mleft = maskedArray(lspecvec, lflagvec);
     341    MaskedArray<Float> mright = maskedArray(rspecvec, rflagvec);
     342    if (mode == "ADD") {
     343      mleft += mright;
     344    } else if ( mode == "SUB") {
     345      mleft -= mright;
     346    } else if ( mode == "MUL") {
     347      mleft *= mright;
     348    } else if ( mode == "DIV") {
     349      mleft /= mright;
     350    } else {
     351      throw(AipsError("Illegal binary operator"));
     352    }
     353    lspecCol.put(i, mleft.getArray());
     354  }
     355  return out;
     356}
     357
     358
    311359
    312360MaskedArray<Float> STMath::maskedArray( const Vector<Float>& s,
  • branches/Release2.1.2/src/STMath.h

    r1295 r1310  
    119119                  const std::string& mode, bool tsys=false );
    120120
     121  casa::CountedPtr<Scantable>
     122    binaryOperate( const casa::CountedPtr<Scantable>& left,
     123                   const casa::CountedPtr<Scantable>& right,
     124                   const std::string& mode);
     125
    121126  casa::CountedPtr<Scantable> autoQuotient(const casa::CountedPtr<Scantable>& in,
    122127                                           const std::string& mode = "NEAREST",
  • branches/Release2.1.2/src/STMathWrapper.h

    r1200 r1310  
    7272                  const std::string& mode, bool tsys=false )
    7373  { return ScantableWrapper(STMath::unaryOperate(in.getCP(), val, mode, tsys)); }
     74
     75  ScantableWrapper binaryOperate( const ScantableWrapper& left,
     76                                  const ScantableWrapper& right,
     77                                  const std::string& mode)
     78  { return ScantableWrapper( STMath::binaryOperate( left.getCP(), right.getCP(),
     79                                                    mode ) ); }
     80
    7481
    7582  ScantableWrapper autoQuotient( const ScantableWrapper& in,
  • branches/Release2.1.2/src/python_STMath.cpp

    r1192 r1310  
    4949        .def("_averagebeams", &STMathWrapper::averageBeams)
    5050        .def("_unaryop", &STMathWrapper::unaryOperate)
     51        .def("_binaryop", &STMathWrapper::binaryOperate)
    5152        .def("_auto_quotient", &STMathWrapper::autoQuotient)
    5253        .def("_quotient", &STMathWrapper::quotient)
Note: See TracChangeset for help on using the changeset viewer.