Changeset 2703


Ignore:
Timestamp:
12/19/12 19:19:53 (12 years ago)
Author:
Takeshi Nakazato
Message:

New Development: Yes

JIRA Issue: Yes CAS-4770, 4771, 4772

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

First version of calibration classes for sky calibration (STCalSkyPSAlma)
and Tsys calibration (STCalTsys), which are derived from base class
(STCalibration).

The caltable classes, STCalSky and STCalTsys, are renamed as STCalSkyTable
and STCalTsysTable, respectively.


Location:
trunk/src
Files:
8 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/CMakeLists.txt

    r2702 r2703  
    7171     ${SRCDIR}/PlotHelper.cpp
    7272     ${SRCDIR}/STApplyTable.cpp
    73      ${SRCDIR}/STCalTsys.cpp
    74      ${SRCDIR}/STCalSky.cpp )
     73     ${SRCDIR}/STCalTsysTable.cpp
     74     ${SRCDIR}/STCalSkyTable.cpp
     75     ${SRCDIR}/STCalibration.cpp
     76     ${SRCDIR}/STCalSkyPSAlma.cpp
     77     ${SRCDIR}/STCalTsys.cpp )
    7578
    7679set( ASAP_PYSRCS
  • trunk/src/STApplyTable.cpp

    r2696 r2703  
    55//
    66//
    7 // Author: Takeshi Nakazato
     7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp> (C) 2012
    88//
    99// Copyright: See COPYING file that comes with this distribution
     
    104104}
    105105
     106void STApplyTable::save(const String &name)
     107{
     108  table_.deepCopy(name, Table::New);
    106109}
     110
     111}
  • trunk/src/STApplyTable.h

    r2696 r2703  
    66// Base class for application tables.
    77//
    8 // Author: Takeshi Nakazato
     8// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp> (C) 2012
    99//
    1010// Copyright: See COPYING file that comes with this distribution
    1111//
    1212//
    13 #ifndef ASAPAPPLYTABLE_H
    14 #define ASAPAPPLYTABLE_H
     13#ifndef ASAP_APPLY_TABLE_H
     14#define ASAP_APPLY_TABLE_H
    1515
    1616#include <casa/Arrays/Vector.h>
     
    6767  void unsetSelection();
    6868
     69  void save(const casa::String &name);
     70
    6971protected:
    7072  void setbasedata(casa::uInt irow, casa::uInt scanno, casa::uInt cycleno,
  • trunk/src/STCalTsys.cpp

    r2696 r2703  
    55//
    66//
    7 // Author: Takeshi Nakazato
     7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp> (C) 2012
    88//
    99// Copyright: See COPYING file that comes with this distribution
    1010//
    1111//
    12 #include <casa/Exceptions/Error.h>
    13 #include <tables/Tables/TableDesc.h>
    14 #include <tables/Tables/SetupNewTab.h>
    15 #include <tables/Tables/ArrColDesc.h>
    16 #include <tables/Tables/ScaColDesc.h>
    17 #include <tables/Tables/TableRecord.h>
    18 #include <measures/TableMeasures/TableMeasDesc.h>
    19 #include <measures/TableMeasures/TableMeasRefDesc.h>
    20 #include <measures/TableMeasures/TableMeasValueDesc.h>
    2112
    22 #include "Scantable.h"
     13#include <vector>
     14#include "STSelector.h"
    2315#include "STCalTsys.h"
     16#include "RowAccumulator.h"
     17#include "STIdxIter.h"
     18#include "STDefs.h"
     19#include <atnf/PKSIO/SrcType.h>
    2420
     21#include <casa/Arrays/ArrayMath.h>
    2522
     23using namespace std;
    2624using namespace casa;
    2725
    2826namespace asap {
    29 
    30 const String STCalTsys::name_ = "APPLY_TSYS";
    31 
    32 STCalTsys::STCalTsys(const Scantable& parent)
    33   : STApplyTable(parent, name_)
     27  STCalTsys::STCalTsys(CountedPtr<Scantable> &s, vector<int> &iflist)
     28    : STCalibration(s),
     29      iflist_(iflist)
    3430{
    35   setup();
     31  applytable_ = new STCalTsysTable(*s);
    3632}
    3733
    38 STCalTsys::~STCalTsys()
     34void STCalTsys::calibrate()
    3935{
     36  STSelector selOrg = scantable_->getSelection();
     37  STSelector sel;
     38  sel.setIFs(iflist_);
     39  scantable_->setSelection(sel);
     40 
     41  fillCalTable();
     42
     43  scantable_->setSelection(selOrg);
    4044}
    4145
    42 void STCalTsys::setup()
     46void STCalTsys::fillCalTable()
    4347{
    44   table_.addColumn(ArrayColumnDesc<Float>("TSYS"));
    45   table_.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
     48  RowAccumulator acc(W_TINT);
     49 
     50  vector<string> cols(3);
     51  cols[0] = "IFNO";
     52  cols[1] = "POLNO";
     53  cols[2] = "BEAMNO";
     54  STIdxIterAcc iter(scantable_, cols);
    4655
    47   table_.rwKeywordSet().define("ApplyType", "TSYS");
     56  ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(scantable_->table(), "TIME");
     57  Vector<Double> timeSec = tcol->getColumn() * 86400.0;
     58  tcol->attach(scantable_->table(), "INTERVAL");
     59  Vector<Double> intervalSec = tcol->getColumn();
     60  delete tcol;
     61  ROScalarColumn<Float> *ecol = new ROScalarColumn<Float>(scantable_->table(), "ELEVATION");
     62  Vector<Float> elevation = ecol->getColumn();
     63  delete ecol;
    4864
    49   attachOptionalColumns();
     65  ROArrayColumn<Float> specCol(scantable_->table(), "TSYS");
     66  ROArrayColumn<uChar> flagCol(scantable_->table(), "FLAGTRA");
     67
     68  // dummy Tsys: the following process doesn't need Tsys but RowAccumulator
     69  //             requires to set it with spectral data
     70  Vector<Float> tsys(1, 1.0);
     71
     72  Double timeCen = 0.0;
     73  Float elCen = 0.0;
     74  uInt count = 0;
     75
     76  while(!iter.pastEnd()) {
     77    Vector<uInt> rows = iter.getRows(SHARE);
     78    Vector<uInt> current = iter.current();
     79    uInt len = rows.nelements();
     80    if (len == 0) {
     81      iter.next();
     82      continue;
     83    }
     84   
     85    uInt nchan = scantable_->nchan(scantable_->getIF(rows[0]));
     86    Vector<uChar> flag(nchan);
     87    Vector<Bool> bflag(nchan);
     88    Vector<Float> spec(nchan);
     89
     90    Vector<Double> timeSep(len);
     91    for (uInt i = 0; i < len-1; i++) {
     92      timeSep[i] = timeSec[rows[i+1]] - timeSec[rows[i]] ;
     93    }
     94    Double tMedian = median(timeSep(IPosition(1,0), IPosition(1,len-2)));
     95    timeSep[len-1] = tMedian * 10000.0 ; // any large value
     96
     97    uInt irow ;
     98    uInt jrow ;
     99    for (uInt i = 0; i < len; i++) {
     100      irow = rows[i];
     101      jrow = (i < len-1) ? rows[i+1] : rows[i];
     102      // accumulate data
     103      flagCol.get(irow, flag);
     104      convertArray(bflag, flag);
     105      specCol.get(irow, spec);
     106      if ( !allEQ(bflag,True) )
     107        acc.add( spec, !bflag, tsys, intervalSec[irow], timeSec[irow] ) ;
     108      timeCen += timeSec[irow];
     109      elCen += elevation[irow];
     110      count++;
     111
     112      // check time gap
     113      double gap = 2.0 * timeSep[i] / (intervalSec[jrow] + intervalSec[irow]);
     114      if ( gap > 5.0 ) {
     115        if ( acc.state() ) {
     116          acc.replaceNaN() ;
     117//           const Vector<Bool> &msk = acc.getMask();
     118//           convertArray(flag, !msk);
     119//           for (uInt k = 0; k < nchan; ++k) {
     120//             uChar userFlag = 1 << 7;
     121//             if (msk[k]==True) userFlag = 0 << 7;
     122//             flag(k) = userFlag;
     123//           }
     124          timeCen /= (Double)count * 86400.0; // sec->day
     125          elCen /= (Float)count;
     126          STCalTsysTable *p = dynamic_cast<STCalTsysTable *>(&(*applytable_));
     127          p->appenddata(0, 0, current[2], current[0], current[1],
     128                        timeCen, elCen, acc.getSpectrum());
     129        }
     130        acc.reset() ;
     131        timeCen = 0.0;
     132        elCen = 0.0;
     133        count = 0;
     134      }
     135    }
     136
     137    iter.next() ;
     138  }
    50139}
    51140
    52 void STCalTsys::attachOptionalColumns()
    53 {
    54   tsysCol_.attach(table_, "TSYS");
    55   elCol_.attach(table_,"ELEVATION");
    56  
    57141}
    58 
    59 void STCalTsys::setdata(uInt irow, uInt scanno, uInt cycleno,
    60                         uInt beamno, uInt ifno, uInt polno,
    61                         Double time, Float elevation, Vector<Float> tsys)
    62 {
    63   if (irow >= (uInt)nrow()) {
    64     throw AipsError("row index out of range");
    65   }
    66 
    67   if (!sel_.empty()) {
    68     os_.origin(LogOrigin("STCalTsys","setdata",WHERE));
    69     os_ << LogIO::WARN << "Data selection is effective. Specified row index may be wrong." << LogIO::POST;
    70   } 
    71 
    72   setbasedata(irow, scanno, cycleno, beamno, ifno, polno, time);
    73   elCol_.put(irow, elevation);
    74   tsysCol_.put(irow, tsys);
    75 }
    76 
    77 void STCalTsys::appenddata(uInt scanno, uInt cycleno,
    78                            uInt beamno, uInt ifno, uInt polno,
    79                            Double time, Float elevation, Vector<Float> tsys)
    80 {
    81   uInt irow = nrow();
    82   table_.addRow(1, True);
    83   setdata(irow, scanno, cycleno, beamno, ifno, polno, time, elevation, tsys);
    84 }
    85 }
  • trunk/src/STCalTsys.h

    r2696 r2703  
    44// Description:
    55//
    6 // ApplyTable for Tsys calibration.
    76//
    8 // Author: Takeshi Nakazato
     7// Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012
    98//
    109// Copyright: See COPYING file that comes with this distribution
    1110//
    1211//
    13 #ifndef ASAPCALTSYS_H
    14 #define ASAPCALTSYS_H
     12#ifndef ASAP_CALTSYS_H
     13#define ASAP_CALTSYS_H
    1514
    16 #include <tables/Tables/ArrayColumn.h>
    17 #include <tables/Tables/ScalarColumn.h>
     15#include <memory>
     16#include <vector>
    1817
     18#include <casa/aips.h>
     19#include <casa/Arrays/Vector.h>
     20#include <casa/BasicSL/String.h>
     21#include <casa/Utilities/CountedPtr.h>
     22
     23#include <scimath/Mathematics/InterpolateArray1D.h>
     24
     25#include "RowAccumulator.h"
    1926#include "Scantable.h"
     27#include "STDefs.h"
    2028#include "STApplyTable.h"
     29#include "STCalibration.h"
     30#include "STCalTsysTable.h"
     31
    2132
    2233namespace asap {
    2334
    2435/**
    25 ApplyTable for Tsys calibration
     36 * Calibration operations on Scantable objects
     37 * @author TakeshiNakazato
     38 */
     39class STCalTsys : public STCalibration {
     40public:
     41  STCalTsys(casa::CountedPtr<Scantable> &s, vector<int> &iflist);
    2642
    27 @author Takeshi Nakazato
    28 @date $Date:$
    29 @version $Revision:$
    30 */
    31 class STCalTsys : public STApplyTable {
    32 public:
    33   STCalTsys() {;}
    34   STCalTsys(const Scantable& parent);
     43  virtual void calibrate();
    3544
    36   virtual ~STCalTsys();
     45  ~STCalTsys() {;}
     46private:
     47  void fillCalTable();
    3748
    38   void setup();
    39   const casa::String& name() const {return name_;};
    40 
    41   void attachOptionalColumns();
    42 
    43   void setdata(casa::uInt irow, casa::uInt scanno, casa::uInt cycleno,
    44                casa::uInt beamno, casa::uInt ifno,
    45                casa::uInt polno, casa::Double time, casa::Float elevation,
    46                casa::Vector<casa::Float> tsys);
    47   void appenddata(casa::uInt scanno, casa::uInt cycleno,
    48                   casa::uInt beamno, casa::uInt ifno, casa::uInt polno,
    49                   casa::Double time, casa::Float elevation,
    50                   casa::Vector<casa::Float> tsys);
    51  
    52   casa::Vector<casa::Float> getElevation() {return elCol_.getColumn();}
    53   casa::Matrix<casa::Float> getTsys() {return tsysCol_.getColumn();}
    54 
    55 private:
    56   static const casa::String name_ ;
    57   casa::ArrayColumn<casa::Float> tsysCol_;
    58   casa::ScalarColumn<casa::Float> elCol_;
     49  vector<int> iflist_;
    5950};
    6051
    6152}
    62 
    6353#endif
Note: See TracChangeset for help on using the changeset viewer.