Changeset 1994


Ignore:
Timestamp:
02/16/11 14:59:40 (13 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-1306)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added row selection parameters to scantable.flag,

ScantableWrapper::flag and Scantable::flag.

Test Programs:

Put in Release Notes: No

Module(s): scantable class

Description:

Enabled a row selection in scantable.flag.

  • A parameter 'row' is added to scantable.flag. The default value -1 applies

specified channel flags to the all rows in the scantable (same as previous code).

  • A parameter 'whichrow' is also added to ScantableWrapper::flag and

Scantable::flag accordingly.

  • The actual flagg application part in the code Scantable::flag is moved to a new

private function Scantable::applyChanFlag(uInt whichrow, vector<bool> msk, uChar flagval).
The function applies flag with a value, 'flagval', to masked channels, 'msk',
in a selected row, 'whichrow'.


Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r1992 r1994  
    10141014
    10151015    @asaplog_post_dec
    1016     def flag(self, mask=None, unflag=False):
     1016    def flag(self, row=-1, mask=None, unflag=False):
    10171017        """\
    10181018        Flag the selected data using an optional channel mask.
     
    10201020        Parameters:
    10211021
     1022            row:    an optional row number in the scantable.
     1023                      Default -1 flags all rows
     1024                     
    10221025            mask:   an optional channel mask, created with create_mask. Default
    10231026                    (no mask) is all channels.
     
    10281031        varlist = vars()
    10291032        mask = mask or []
    1030         self._flag(mask, unflag)
     1033        self._flag(row, mask, unflag)
    10311034        self._add_history("flag", varlist)
    10321035
  • trunk/src/Scantable.cpp

    r1987 r1994  
    778778}
    779779
    780 void Scantable::flag(const std::vector<bool>& msk, bool unflag)
    781 {
     780
     781void Scantable::flag( int whichrow, const std::vector<bool>& msk, bool unflag ) {
    782782  std::vector<bool>::const_iterator it;
    783783  uInt ntrue = 0;
     784  if (whichrow >= int(table_.nrow()) ) {
     785    throw(AipsError("Invalid row number"));
     786  }
    784787  for (it = msk.begin(); it != msk.end(); ++it) {
    785788    if ( *it ) {
     
    787790    }
    788791  }
    789   if ( selector_.empty()  && (msk.size() == 0 || msk.size() == ntrue) )
     792  //if ( selector_.empty()  && (msk.size() == 0 || msk.size() == ntrue) )
     793  if ( whichrow == -1 && !unflag && selector_.empty() && (msk.size() == 0 || msk.size() == ntrue) )
    790794    throw(AipsError("Trying to flag whole scantable."));
     795  uChar userflag = 1 << 7;
     796  if ( unflag ) {
     797    userflag = 0 << 7;
     798  }
     799  if (whichrow > -1 ) {
     800    applyChanFlag(uInt(whichrow), msk, userflag);
     801  } else {
     802    for ( uInt i=0; i<table_.nrow(); ++i) {
     803      applyChanFlag(i, msk, userflag);
     804    }
     805  }
     806}
     807
     808void Scantable::applyChanFlag( uInt whichrow, const std::vector<bool>& msk, uChar flagval )
     809{
     810  if (whichrow >= table_.nrow() ) {
     811    throw( casa::indexError<int>( whichrow, "asap::Scantable::applyChanFlag: Invalid row number" ) );
     812  }
     813  Vector<uChar> flgs = flagsCol_(whichrow);
    791814  if ( msk.size() == 0 ) {
    792     uChar userflag = 1 << 7;
    793     if ( unflag ) {
    794       userflag = 0 << 7;
    795     }
    796     for ( uInt i=0; i<table_.nrow(); ++i) {
    797       Vector<uChar> flgs = flagsCol_(i);
    798       flgs = userflag;
    799       flagsCol_.put(i, flgs);
    800     }
     815    flgs = flagval;
     816    flagsCol_.put(whichrow, flgs);
    801817    return;
    802818  }
     
    804820    throw(AipsError("Mask has incorrect number of channels."));
    805821  }
    806   for ( uInt i=0; i<table_.nrow(); ++i) {
    807     Vector<uChar> flgs = flagsCol_(i);
    808     if ( flgs.nelements() != msk.size() ) {
    809       throw(AipsError("Mask has incorrect number of channels."
    810                       " Probably varying with IF. Please flag per IF"));
    811     }
    812     std::vector<bool>::const_iterator it;
    813     uInt j = 0;
    814     uChar userflag = 1 << 7;
    815     if ( unflag ) {
    816       userflag = 0 << 7;
    817     }
    818     for (it = msk.begin(); it != msk.end(); ++it) {
    819       if ( *it ) {
    820         flgs(j) = userflag;
    821       }
    822       ++j;
    823     }
    824     flagsCol_.put(i, flgs);
    825   }
     822  if ( flgs.nelements() != msk.size() ) {
     823    throw(AipsError("Mask has incorrect number of channels."
     824                    " Probably varying with IF. Please flag per IF"));
     825  }
     826  std::vector<bool>::const_iterator it;
     827  uInt j = 0;
     828  for (it = msk.begin(); it != msk.end(); ++it) {
     829    if ( *it ) {
     830      flgs(j) = flagval;
     831    }
     832    ++j;
     833  }
     834  flagsCol_.put(whichrow, flgs);
    826835}
    827836
  • trunk/src/Scantable.h

    r1947 r1994  
    230230   */
    231231  //void flag( const std::vector<bool>& msk = std::vector<bool>());
    232   void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
     232  //void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
     233
     234  void flag( int whichrow = -1, const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
    233235
    234236  /**
     
    607609
    608610  void doPolyBaseline(const std::vector<bool>& mask, int order, int rowno, Fitter& fitter);
     611
     612  void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval);
     613
     614
    609615};
    610616
    611 
    612617} // namespace
    613618
  • trunk/src/ScantableWrapper.h

    r1947 r1994  
    109109    { table_->flag(msk); }
    110110  **/
     111  /**
    111112  void flag(const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
    112113    { table_->flag(msk, unflag); }
     114  **/
     115  void flag(int whichrow=-1, const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
     116    { table_->flag(whichrow, msk, unflag); }
    113117
    114118  void flagRow(const std::vector<casa::uInt>& rows=std::vector<casa::uInt>(), bool unflag=false)
Note: See TracChangeset for help on using the changeset viewer.