LCOV - code coverage report
Current view: top level - msvis/MSVis - AveragingVi2Factory.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 109 162 67.3 %
Date: 2024-10-12 00:35:29 Functions: 19 33 57.6 %

          Line data    Source code
       1             : /*
       2             :  * AveragingVi2Factory.cc
       3             :  *
       4             :  *  Created on: Feb 25, 2013
       5             :  *      Author: jjacobs
       6             :  */
       7             : 
       8             : 
       9             : #include <stdcasa/UtilJ.h>
      10             : #include <msvis/MSVis/AveragingVi2Factory.h>
      11             : #include <msvis/MSVis/VisibilityIterator2.h>
      12             : #include <msvis/MSVis/VisibilityIteratorImpl2.h>
      13             : #include <msvis/MSVis/AveragingTvi2.h>
      14             : #include <cstdarg>
      15             : 
      16             : using namespace std;
      17             : 
      18             : using namespace casacore;
      19             : namespace casa {
      20             : namespace vi {
      21             : 
      22          19 : AveragingParameters::AveragingParameters ()
      23          19 : : averagingInterval_p (0),
      24          19 :   averagingOptions_p (AveragingOptions ()),
      25          19 :   chunkInterval_p (0),
      26          19 :   sortColumns_p (SortColumns ()),
      27          19 :   weightScaling_p (0),
      28          19 :   isWritable_p(false)
      29          19 : {}
      30             : 
      31          36 : AveragingParameters::AveragingParameters (Double averagingInterval,
      32             :                                           Double chunkInterval,
      33             :                                           const SortColumns & sortColumns,
      34             :                                           const AveragingOptions & options,
      35             :                                           Double maxUvwDistance,
      36             :                                           WeightScaling * weightScalingForAveraging,
      37             :                                           Bool isWriteable,
      38             :                                           Double dx,
      39          36 :                                           Double dy)
      40          36 : : averagingInterval_p (averagingInterval),
      41          36 :   averagingOptions_p (options),
      42          36 :   chunkInterval_p (chunkInterval),
      43          36 :   maxUvwDistance_p (maxUvwDistance),
      44          36 :   sortColumns_p (sortColumns),
      45          36 :   weightScaling_p (weightScalingForAveraging),
      46          36 :   isWritable_p(isWriteable),
      47          36 :   XpcOffset_p(dx),
      48          36 :   YpcOffset_p(dy)
      49             : {
      50          36 :     Assert (averagingInterval > 0);
      51          36 :     Assert (chunkInterval >= 0);
      52          36 :     Assert (chunkInterval == 0 || chunkInterval >= averagingInterval);
      53          36 :     Assert (! options.contains (AveragingOptions::BaselineDependentAveraging) ||
      54             :             maxUvwDistance_p > 0.001);
      55             : 
      56          36 :     validateOptions (); // Throws if error
      57          36 : }
      58             : 
      59          53 : AveragingParameters::AveragingParameters (const AveragingParameters & other)
      60             : {
      61          53 :     * this = other;
      62          53 : }
      63             : 
      64             : AveragingParameters &
      65          72 : AveragingParameters::operator= (const AveragingParameters & other)
      66             : {
      67          72 :     if (this != & other){
      68             : 
      69          72 :         averagingInterval_p = other.averagingInterval_p;
      70          72 :         averagingOptions_p = other.averagingOptions_p;
      71          72 :         chunkInterval_p = other.chunkInterval_p;
      72          72 :         maxUvwDistance_p = other.maxUvwDistance_p;
      73          72 :         sortColumns_p = other.sortColumns_p;
      74          72 :         weightScaling_p = other.weightScaling_p;
      75          72 :         isWritable_p = other.isWritable_p;
      76          72 :         XpcOffset_p = other.XpcOffset_p;
      77          72 :         YpcOffset_p = other.YpcOffset_p;
      78             : 
      79          72 :         validate ();
      80             :     }
      81             : 
      82          72 :     return *this;
      83             : }
      84             : 
      85             : VisBufferComponents2
      86           0 : AveragingParameters::allDataColumns () const
      87             : {
      88             :     return VisBufferComponents2::these ({VisBufferComponent2::VisibilityModel,
      89             :                                          VisBufferComponent2::VisibilityObserved,
      90           0 :                                          VisBufferComponent2::VisibilityCorrected});
      91             : }
      92             : 
      93             : Double
      94          19 : AveragingParameters::getChunkInterval () const
      95             : {
      96          19 :     Assert (chunkInterval_p >= 0);
      97             : 
      98          19 :     return chunkInterval_p;
      99             : }
     100             : 
     101             : Double
     102         146 : AveragingParameters::getAveragingInterval () const
     103             : {
     104         146 :     Assert (averagingInterval_p > 0);
     105             : 
     106         146 :     return averagingInterval_p;
     107             : }
     108             : 
     109             : Double
     110          36 : AveragingParameters::getMaxUvwDistance () const
     111             : {
     112          36 :     return maxUvwDistance_p;
     113             : }
     114             : 
     115             : const AveragingOptions &
     116         108 : AveragingParameters::getOptions () const
     117             : {
     118         108 :     return averagingOptions_p;
     119             : }
     120             : 
     121             : const SortColumns &
     122          19 : AveragingParameters::getSortColumns () const
     123             : {
     124          19 :     return sortColumns_p;
     125             : }
     126             : 
     127             : WeightScaling *
     128          19 : AveragingParameters::getWeightScaling () const
     129             : {
     130          19 :     return weightScaling_p;
     131             : }
     132             : 
     133             : Double
     134           0 : AveragingParameters::getXpcOffset () const
     135             : {
     136           0 :     return XpcOffset_p;
     137             : }
     138             : 
     139             : Double
     140           0 : AveragingParameters::getYpcOffset () const
     141             : {
     142           0 :     return YpcOffset_p;
     143             : }
     144             : 
     145             : Bool
     146          19 : AveragingParameters::isWriteable () const
     147             : {
     148          19 :     return isWritable_p;
     149             : }
     150             : 
     151             : 
     152             : void
     153           0 : AveragingParameters::setChunkInterval (Double value)
     154             : {
     155           0 :     ThrowIf (value >= 0, "ChunkInterval must be >= 0.");
     156             : 
     157           0 :     chunkInterval_p = value;
     158           0 : }
     159             : 
     160             : void
     161           0 : AveragingParameters::setAveragingInterval (Double value)
     162             : {
     163           0 :     ThrowIf (value > 0, "AveragingInterval must be > 0.");
     164             : 
     165           0 :     averagingInterval_p = value;
     166           0 : }
     167             : 
     168             : void
     169           0 : AveragingParameters::setMaxUvwDistance (Double value)
     170             : {
     171           0 :     ThrowIf (value < 0, "MaxUvwDistance must be >= 0.");
     172             : 
     173           0 :     maxUvwDistance_p = value;
     174           0 : }
     175             : 
     176             : void
     177           0 : AveragingParameters::setOptions (const AveragingOptions & value)
     178             : {
     179           0 :     averagingOptions_p = value;
     180             : 
     181           0 :     validateOptions ();
     182           0 : }
     183             : 
     184             : void
     185           0 : AveragingParameters::setSortColumns (const SortColumns & value)
     186             : {
     187           0 :     sortColumns_p = value;
     188           0 : }
     189             : 
     190             : void
     191           0 : AveragingParameters::setWeightScaling (WeightScaling * value)
     192             : {
     193           0 :     weightScaling_p = value;
     194           0 : }
     195             : 
     196             : void
     197           0 : AveragingParameters::setWritable (Bool isWritable)
     198             : {
     199           0 :     isWritable_p = isWritable;
     200           0 : }
     201             : 
     202             : void
     203           0 : AveragingParameters::setPhaseShift (Double dx, Double dy)
     204             : {
     205           0 :         XpcOffset_p = dx;
     206           0 :         YpcOffset_p = dy;
     207           0 : }
     208             : 
     209             : void
     210          72 : AveragingParameters::validate()
     211             : {
     212          72 :     Assert (averagingInterval_p > 0);
     213          72 :     Assert (chunkInterval_p >= 0);
     214          72 :     Assert (chunkInterval_p == 0 || chunkInterval_p >= averagingInterval_p);
     215          72 :     Assert (! averagingOptions_p.contains (AveragingOptions::BaselineDependentAveraging) ||
     216             :             maxUvwDistance_p > 0.001);
     217             : 
     218          72 :     validateOptions (); // Throws if error
     219          72 : }
     220             : 
     221             : 
     222             : void
     223         108 : AveragingParameters::validateOptions ()
     224             : {
     225             : 
     226         108 :     if (averagingOptions_p.contains(AveragingOptions::AverageObserved))
     227             :     {
     228             : 
     229         105 :         Int bits  = AveragingOptions::ObservedPlainAvg |
     230             :                         AveragingOptions::ObservedFlagAvg |
     231             :                         AveragingOptions::ObservedWeightAvgFromSIGMA |
     232             :                         AveragingOptions::ObservedFlagWeightAvgFromSIGMA;
     233             : 
     234         105 :         Int nSet = averagingOptions_p.nSet (bits);
     235             : 
     236         105 :         ThrowIf (nSet > 1, "Inconsistent DATA weights options provided");
     237             : 
     238         105 :         ThrowIf (nSet == 0, "Need to specify DATA weighting option");
     239             :     }
     240             : 
     241             : 
     242         108 :     if (averagingOptions_p.contains(AveragingOptions::AverageCorrected))
     243             :     {
     244             : 
     245           6 :         Int bits  = AveragingOptions::CorrectedPlainAvg |
     246             :                         AveragingOptions::CorrectedFlagAvg |
     247             :                         AveragingOptions::CorrectedWeightAvgFromWEIGHT |
     248             :                         AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT;
     249             : 
     250           6 :         Int nSet = averagingOptions_p.nSet (bits);
     251             : 
     252           6 :         ThrowIf (nSet > 1, "Inconsistent CORRECTED_DATA weights options provided");
     253             : 
     254           6 :         ThrowIf (nSet == 0, "Need to specify CORRECTED_DATA weighting option");
     255             :     }
     256             : 
     257         108 :     if (averagingOptions_p.contains(AveragingOptions::AverageModel))
     258             :     {
     259             : 
     260           6 :         Int bits  = AveragingOptions::ModelPlainAvg |
     261             :                         AveragingOptions::ModelFlagAvg |
     262             :                         AveragingOptions::ModelWeightAvgFromWEIGHT |
     263             :                         AveragingOptions::ModelWeightAvgFromSIGMA |
     264             :                         AveragingOptions::ModelFlagWeightAvgFromWEIGHT |
     265             :                         AveragingOptions::ModelFlagWeightAvgFromSIGMA;
     266             : 
     267           6 :         Int nSet = averagingOptions_p.nSet (bits);
     268             : 
     269           6 :         ThrowIf (nSet > 1, "Inconsistent MODEL_DATA weights options provided");
     270             : 
     271           6 :         ThrowIf (nSet == 0, "Need to specify MODEL_DATA weighting option");
     272             :     }
     273         108 : }
     274             : 
     275          19 : AveragingVi2Factory::AveragingVi2Factory (const AveragingParameters & parameters,
     276          19 :                                           MeasurementSet * ms)
     277             : {
     278          19 :     Block <const MeasurementSet *> mss (1, ms);
     279             : 
     280          19 :     initialize (parameters, mss);
     281          19 : }
     282             : 
     283           0 : AveragingVi2Factory::AveragingVi2Factory  (const AveragingParameters & parameters,
     284             :                                            MeasurementSet * ms1,
     285             :                                            MeasurementSet * ms2,
     286           0 :                                            ...)
     287             : {
     288             :     // Capture the first argument directly into the stl vector
     289             : 
     290           0 :     vector<MeasurementSet *> mssV;
     291           0 :     mssV.push_back (ms1);
     292             : 
     293             :     va_list args;
     294             : 
     295           0 :     va_start (args, ms2);
     296             : 
     297           0 :     MeasurementSet * ms = va_arg (args, MeasurementSet *);
     298             : 
     299           0 :     while (ms != 0){
     300             : 
     301           0 :         mssV.push_back (ms);
     302             : 
     303           0 :         ms = va_arg (args, MeasurementSet *);
     304             :     }
     305             : 
     306             :     // Convert the stl vector to the casa Vector.
     307             : 
     308           0 :     Block <const MeasurementSet *> mss (mssV.size());
     309           0 :     for (uInt i = 0; i < mssV.size(); i++){
     310           0 :         mss [i] = mssV [i];
     311             :     }
     312             : 
     313             :     // Now have the other overload do the actual work.
     314             : 
     315           0 :     initialize (parameters, mss);
     316           0 : }
     317             : 
     318             : 
     319           0 : AveragingVi2Factory::AveragingVi2Factory (const AveragingParameters & parameters,
     320           0 :                                           const Block<const MeasurementSet *> & mss)
     321             : {
     322           0 :     initialize (parameters, mss);
     323           0 : }
     324             : 
     325          19 : AveragingVi2Factory::~AveragingVi2Factory ()
     326             : {
     327          19 : }
     328             : 
     329             : 
     330             : void
     331          19 : AveragingVi2Factory::initialize (const AveragingParameters & parameters,
     332             :                                  const Block<const MeasurementSet *> & mss)
     333             : {
     334          19 :     parameters_p = parameters;
     335          19 :     mss_p = mss;
     336          19 : }
     337             : 
     338             : 
     339             : ViImplementation2 *
     340          19 : AveragingVi2Factory::createVi () const
     341             : {
     342             : 
     343             :     // Make the chunk interval compatible with the averaging interval up rounding it up to
     344             :     // the nearest multiple of the averaging interval (e.g., chunkInterval 12 with averaging
     345             :     // interval of 5 is rounded to 15.
     346             : 
     347          19 :     Double chunkInterval = parameters_p.getChunkInterval ();
     348          19 :     Double chunkRatio = ceil (chunkInterval / parameters_p.getAveragingInterval ());
     349          19 :     chunkInterval = parameters_p.getAveragingInterval () * chunkRatio;
     350          19 :     Bool isWriteable = parameters_p.isWriteable();
     351             : 
     352             :     // Create a simple VI implementation to perform the reading.
     353             : 
     354          19 :     VisibilityIteratorImpl2 * vii2 = new VisibilityIteratorImpl2 (mss_p,
     355          19 :                                                                   parameters_p.getSortColumns (),
     356             :                                                                   chunkInterval,
     357          19 :                                                                   isWriteable);
     358             : 
     359          19 :     vii2->setWeightScaling (parameters_p.getWeightScaling());
     360             : 
     361          19 :     AveragingTvi2 * averagingTvi2 = new AveragingTvi2 (vii2, parameters_p);
     362             : 
     363          19 :     return averagingTvi2;
     364             : }
     365             : 
     366             : // AveragingVi2LayerFactory ctor
     367          17 : AveragingVi2LayerFactory::AveragingVi2LayerFactory(const AveragingParameters& avepars)
     368             :   : ViiLayerFactory(),
     369          17 :     avepars_p(avepars)
     370          17 : {}
     371             : 
     372             : // AveragingVi2-specific layer-creator
     373             : ViImplementation2*
     374          17 : AveragingVi2LayerFactory::createInstance (ViImplementation2* vii0) const 
     375             : {
     376             :     // Make the AveragintTvi2, using supplied ViImplementation2, and return it
     377          17 :     ViImplementation2 *vii = new AveragingTvi2(vii0,avepars_p);
     378          17 :     return vii;
     379             : }
     380             : 
     381             : 
     382             : 
     383             : 
     384             : 
     385             : } // end namesapce vi
     386             : using namespace casacore;
     387             : } // end namespace casa

Generated by: LCOV version 1.16