Changeset 2900


Ignore:
Timestamp:
03/12/14 12:23:31 (11 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-5875

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: test_sdcoadd

Put in Release Notes: No

Module(s): sd

Description: Describe your changes here...

Added freq_tol parameter to asapmath.merge.
The freq_tol allows to specify frequency tolerance as
numeric value (1.0e6) or string ('1MHz'). The value will
be used to merge FREQUENCIES rows, FREQ_ID, and IFNO.


Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r2845 r2900  
    823823
    824824@asaplog_post_dec
    825 def merge(*args):
     825def merge(*args, **kwargs):
    826826    """
    827827    Merge a list of scanatables, or comma-sperated scantables into one
     
    829829    Parameters:
    830830        A list [scan1, scan2] or scan1, scan2.
     831        freq_tol: frequency tolerance for merging IFs. numeric values
     832                  in units of Hz (1.0e6 -> 1MHz) and string ('1MHz')
     833                  is allowed.
    831834    Example:
    832835        myscans = [scan1, scan2]
     
    834837        # or equivalent
    835838        sameallscans = merge(scan1, scan2)
     839        # with freqtol
     840        allscans = merge(scan1, scan2, freq_tol=1.0e6)
     841        # or equivalently
     842        allscans = merge(scan1, scan2, freq_tol='1MHz')
    836843    """
    837844    varlist = vars()
     
    842849    else:
    843850        lst = tuple(args)
     851    if kwargs.has_key('freq_tol'):
     852        freq_tol = str(kwargs['freq_tol'])
     853    else:
     854        freq_tol = ''
    844855    varlist["args"] = "%d scantables" % len(lst)
    845856    # need special formatting her for history...
     
    850861            msg = "Please give a list of scantables"
    851862            raise TypeError(msg)
    852     s = scantable(stm._merge(lst))
     863    s = scantable(stm._merge(lst, freq_tol))
    853864    s._add_history("merge", varlist)
    854865    return s
  • trunk/src/STFrequencies.cpp

    r2816 r2900  
    1616#include <casa/Arrays/IPosition.h>
    1717#include <casa/Logging/LogIO.h>
     18#include <casa/BasicMath/Math.h>
    1819
    1920#include <tables/Tables/TableDesc.h>
     
    450451}
    451452
     453bool STFrequencies::match( Double refpix, Double refval,
     454                           Double inc, Double freqTolInHz,
     455                           uInt &id)
     456{
     457  ROScalarColumn<uInt> idCol(table_, "ID");
     458  ROScalarColumn<Double> refPixCol(table_, "REFPIX");
     459  ROScalarColumn<Double> refValCol(table_, "REFVAL");
     460  ROScalarColumn<Double> incCol(table_, "INCREMENT");
     461  for (uInt irow = 0; irow < table_.nrow(); ++irow) {
     462    Double refInc = incCol(irow);
     463    Double refFreq = refValCol(irow) - refPixCol(irow) * refInc;
     464    Double freq0 = refval - refpix * inc;
     465    if (nearAbs(inc, refInc, freqTolInHz) &&
     466        nearAbs(refFreq, freq0, freqTolInHz)) {
     467      id = irow;
     468      return true;
     469    }
     470  }
     471  return false;
     472}
     473 
    452474} // namespace
  • trunk/src/STFrequencies.h

    r1819 r2900  
    172172  const casa::String& name() const { return name_; }
    173173
     174  /**
     175   * Examine given set of refpix, refval, and increment matches
     176   * any of the rows within a tolerance of freqTolInHz. If match,
     177   * return true and id is filled properly. Otherwise, return false
     178   * and id may have invalid value.
     179   *
     180   * @param[in] refpix
     181   * @param[in] refval
     182   * @param[in] inc
     183   * @param[in] freqTolInHz
     184   * @param[out] id
     185   * @return boolean indicating match with any rows or not
     186   */
     187  bool match( casa::Double refpix, casa::Double refval, casa::Double inc,
     188              casa::Double freqTolInHz, casa::uInt &id);
     189
    174190private:
    175191
  • trunk/src/STMath.cpp

    r2899 r2900  
    25412541
    25422542CountedPtr< Scantable >
    2543 STMath::merge( const std::vector< CountedPtr < Scantable > >& in )
    2544 //STMath::merge( const std::vector< CountedPtr < Scantable > >& in,
    2545 //             const std::string &freqTol )
    2546 {
    2547   /**
    2548   LogIO os;
    2549   Double freqTolInHz = 0.0;
     2543STMath::merge( const std::vector< CountedPtr < Scantable > >& in,
     2544               const std::string &freqTol )
     2545{
     2546  Double freqTolInHz = 1.0; // default is 1.0Hz according to concat task
    25502547  if (freqTol.size() > 0) {
    25512548    Quantum<Double> freqTolInQuantity;
     
    25582555    freqTolInHz = freqTolInQuantity.getValue("Hz");
    25592556  }
    2560   **/
    25612557 
    25622558  if ( in.size() < 2 ) {
     
    25792575  uInt newscanno = max(scannos)+1;
    25802576  ++it;
     2577
     2578  // new IFNO
     2579  uInt ifnoCounter = max(ifnocol.getColumn()) + 1;
     2580 
    25812581  while ( it != in.end() ){
    2582     /**
    25832582    // Check FREQUENCIES/BASEFRAME
    25842583    if ( out->frequencies().getFrame(true) != (*it)->frequencies().getFrame(true) ) {
    25852584      throw(AipsError("BASEFRAME is not identical"));
    25862585    }
    2587     **/
    25882586   
    25892587    if ( ! (*it)->conformant(*out) ) {
     
    26212619        (*it)->frequencies().getEntry(rp, rv, inc, rec.asuInt("FREQ_ID"));
    26222620        uInt id;
    2623         id = out->frequencies().addEntry(rp, rv, inc);
    2624         //if ( !out->frequencies().match(rp, rv, inc, freqTolInHz, id) ) {
    2625         //  id = out->frequencies().addEntry(rp, rv, inc);
    2626         //}
     2621       
     2622        // default value is new unique IFNO
     2623        uInt newifno = ifnoCounter;
     2624        uInt nchan = rec.asArrayFloat("SPECTRA").shape()[0];
     2625        //id = out->frequencies().addEntry(rp, rv, inc);
     2626        if ( !out->frequencies().match(rp, rv, inc, freqTolInHz, id) ) {
     2627          // add new entry to FREQUENCIES table
     2628          id = out->frequencies().addEntry(rp, rv, inc);
     2629
     2630          // increment counter for IFNO
     2631          ifnoCounter++;
     2632        }
     2633        else {
     2634          // should renumber IFNO to be same as existing rows that have same FREQ_ID
     2635          LogIO os(LogOrigin("STMath", "merge", WHERE));
     2636          Table outFreqIdSelected = tout(tout.col("FREQ_ID") == id);
     2637          TableIterator _iter(outFreqIdSelected, "IFNO");
     2638          map<uInt, uInt> nchanMap;
     2639          while (!_iter.pastEnd()) {
     2640            const Table _table = _iter.table();
     2641            ROTableRow _row(_table);
     2642            const TableRecord &_rec = _row.get(0);
     2643            uInt nchan = _rec.asArrayFloat("SPECTRA").shape()[0];
     2644            if (nchanMap.find(nchan) != nchanMap.end()) {
     2645              throw(AipsError("There are non-unique IFNOs assigned to spectra that have same FREQ_ID and same nchan. Something wrong."));
     2646            }
     2647            nchanMap[nchan] = _rec.asuInt("IFNO");
     2648            _iter.next();
     2649          }
     2650
     2651          os << LogIO::DEBUGGING << "nchanMap for " << id << ":" << LogIO::POST;
     2652          for (map<uInt, uInt>::iterator i = nchanMap.begin(); i != nchanMap.end(); ++i) {
     2653            os << LogIO::DEBUGGING << "nchanMap[" << i->first << "] = " << i->second << LogIO::POST;
     2654          }
     2655
     2656          if (nchanMap.find(nchan) == nchanMap.end()) {
     2657            // increment counter for IFNO
     2658            ifnoCounter++;
     2659          }
     2660          else {
     2661            // renumber IFNO to be same as existing value that corresponds to nchan
     2662            newifno = nchanMap[nchan];
     2663          }
     2664          os << LogIO::DEBUGGING << "newifno = " << newifno << LogIO::POST;
     2665        }
    26272666        thecolvals = id;
    26282667        freqidcol.putColumnRange(slice, thecolvals);
     2668
     2669        thecolvals = newifno;
     2670        ifnocol.putColumnRange(slice, thecolvals);
    26292671       
    26302672        // Set the proper MOLECULE_ID
  • trunk/src/STMath.h

    r2658 r2900  
    310310
    311311  casa::CountedPtr<Scantable>
    312     merge(const std::vector<casa::CountedPtr<Scantable> >& in);
     312    merge(const std::vector<casa::CountedPtr<Scantable> >& in,
     313          const std::string &freqTol = "");
    313314
    314315  casa::CountedPtr<Scantable>
  • trunk/src/STMathWrapper.h

    r2428 r2900  
    175175
    176176  ScantableWrapper
    177     merge(const std::vector<ScantableWrapper >& in)
    178 
     177    merge(const std::vector<ScantableWrapper >& in,
     178          const std::string &freqTol)
    179179  {
    180180    std::vector<casa::CountedPtr<Scantable> > sts;
    181181    for (unsigned int i=0; i<in.size(); ++i) sts.push_back(in[i].getCP());
    182     return ScantableWrapper(STMath::merge(sts)); }
     182    return ScantableWrapper(STMath::merge(sts, freqTol)); }
    183183
    184184  ScantableWrapper rotateXYPhase( const ScantableWrapper& in, float angle)
Note: See TracChangeset for help on using the changeset viewer.