LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - CalSolVi2Organizer.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 146 0.0 %
Date: 2024-10-12 00:35:29 Functions: 0 17 0.0 %

          Line data    Source code
       1             : //# CalSolVi2Organizer.cc: Definition of CalSolVi2Organizer
       2             : //# Copyright (C) 2016
       3             : //# Associated Universities, Inc. Washington DC, USA.
       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 adressed 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             : //#
      27             : 
      28             : 
      29             : //#include <casacore/ms/MeasurementSets/MeasurementSet.h>
      30             : #include <synthesis/MeasurementComponents/CalSolVi2Organizer.h>
      31             : #include <msvis/MSVis/IteratingParameters.h>
      32             : #include <msvis/MSVis/LayeredVi2Factory.h>
      33             : #include <msvis/MSVis/SimpleSimVi2.h>
      34             : #include <msvis/MSVis/AveragingTvi2.h>
      35             : #include <synthesis/MeasurementComponents/FiltrationTVI.h>
      36             : #include <casacore/casa/aips.h>
      37             : #include <iostream>
      38             : 
      39             : using namespace casacore;
      40             : 
      41             : namespace casa { //# NAMESPACE CASA - BEGIN
      42             : 
      43             : using namespace vi;
      44             :   
      45             : // Constructor
      46           0 : CalSolVi2Organizer::CalSolVi2Organizer() : 
      47           0 :   data_(NULL),
      48           0 :   cal_(NULL),
      49           0 :   chanave_(NULL),
      50           0 :   timeave_(NULL),
      51           0 :   polave_(NULL),
      52           0 :   calfilter_(NULL),
      53           0 :   factories_(),
      54           0 :   vi_(NULL)
      55             : {
      56             :   // nothing else
      57           0 : }
      58             : 
      59             : // Destructor
      60           0 : CalSolVi2Organizer::~CalSolVi2Organizer()
      61             : {
      62           0 :   cleanUp();
      63           0 : }
      64             : 
      65           0 : vi::VisibilityIterator2& CalSolVi2Organizer::makeFullVI() {
      66             : 
      67           0 :   AlwaysAssert(factories_.nelements()>0, casacore::AipsError);
      68             : 
      69           0 :   if (vi_) delete vi_;
      70           0 :   vi_=new VisibilityIterator2(factories_);
      71             : 
      72           0 :   return *vi_;
      73             : }
      74             : 
      75           0 : int CalSolVi2Organizer::countSolutions(casacore::Vector<int>& nChunkPerSolve) {
      76             : 
      77             :   // TBD:  Make this smart w.r.t. combine options...
      78             : 
      79           0 :   AlwaysAssert(factories_.nelements()>0, AipsError);
      80             : 
      81             :   // A local (temporary) VI2 using just the bottom layer
      82             :   //  This assumes each solutions constains data
      83             :   //  from one or more chunk in the bottom layer
      84             :   //  (i.e., one chunk contains data for at most
      85             :   //   one distict solution)
      86             :   // Using this VI2 (rather than the full one) ensures
      87             :   //  that we do not invoke the averaging layers
      88             :   //  in non-trivial ways
      89             :   //  (NB:the loop below will need to vi.origin() to
      90             :   //   examine times and indices to handle 
      91             :   //   non-trivial solution-counting cases, e.g.,
      92             :   //   combine='spw', etc.)
      93           0 :   VisibilityIterator2 vi(factories_(Slice(0,1,1)));
      94             : 
      95             :   // Q: is MS sort init cost too high here?
      96             : 
      97           0 :   Int nchunks(0);
      98           0 :   for (vi.originChunks();vi.moreChunks();vi.nextChunk()) {
      99           0 :     ++nchunks;
     100             :   }
     101             :   //  not needed!
     102             :   //    for (vi.origin();vi.more();vi.next()) 
     103             : 
     104             :   // Trivial, for now
     105             :   //  Later, this will be filled in comb*-dependent manner
     106           0 :   nChunkPerSolve.resize(nchunks);
     107           0 :   nChunkPerSolve.set(1);
     108             : 
     109           0 :   return nchunks;
     110             : 
     111           0 : }
     112             : 
     113             : 
     114           0 : void CalSolVi2Organizer::addDiskIO(MeasurementSet* ms,Float interval,
     115             :                                    Bool combobs,Bool combscan,
     116             :                                    Bool combfld,Bool combspw,
     117             :                                    Bool useMSIter2,
     118             :                                    std::shared_ptr<FrequencySelections> freqSel) 
     119             : {
     120             : 
     121             :   //  Must be first specified layer
     122           0 :   AlwaysAssert(factories_.nelements()==0, AipsError);
     123             : 
     124             : 
     125           0 :   Block<Int> sc;
     126           0 :   deriveVI2Sort(sc,combobs,combscan,combfld,combspw);
     127           0 :   IteratingParameters iterpar(interval,SortColumns(sc));
     128             : 
     129           0 :   auto diskLayerFactory=new VisIterImpl2LayerFactory(ms,iterpar,True,useMSIter2);
     130             : 
     131           0 :   if(freqSel)
     132           0 :     diskLayerFactory->setFrequencySelections(freqSel);
     133             : 
     134           0 :   data_ = diskLayerFactory;
     135             : 
     136           0 :   factories_.resize(1);
     137           0 :   factories_[0]=data_;
     138           0 : }
     139             : 
     140           0 : void CalSolVi2Organizer::addSimIO() {
     141             : 
     142             :   //  Must be first specified layer
     143           0 :   AlwaysAssert(factories_.nelements()==0, AipsError);
     144             : 
     145           0 :   SimpleSimVi2Parameters ss;
     146           0 :   data_=new SimpleSimVi2LayerFactory(ss);
     147             : 
     148           0 :   factories_.resize(1);
     149           0 :   factories_[0]=data_;
     150           0 : }
     151             : 
     152           0 : void CalSolVi2Organizer::addSimIO(const SimpleSimVi2Parameters& ss) {
     153             : 
     154             :   //  Must be first specified layer
     155           0 :   AlwaysAssert(factories_.nelements()==0, AipsError);
     156             : 
     157           0 :   data_=new SimpleSimVi2LayerFactory(ss);
     158             : 
     159           0 :   factories_.resize(1);
     160           0 :   factories_[0]=data_;
     161           0 : }
     162             : 
     163           0 : void CalSolVi2Organizer::addCalForSolving(Float calfactor) {
     164             : 
     165             :   // Must not have added one already!
     166           0 :   AlwaysAssert(!cal_, AipsError);
     167             : 
     168             :   //  Must be at least one other layer already...
     169           0 :   AlwaysAssert(factories_.nelements()>0, AipsError);
     170             : 
     171           0 :   CalibratingParameters cp(calfactor);
     172             :   // Make the layer factory
     173           0 :   cal_= new vi::CalSolvingVi2LayerFactory(cp);
     174             : 
     175             :   // Add it to the list...
     176           0 :   this->appendFactory(cal_);
     177             : 
     178           0 : }
     179             : 
     180             : //
     181           0 : void CalSolVi2Organizer::addCalForSolving(VisEquation& ve, const Bool& corrDepFlags) {
     182             : 
     183             :   // Must not have added one already!
     184           0 :   AlwaysAssert(!cal_, AipsError);
     185             : 
     186             :   //  Must be at least one other layer already...
     187           0 :   AlwaysAssert(factories_.nelements()>0, AipsError);
     188             : 
     189             :   // Make the layer factory
     190           0 :   cal_= new CalSolvingVi2LayerFactoryByVE(&ve,corrDepFlags);
     191             : 
     192             :   // Add it to the list...
     193           0 :   this->appendFactory(cal_);
     194             : 
     195           0 : }
     196             : 
     197             : 
     198           0 : void CalSolVi2Organizer::addChanAve(Vector<Int> chanbin) {
     199             : 
     200             :   // Must not have added one already!
     201           0 :   AlwaysAssert(!chanave_, AipsError);
     202             : 
     203             :   //  Must be at least one other layer already...
     204           0 :   AlwaysAssert(factories_.nelements()>0, AipsError);
     205             : 
     206             :   // Force no averaging with chanbin[i]=0 in ChannelAverageTVI
     207             :   //  (NB: chanbin[i]=1 means nchan averaging)
     208           0 :   chanbin(chanbin==1)=0;
     209             : 
     210           0 :   Record config;
     211           0 :   config.define("chanbin",chanbin);
     212             : 
     213             :   // Make the layer factory
     214           0 :   chanave_= new ChannelAverageTVILayerFactory(config);
     215             : 
     216             :   // Add it to the list...
     217           0 :   this->appendFactory(chanave_);
     218             : 
     219           0 : }
     220             : 
     221             : // Add time-averaging layer factory
     222           0 : void CalSolVi2Organizer::addTimeAve(Float timebin) {
     223             : 
     224             :   // Must not have added one already!
     225           0 :   AlwaysAssert(!timeave_, AipsError);
     226             : 
     227             :   //  Must be at least one other layer already...
     228           0 :   AlwaysAssert(factories_.nelements()>0, AipsError);
     229             : 
     230             :   AveragingOptions aveopt(AveragingOptions::AverageCorrected|
     231             :                           AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT|
     232             :                           AveragingOptions::AverageModel|
     233           0 :                           AveragingOptions::ModelPlainAvg);
     234           0 :   AveragingParameters avepar(timebin,0.0,SortColumns(),aveopt);
     235           0 :   timeave_ = new AveragingVi2LayerFactory(avepar);
     236             : 
     237             :   // Add it to the list...
     238           0 :   this->appendFactory(timeave_);
     239             : 
     240           0 : }
     241             : 
     242             : // Add data-filtering layer factory
     243           0 : void CalSolVi2Organizer::addCalFilter(Record const &config) {
     244             :   // Must not have added one already!
     245           0 :   AlwaysAssert(!timeave_, AipsError);
     246             : 
     247             :   //  Must be at least one other layer already...
     248           0 :   AlwaysAssert(factories_.nelements()>0, AipsError);
     249             : 
     250             :   // config must have "mode" field
     251           0 :   AlwaysAssert(config.isDefined("mode"), AipsError);
     252             : 
     253           0 :   Record configuration(config);
     254           0 :   String const mode = configuration.asString("mode");
     255           0 :   if (mode == "SDGAIN_OTFD") {
     256           0 :     configuration.define("type", (Int)FilteringType::SDDoubleCircleFilter);
     257             :   } else {
     258             :     // not supported
     259           0 :     configuration.define("type", (Int)FilteringType::NoTypeFilter);
     260             :   }
     261             : 
     262           0 :   calfilter_ = new FiltrationTVILayerFactory(configuration);
     263             : 
     264             :   // Add it to the list...
     265           0 :   this->appendFactory(calfilter_);
     266           0 : }
     267             : 
     268             : 
     269             : 
     270           0 : void CalSolVi2Organizer::addCorrCombine() {
     271             :   //  Must be at least one other layer already...
     272           0 :     AlwaysAssert(factories_.nelements()>0, AipsError);
     273             : 
     274           0 :   Record config;
     275           0 :   config.define("mode", "default");
     276           0 :   polave_= new PolAverageTVILayerFactory(config);
     277           0 :   this->appendFactory(polave_);
     278           0 : }
     279             : 
     280             : 
     281             : 
     282           0 : void CalSolVi2Organizer::appendFactory(ViiLayerFactory* f) {
     283             : 
     284           0 :   Int nf=factories_.nelements();
     285           0 :   factories_.resize(nf+1,True);  // copies exising values
     286           0 :   factories_[nf]=f;
     287             : 
     288           0 : }
     289             : 
     290             : 
     291           0 : void CalSolVi2Organizer::cleanUp() {
     292             : 
     293           0 :   if (vi_) delete vi_; vi_=NULL;
     294           0 :   if (data_) delete data_; data_=NULL;
     295           0 :   if (cal_) delete cal_;  cal_=NULL;
     296           0 :   if (chanave_) delete chanave_;  chanave_=NULL;
     297           0 :   if (timeave_) delete timeave_;  timeave_=NULL;
     298           0 :   if (polave_) delete polave_; polave_=NULL;
     299           0 :   if (calfilter_) delete calfilter_; calfilter_=NULL;
     300           0 :   factories_.resize(0);
     301             : 
     302           0 : }
     303             : 
     304           0 : void CalSolVi2Organizer::barf() {
     305             :   
     306           0 :   cout << "data_        = " << data_ << endl;
     307           0 :   cout << "cal_       = " << cal_ << endl;
     308           0 :   cout << "chanave_   = " << chanave_ << endl;
     309           0 :   cout << "timeave_   = " << timeave_ << endl;
     310           0 :   cout << "factories_ = " << factories_ << endl;
     311             : 
     312           0 :   if (vi_)
     313           0 :     cout << "VI Layers: " << vi_->ViiType() << endl;
     314             : 
     315           0 : }
     316             : 
     317           0 : void CalSolVi2Organizer::deriveVI2Sort(Block<Int>& sortcols, 
     318             :                                        Bool combobs,Bool combscan,
     319             :                                        Bool combfld,Bool combspw) 
     320             : {
     321             : 
     322             : /*  NB: interval is now just the prescribed averaging interval: min(solint,preavg)
     323             :      ---> no need to re-interpret it
     324             : 
     325             :   // Interpret solution interval for the VI2
     326             :   iterInterval=(max(interval(),DBL_MIN));
     327             :   if (interval() < 0.0) {   // means no interval (infinite solint)
     328             :     iterInterval=0.0;
     329             :     interval()=DBL_MAX;
     330             :   }
     331             : */  
     332           0 :   Bool verbose(False);
     333           0 :   if (verbose) {
     334             :     //cout << "   interval()=" << interval() ;
     335           0 :     cout << boolalpha << "; combobs =" << combobs;
     336           0 :     cout << boolalpha << "; combscan=" << combscan;
     337           0 :     cout << boolalpha << "; combfld =" << combfld ;
     338           0 :     cout << boolalpha << "; combspw =" << combspw ;
     339           0 :     cout << endl;
     340             :   }
     341             :   
     342           0 :   Int nsortcol(4+(combscan?0:1)+(combobs?0:1) );  // include room for scan,obs
     343           0 :   sortcols.resize(nsortcol);
     344           0 :   Int i(0);
     345           0 :   sortcols[i++]=MS::ARRAY_ID;
     346           0 :   if (!combobs) sortcols[i++]=MS::OBSERVATION_ID;  // force obsid boundaries
     347           0 :   if (!combscan) sortcols[i++]=MS::SCAN_NUMBER;  // force scan boundaries
     348           0 :   if (!combfld) sortcols[i++]=MS::FIELD_ID;      // force field boundaries
     349           0 :   if (!combspw) sortcols[i++]=MS::DATA_DESC_ID;  // force spw boundaries
     350           0 :   sortcols[i++]=MS::TIME;
     351           0 :   if (combfld) sortcols[i++]=MS::FIELD_ID;      // effectively ignore field boundaries
     352           0 :   if (combspw) sortcols[i++]=MS::DATA_DESC_ID;  // effectively ignore spw boundaries
     353             :   if (true || verbose) {
     354             :     //    cout << " sort sortcols: " << Vector<Int>(sortcols) << endl;
     355             :   }
     356             :   
     357           0 : }
     358             : 
     359             : 
     360             : 
     361             : 
     362             : 
     363             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16