LCOV - code coverage report
Current view: top level - singledish/SingleDish - BaselineTable.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 166 0.0 %
Date: 2024-10-10 19:51:30 Functions: 0 21 0.0 %

          Line data    Source code
       1             : //# BaselineTable.cc: this code defines baseline table
       2             : //# Copyright (C) 2015
       3             : //# National Astronomical Observatory of Japan
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id$
      27             : #include <assert.h>
      28             : 
      29             : #include <casacore/casa/Containers/ValueHolder.h>
      30             : #include <casacore/casa/Exceptions/Error.h>
      31             : #include <casacore/casa/OS/Path.h>
      32             : #include <casacore/measures/TableMeasures/TableMeasDesc.h>
      33             : #include <casacore/measures/TableMeasures/TableMeasRefDesc.h>
      34             : #include <casacore/measures/TableMeasures/TableMeasValueDesc.h>
      35             : #include <singledish/SingleDish/BaselineTable.h>
      36             : #include <stdcasa/StdCasa/CasacSupport.h>
      37             : #include <casacore/tables/Tables/TableDesc.h>
      38             : #include <casacore/tables/Tables/SetupNewTab.h>
      39             : #include <casacore/tables/Tables/ArrColDesc.h>
      40             : #include <casacore/tables/Tables/ScaColDesc.h>
      41             : #include <casacore/tables/Tables/TableRecord.h>
      42             : #include <casacore/tables/Tables/TableProxy.h>
      43             : 
      44             : using namespace casacore;
      45             : using namespace casacore;
      46             : using namespace casacore;
      47             : using namespace casacore;
      48             : using namespace casacore;
      49             : using namespace casacore;
      50             : using namespace casacore;
      51             : namespace casa {
      52             : 
      53             : const String BaselineTable::name_ = "APPLY_BASELINE";
      54             : 
      55           0 : BaselineTable::BaselineTable(const MeasurementSet& parent)
      56             : {
      57           0 :   TableDesc td("", "1", TableDesc::Scratch);
      58           0 :   td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
      59           0 :   td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
      60           0 :   td.addColumn(ScalarColumnDesc<uInt>("ANTNO"));
      61           0 :   td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
      62           0 :   td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
      63           0 :   td.addColumn(ScalarColumnDesc<Double>("TIME"));
      64           0 :   TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
      65           0 :   TableMeasValueDesc measVal(td, "TIME");
      66           0 :   TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
      67           0 :   mepochCol.write(td);
      68           0 :   String tabname = parent.tableName()+"/"+name_;
      69           0 :   SetupNewTable aNewTab(tabname, td, Table::Scratch);
      70           0 :   table_ = Table(aNewTab, Table::Memory);
      71           0 :   attachBaseColumns();
      72             : 
      73           0 :   table_.rwKeywordSet().define("VERSION", 1);
      74           0 :   table_.rwKeywordSet().define("MSName", parent.tableName());
      75           0 :   table_.rwKeywordSet().define("ApplyType", "NONE");
      76           0 :   table_.rwKeywordSet().defineTable("FREQUENCIES", parent.spectralWindow());
      77           0 :   table_.tableInfo().setType("ApplyTable");
      78           0 :   originaltable_ = table_;
      79             : 
      80           0 :   setup();
      81           0 : }
      82             : 
      83           0 : BaselineTable::BaselineTable(const String &name)
      84             : {
      85           0 :   table_ = Table(name, Table::Update);
      86           0 :   attachBaseColumns();
      87           0 :   originaltable_ = table_;
      88           0 :   attachOptionalColumns();
      89           0 : }
      90             : 
      91           0 : BaselineTable::~BaselineTable()
      92             : {
      93           0 : }
      94             : 
      95           0 : void BaselineTable::attach()
      96             : {
      97           0 :   attachBaseColumns();
      98           0 :   attachOptionalColumns();
      99           0 : }
     100             : 
     101           0 : void BaselineTable::attachBaseColumns()
     102             : {
     103           0 :   scanCol_.attach(table_, "SCANNO");
     104           0 :   beamCol_.attach(table_, "BEAMNO");
     105           0 :   antCol_.attach(table_, "ANTNO");
     106           0 :   ifCol_.attach(table_, "IFNO");
     107           0 :   timeCol_.attach(table_, "TIME");
     108           0 :   timeMeasCol_.attach(table_, "TIME");
     109           0 :   freqidCol_.attach(table_, "FREQ_ID");
     110           0 : }
     111           0 : void BaselineTable::setup()
     112             : {
     113           0 :   table_.addColumn(ArrayColumnDesc<Bool>("APPLY"));
     114           0 :   table_.addColumn(ArrayColumnDesc<uInt>("FUNC_TYPE"));
     115           0 :   table_.addColumn(ArrayColumnDesc<Int>("FUNC_PARAM"));
     116           0 :   table_.addColumn(ArrayColumnDesc<Float>("FUNC_FPARAM"));
     117           0 :   table_.addColumn(ArrayColumnDesc<uInt>("MASKLIST"));
     118           0 :   table_.addColumn(ArrayColumnDesc<Float>("RESULT"));
     119           0 :   table_.addColumn(ArrayColumnDesc<Float>("RMS"));
     120           0 :   table_.addColumn(ScalarColumnDesc<uInt>("NCHAN"));
     121           0 :   table_.addColumn(ArrayColumnDesc<Float>("CLIP_THRESHOLD"));
     122           0 :   table_.addColumn(ArrayColumnDesc<uInt>("CLIP_ITERATION"));
     123           0 :   table_.addColumn(ArrayColumnDesc<Bool>("USE_LF"));
     124           0 :   table_.addColumn(ArrayColumnDesc<Float>("LF_THRESHOLD"));
     125           0 :   table_.addColumn(ArrayColumnDesc<uInt>("LF_AVERAGE"));
     126           0 :   table_.addColumn(ArrayColumnDesc<uInt>("LF_EDGE"));
     127             : 
     128           0 :   table_.rwKeywordSet().define("ApplyType", "BASELINE");
     129             : 
     130           0 :   attachOptionalColumns();
     131           0 : }
     132             : 
     133           0 : void BaselineTable::attachOptionalColumns()
     134             : {
     135           0 :   applyCol_.attach(table_, "APPLY");
     136           0 :   ftypeCol_.attach(table_, "FUNC_TYPE");
     137           0 :   fparCol_.attach(table_, "FUNC_PARAM");
     138           0 :   ffparCol_.attach(table_, "FUNC_FPARAM");
     139           0 :   maskCol_.attach(table_, "MASKLIST");
     140           0 :   resCol_.attach(table_, "RESULT");
     141           0 :   rmsCol_.attach(table_, "RMS");
     142           0 :   nchanCol_.attach(table_, "NCHAN");
     143           0 :   cthresCol_.attach(table_, "CLIP_THRESHOLD");
     144           0 :   citerCol_.attach(table_, "CLIP_ITERATION");
     145           0 :   uselfCol_.attach(table_, "USE_LF");
     146           0 :   lfthresCol_.attach(table_, "LF_THRESHOLD");
     147           0 :   lfavgCol_.attach(table_, "LF_AVERAGE");
     148           0 :   lfedgeCol_.attach(table_, "LF_EDGE");
     149             : 
     150           0 :   ftypeCol_.rwKeywordSet().define("Polynomial",   BaselineType_kPolynomial);
     151           0 :   ftypeCol_.rwKeywordSet().define("Chebyshev",    BaselineType_kChebyshev);
     152           0 :   ftypeCol_.rwKeywordSet().define("Cubic Spline", BaselineType_kCubicSpline);
     153           0 :   ftypeCol_.rwKeywordSet().define("Sinusoid",     BaselineType_kSinusoid);
     154           0 : }
     155             : 
     156           0 : void BaselineTable::save(const std::string &filename)
     157             : {
     158           0 :   String inname(filename);
     159           0 :   Path path(inname);
     160           0 :   inname = path.expandedName();
     161           0 :   table_.deepCopy(inname, Table::New);
     162           0 : }
     163             : 
     164           0 : bool BaselineTable::getApply(uInt irow, uInt ipol) const
     165             : {
     166           0 :   Vector<Bool> apply = applyCol_.get(irow);
     167           0 :   return static_cast<bool>(apply[ipol]);
     168           0 : }
     169             : 
     170           0 : std::vector<bool> BaselineTable::getMask(uInt irow, uInt ipol)
     171             : {
     172           0 :   uInt nchan = nchanCol_.get(irow);
     173           0 :   Matrix<uInt> masklist = maskCol_.get(irow);
     174           0 :   return getMaskFromMaskList(nchan, masklist.row(ipol));
     175           0 : }
     176             : 
     177           0 : uint BaselineTable::getBaselineType(uInt irow, uInt ipol) const
     178             : {
     179           0 :   Vector<uInt> ftype = ftypeCol_.get(irow);
     180           0 :   return static_cast<uint>(ftype[ipol]);
     181           0 : }
     182             : 
     183           0 : int BaselineTable::getFPar(uInt irow, uInt ipol) const
     184             : {
     185           0 :   Vector<Int> fpar = fparCol_.get(irow);
     186           0 :   return static_cast<int>(fpar[ipol]);
     187           0 : }
     188             : 
     189           0 : void BaselineTable::setbasedata(uInt irow, uInt scanno, uInt beamno, uInt antno, 
     190             :                                 uInt ifno, uInt freqid, Double time)
     191             : {
     192           0 :   scanCol_.put(irow, scanno);
     193           0 :   beamCol_.put(irow, beamno);
     194           0 :   antCol_.put(irow, antno);
     195           0 :   ifCol_.put(irow, ifno);
     196           0 :   timeCol_.put(irow, time);
     197           0 :   freqidCol_.put(irow, freqid);
     198           0 : }
     199             : 
     200           0 : void BaselineTable::setdata(uInt irow, uInt scanno, 
     201             :                             uInt beamno, uInt antno, uInt ifno, 
     202             :                             uInt freqid, Double time, 
     203             :                             Array<Bool> apply, 
     204             :                             Array<uInt> ftype,
     205             :                             Array<Int> fpar, 
     206             :                             Array<Float> ffpar, 
     207             :                             Array<uInt> mask,
     208             :                             Array<Float> res,
     209             :                             Array<Float> rms, 
     210             :                             uInt nchan, 
     211             :                             Array<Float> cthres,
     212             :                             Array<uInt> citer, 
     213             :                             Array<Bool> uself, 
     214             :                             Array<Float> lfthres, 
     215             :                             Array<uInt> lfavg, 
     216             :                             Array<uInt> lfedge)
     217             : {
     218           0 :   if (irow >= (uInt)nrow()) {
     219           0 :     stringstream ss;
     220           0 :     ss << "row index out of range[irow=" << irow << "][nrow=" << nrow() << "]";
     221           0 :     throw AipsError(ss.str());
     222           0 :   }
     223             : 
     224           0 :   setbasedata(irow, scanno, beamno, antno, ifno, freqid, time);
     225           0 :   applyCol_.put(irow, apply);
     226           0 :   ftypeCol_.put(irow, ftype);
     227           0 :   fparCol_.put(irow, fpar);
     228           0 :   ffparCol_.put(irow, ffpar);
     229           0 :   maskCol_.put(irow, mask);
     230           0 :   resCol_.put(irow, res);
     231           0 :   rmsCol_.put(irow, rms);
     232           0 :   nchanCol_.put(irow, nchan);
     233           0 :   cthresCol_.put(irow, cthres);
     234           0 :   citerCol_.put(irow, citer);
     235           0 :   uselfCol_.put(irow, uself);
     236           0 :   lfthresCol_.put(irow, lfthres);
     237           0 :   lfavgCol_.put(irow, lfavg);
     238           0 :   lfedgeCol_.put(irow, lfedge);
     239           0 : }
     240             : 
     241           0 : void BaselineTable::appenddata(uInt scanno, uInt beamno, 
     242             :                                uInt antno, uInt ifno, 
     243             :                                uInt freqid, Double time, 
     244             :                                Array<Bool> apply, 
     245             :                                Array<uInt> ftype, 
     246             :                                Array<Int> fpar, 
     247             :                                Array<Float> ffpar, 
     248             :                                Array<uInt> mask,
     249             :                                Array<Float> res,
     250             :                                Array<Float> rms,
     251             :                                uInt nchan, 
     252             :                                Array<Float> cthres,
     253             :                                Array<uInt> citer, 
     254             :                                Array<Bool> uself, 
     255             :                                Array<Float> lfthres, 
     256             :                                Array<uInt> lfavg, 
     257             :                                Array<uInt> lfedge)
     258             : {
     259           0 :   uInt irow = nrow();
     260           0 :   table_.addRow(1, true);
     261           0 :   setdata(irow, scanno, beamno, antno, ifno, freqid, time, 
     262             :           apply, ftype, fpar, ffpar, mask, res, rms, 
     263             :           nchan, cthres, citer, uself, lfthres, lfavg, lfedge);
     264           0 : }
     265             : 
     266           0 : void BaselineTable::appendbasedata(int scanno, int beamno, 
     267             :                                    int antno, int ifno, 
     268             :                                    int freqid, Double time)
     269             : {
     270           0 :   uInt irow = nrow();
     271           0 :   table_.addRow(1, true);
     272           0 :   setbasedata(irow, uInt(scanno), uInt(beamno), uInt(antno), 
     273             :               uInt(ifno), uInt(freqid), time);
     274           0 : }
     275             : 
     276           0 : void BaselineTable::setresult(uInt irow, 
     277             :                               Vector<Float> res, 
     278             :                               Array<Float> rms)
     279             : {
     280           0 :   resCol_.put(irow, res);
     281           0 :   rmsCol_.put(irow, rms);
     282           0 : }
     283             : 
     284           0 : uInt BaselineTable::getNChan(int irow)
     285             : {
     286           0 :   return nchanCol_.get(irow);
     287             : }
     288             : 
     289           0 : uInt BaselineTable::nchan(uInt ifno)
     290             : {
     291           0 :   uInt tmp = ifno;
     292           0 :   return tmp;
     293             : }
     294             : 
     295           0 : std::vector<bool> BaselineTable::getMaskFromMaskList(uInt const nchan, Vector<uInt> const& masklist)
     296             : {
     297           0 :   if (masklist.size() % 2 != 0) {
     298           0 :     throw(AipsError("masklist must have even number of elements."));
     299             :   }
     300             : 
     301           0 :   std::vector<bool> res((int)nchan, false);
     302             : 
     303           0 :   for (uInt j = 0; j < masklist.size(); j += 2) {
     304           0 :     for (int i = masklist[j]; i <= min((Int)nchan-1, (Int)masklist[j+1]); ++i) {
     305           0 :       res[i] = true;
     306             :     }
     307           0 :     if (masklist[j+1] == nchan-1) {
     308           0 :       break;
     309             :     }
     310             :   }
     311             : 
     312           0 :   return res;
     313           0 : }
     314             : }

Generated by: LCOV version 1.16