LCOV - code coverage report
Current view: top level - msvis/MSVis - AveragingVi2Factory.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 96 149 64.4 %
Date: 2023-11-06 10:06:49 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         216 : AveragingParameters::AveragingParameters ()
      23             : : averagingInterval_p (0),
      24             :   averagingOptions_p (AveragingOptions ()),
      25             :   chunkInterval_p (0),
      26             :   sortColumns_p (SortColumns ()),
      27             :   weightScaling_p (0),
      28         216 :   isWritable_p(false)
      29         216 : {}
      30             : 
      31         362 : 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         362 :                                           Double dy)
      40             : : averagingInterval_p (averagingInterval),
      41             :   averagingOptions_p (options),
      42             :   chunkInterval_p (chunkInterval),
      43             :   maxUvwDistance_p (maxUvwDistance),
      44             :   sortColumns_p (sortColumns),
      45             :   weightScaling_p (weightScalingForAveraging),
      46             :   isWritable_p(isWriteable),
      47             :   XpcOffset_p(dx),
      48         362 :   YpcOffset_p(dy)
      49             : {
      50         362 :     Assert (averagingInterval > 0);
      51         362 :     Assert (chunkInterval >= 0);
      52         362 :     Assert (chunkInterval == 0 || chunkInterval >= averagingInterval);
      53         362 :     Assert (! options.contains (AveragingOptions::BaselineDependentAveraging) ||
      54             :             maxUvwDistance_p > 0.001);
      55             : 
      56         362 :     validateOptions (); // Throws if error
      57         362 : }
      58             : 
      59         508 : AveragingParameters::AveragingParameters (const AveragingParameters & other)
      60             : {
      61         508 :     * this = other;
      62         508 : }
      63             : 
      64             : AveragingParameters &
      65         724 : AveragingParameters::operator= (const AveragingParameters & other)
      66             : {
      67         724 :     if (this != & other){
      68             : 
      69         724 :         averagingInterval_p = other.averagingInterval_p;
      70         724 :         averagingOptions_p = other.averagingOptions_p;
      71         724 :         chunkInterval_p = other.chunkInterval_p;
      72         724 :         maxUvwDistance_p = other.maxUvwDistance_p;
      73         724 :         sortColumns_p = other.sortColumns_p;
      74         724 :         weightScaling_p = other.weightScaling_p;
      75         724 :         isWritable_p = other.isWritable_p;
      76         724 :         XpcOffset_p = other.XpcOffset_p;
      77         724 :         YpcOffset_p = other.YpcOffset_p;
      78             : 
      79         724 :         validate ();
      80             :     }
      81             : 
      82         724 :     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         216 : AveragingParameters::getChunkInterval () const
      95             : {
      96         216 :     Assert (chunkInterval_p >= 0);
      97             : 
      98         216 :     return chunkInterval_p;
      99             : }
     100             : 
     101             : Double
     102        1518 : AveragingParameters::getAveragingInterval () const
     103             : {
     104        1518 :     Assert (averagingInterval_p > 0);
     105             : 
     106        1518 :     return averagingInterval_p;
     107             : }
     108             : 
     109             : Double
     110         362 : AveragingParameters::getMaxUvwDistance () const
     111             : {
     112         362 :     return maxUvwDistance_p;
     113             : }
     114             : 
     115             : const AveragingOptions &
     116        1086 : AveragingParameters::getOptions () const
     117             : {
     118        1086 :     return averagingOptions_p;
     119             : }
     120             : 
     121             : const SortColumns &
     122         216 : AveragingParameters::getSortColumns () const
     123             : {
     124         216 :     return sortColumns_p;
     125             : }
     126             : 
     127             : WeightScaling *
     128         216 : AveragingParameters::getWeightScaling () const
     129             : {
     130         216 :     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         216 : AveragingParameters::isWriteable () const
     147             : {
     148         216 :     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         724 : AveragingParameters::validate()
     211             : {
     212         724 :     Assert (averagingInterval_p > 0);
     213         724 :     Assert (chunkInterval_p >= 0);
     214         724 :     Assert (chunkInterval_p == 0 || chunkInterval_p >= averagingInterval_p);
     215         724 :     Assert (! averagingOptions_p.contains (AveragingOptions::BaselineDependentAveraging) ||
     216             :             maxUvwDistance_p > 0.001);
     217             : 
     218         724 :     validateOptions (); // Throws if error
     219         724 : }
     220             : 
     221             : 
     222             : void
     223        1086 : AveragingParameters::validateOptions ()
     224             : {
     225             : 
     226        1086 :     if (averagingOptions_p.contains(AveragingOptions::AverageObserved))
     227             :     {
     228             : 
     229         450 :         Int bits  = AveragingOptions::ObservedPlainAvg |
     230             :                         AveragingOptions::ObservedFlagAvg |
     231             :                         AveragingOptions::ObservedWeightAvgFromSIGMA |
     232             :                         AveragingOptions::ObservedFlagWeightAvgFromSIGMA;
     233             : 
     234         450 :         Int nSet = averagingOptions_p.nSet (bits);
     235             : 
     236         450 :         ThrowIf (nSet > 1, "Inconsistent DATA weights options provided");
     237             : 
     238         450 :         ThrowIf (nSet == 0, "Need to specify DATA weighting option");
     239             :     }
     240             : 
     241             : 
     242        1086 :     if (averagingOptions_p.contains(AveragingOptions::AverageCorrected))
     243             :     {
     244             : 
     245         516 :         Int bits  = AveragingOptions::CorrectedPlainAvg |
     246             :                         AveragingOptions::CorrectedFlagAvg |
     247             :                         AveragingOptions::CorrectedWeightAvgFromWEIGHT |
     248             :                         AveragingOptions::CorrectedFlagWeightAvgFromWEIGHT;
     249             : 
     250         516 :         Int nSet = averagingOptions_p.nSet (bits);
     251             : 
     252         516 :         ThrowIf (nSet > 1, "Inconsistent CORRECTED_DATA weights options provided");
     253             : 
     254         516 :         ThrowIf (nSet == 0, "Need to specify CORRECTED_DATA weighting option");
     255             :     }
     256             : 
     257        1086 :     if (averagingOptions_p.contains(AveragingOptions::AverageModel))
     258             :     {
     259             : 
     260         498 :         Int bits  = AveragingOptions::ModelPlainAvg |
     261             :                         AveragingOptions::ModelFlagAvg |
     262             :                         AveragingOptions::ModelWeightAvgFromWEIGHT |
     263             :                         AveragingOptions::ModelWeightAvgFromSIGMA |
     264             :                         AveragingOptions::ModelFlagWeightAvgFromWEIGHT |
     265             :                         AveragingOptions::ModelFlagWeightAvgFromSIGMA;
     266             : 
     267         498 :         Int nSet = averagingOptions_p.nSet (bits);
     268             : 
     269         498 :         ThrowIf (nSet > 1, "Inconsistent MODEL_DATA weights options provided");
     270             : 
     271         498 :         ThrowIf (nSet == 0, "Need to specify MODEL_DATA weighting option");
     272             :     }
     273        1086 : }
     274             : 
     275         216 : AveragingVi2Factory::AveragingVi2Factory (const AveragingParameters & parameters,
     276         216 :                                           MeasurementSet * ms)
     277             : {
     278         432 :     Block <const MeasurementSet *> mss (1, ms);
     279             : 
     280         216 :     initialize (parameters, mss);
     281         216 : }
     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         216 : AveragingVi2Factory::~AveragingVi2Factory ()
     326             : {
     327         216 : }
     328             : 
     329             : 
     330             : void
     331         216 : AveragingVi2Factory::initialize (const AveragingParameters & parameters,
     332             :                                  const Block<const MeasurementSet *> & mss)
     333             : {
     334         216 :     parameters_p = parameters;
     335         216 :     mss_p = mss;
     336         216 : }
     337             : 
     338             : 
     339             : ViImplementation2 *
     340         216 : 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         216 :     Double chunkInterval = parameters_p.getChunkInterval ();
     348         216 :     Double chunkRatio = ceil (chunkInterval / parameters_p.getAveragingInterval ());
     349         216 :     chunkInterval = parameters_p.getAveragingInterval () * chunkRatio;
     350         216 :     Bool isWriteable = parameters_p.isWriteable();
     351             : 
     352             :     // Create a simple VI implementation to perform the reading.
     353             : 
     354         216 :     VisibilityIteratorImpl2 * vii2 = new VisibilityIteratorImpl2 (mss_p,
     355         216 :                                                                   parameters_p.getSortColumns (),
     356             :                                                                   chunkInterval,
     357         216 :                                                                   isWriteable);
     358             : 
     359         216 :     vii2->setWeightScaling (parameters_p.getWeightScaling());
     360             : 
     361         216 :     AveragingTvi2 * averagingTvi2 = new AveragingTvi2 (vii2, parameters_p);
     362             : 
     363         216 :     return averagingTvi2;
     364             : }
     365             : 
     366             : // AveragingVi2LayerFactory ctor
     367         146 : AveragingVi2LayerFactory::AveragingVi2LayerFactory(const AveragingParameters& avepars)
     368             :   : ViiLayerFactory(),
     369         146 :     avepars_p(avepars)
     370         146 : {}
     371             : 
     372             : // AveragingVi2-specific layer-creator
     373             : ViImplementation2*
     374         146 : AveragingVi2LayerFactory::createInstance (ViImplementation2* vii0) const 
     375             : {
     376             :     // Make the AveragintTvi2, using supplied ViImplementation2, and return it
     377         146 :     ViImplementation2 *vii = new AveragingTvi2(vii0,avepars_p);
     378         146 :     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