Changeset 1639 for branches


Ignore:
Timestamp:
09/30/09 17:56:00 (15 years ago)
Author:
Kana Sugimoto
Message:

New Development: Yes

JIRA Issue: Yes (CAS-1429)

Ready to Release: Yes

Interface Changes: Yes

What Interface Changed:
A new python method, selector.set_rows(rownrs=[]),
and a cpp function,
STSelector::setRows( const std::vector< int >& rows ),
are added.
The cpp function can be called with selector._setrows()
from python scripts.

Test Programs:

# @casa
s=sd.scantable('ORIGINAL_TABLE_NAME', False)
sel=sd.selector()
rownrs=[1,3,5,7]
sel.set_rows(rownrs)
s.set_selection(sel)
s2=s.copy()
s2.save(name='NEW_TABLE_NAME',format='ASAP',overwrite=True)

Put in Release Notes: Yes

Module(s):

Description:

Data selection by a list of row numbers can be done by
the new method selector.set_rows.

Location:
branches/alma
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/python/selector.py

    r1603 r1639  
    147147        """
    148148        self._setorder(order)
     149
     150    def set_rows(self, rows=[]):
     151        """
     152        Set a sequence of row numbers (0-based). Power users Only!
     153        NOTICE row numbers can be changed easily by sorting,
     154        prior selection, etc.
     155        Parameters:
     156            rows:    a list of integers. Default [] is to unset the selection.
     157        """
     158        vec = _to_list(rows, int)
     159        if isinstance(vec,list):
     160            self._setrows(vec)
     161        else:
     162            raise TypeError('Unknown row number type. Use lists of integers.')
    149163
    150164    def get_scans(self):
  • branches/alma/src/STSelector.cpp

    r1603 r1639  
    116116}
    117117
     118void STSelector::setRows( const std::vector< int >& rows )
     119{
     120  rowselection_ = rows;
     121}
     122
     123// Table STSelector::apply( const Table& tab )
     124// {
     125//   if ( empty() ) {
     126//     return sort(tab);
     127//   }
     128//   TableExprNode query;
     129//   intidmap::const_iterator it;
     130//   for (it = intselections_.begin(); it != intselections_.end(); ++it) {
     131//     TableExprNode theset(Vector<Int>( (*it).second ));
     132//     if ( query.isNull() ) {
     133//       query = tab.col((*it).first).in(theset);
     134//     } else {
     135//       query = tab.col((*it).first).in(theset) && query;
     136//     }
     137//   }
     138//   stringidmap::const_iterator it1;
     139//   for (it1 = stringselections_.begin(); it1 != stringselections_.end(); ++it1) {
     140//     TableExprNode theset(mathutil::toVectorString( (*it1).second ));
     141//     if ( query.isNull() ) {
     142//       query = tab.col((*it1).first).in(theset);
     143//     } else {
     144//       query = tab.col((*it1).first).in(theset) && query;
     145//     }
     146//   }
     147//   // add taql query
     148//   if ( taql_.size() > 0 ) {
     149//     Table tmpt = tab;
     150//     std::string pytaql = "USING STYLE PYTHON " + taql_;
     151
     152//     if ( !query.isNull() ) { // taql and selection
     153//       tmpt = tableCommand(pytaql, tab(query));
     154//     } else { // taql only
     155//       tmpt = tableCommand(pytaql, tab);
     156//     }
     157//     return sort(tmpt);
     158//   } else {
     159//     if ( query.isNull() ) {
     160//       return sort(tab);
     161//     } else {
     162//       return sort(tab(query));
     163//     }
     164//   }
     165// }
    118166Table STSelector::apply( const Table& tab )
    119167{
    120168  if ( empty() ) {
    121169    return sort(tab);
     170  }
     171  Table basetab = tab;
     172  // Important!! Be sure to apply row selection first.
     173  if (rowselection_.size() > 0){
     174    //Vector<Int> intrownrs(rowselection_);
     175    Vector<uInt> rownrs( rowselection_.size() );
     176    convertArray(rownrs, Vector<Int> ( rowselection_ ));
     177    basetab = tab( rownrs );
     178    ///TableExprNode theset(Vector<Int>( rowselection_ ));
     179    ///query = tab.nodeRownr().in(theset);
    122180  }
    123181  TableExprNode query;
     
    126184    TableExprNode theset(Vector<Int>( (*it).second ));
    127185    if ( query.isNull() ) {
    128       query = tab.col((*it).first).in(theset);
     186      //query = tab.col((*it).first).in(theset);
     187      query = basetab.col((*it).first).in(theset);
    129188    } else {
    130       query = tab.col((*it).first).in(theset) && query;
     189      //query = tab.col((*it).first).in(theset) && query;
     190      query = basetab.col((*it).first).in(theset) && query;
    131191    }
    132192  }
     
    135195    TableExprNode theset(mathutil::toVectorString( (*it1).second ));
    136196    if ( query.isNull() ) {
    137       query = tab.col((*it1).first).in(theset);
     197      //query = tab.col((*it1).first).in(theset);
     198      query = basetab.col((*it1).first).in(theset);
    138199    } else {
    139       query = tab.col((*it1).first).in(theset) && query;
     200      //query = tab.col((*it1).first).in(theset) && query;
     201      query = basetab.col((*it1).first).in(theset) && query;
    140202    }
    141203  }
    142204  // add taql query
    143205  if ( taql_.size() > 0 ) {
    144     Table tmpt = tab;
     206    //Table tmpt = tab;
     207    Table tmpt = basetab;
    145208    std::string pytaql = "USING STYLE PYTHON " + taql_;
    146209
    147210    if ( !query.isNull() ) { // taql and selection
    148       tmpt = tableCommand(pytaql, tab(query));
     211      //tmpt = tableCommand(pytaql, tab(query));
     212      tmpt = tableCommand(pytaql, basetab(query));
    149213    } else { // taql only
    150       tmpt = tableCommand(pytaql, tab);
     214      //tmpt = tableCommand(pytaql, tab);
     215      tmpt = tableCommand(pytaql, basetab);
    151216    }
    152217    return sort(tmpt);
    153218  } else {
    154219    if ( query.isNull() ) {
    155       return sort(tab);
     220      //return sort(tab);
     221      return sort(basetab);
    156222    } else {
    157       return sort(tab(query));
     223      //return sort(tab(query));
     224      return sort(basetab(query));
    158225    }
    159226  }
     
    227294bool asap::STSelector::empty( ) const
    228295{
    229   return (intselections_.empty() && taql_.size() == 0 );
     296  //return (intselections_.empty() && taql_.size() == 0 );
     297  return (intselections_.empty() && taql_.size() == 0 && rowselection_.size() == 0);
    230298}
    231299
  • branches/alma/src/STSelector.h

    r939 r1639  
    4848
    4949  void setSortOrder(const std::vector<std::string>& order);
     50  void setRows(const std::vector<int>& rows);
    5051
    5152  std::vector<int> getScans() const;
     
    8687  casa::Block<casa::String> order_;
    8788  std::string taql_;
     89  std::vector<int> rowselection_;
    8890};
    8991
  • branches/alma/src/python_STSelector.cpp

    r939 r1639  
    4141        .def("_settaql", &STSelector::setTaQL)
    4242        .def("_setorder", &STSelector::setSortOrder)
     43        .def("_setrows", &STSelector::setRows)
    4344        .def("_empty", &STSelector::empty)
    4445      ;
Note: See TracChangeset for help on using the changeset viewer.