LCOV - code coverage report
Current view: top level - msvis/MSVis - AveragingVi2Factory.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 162 0.0 %
Date: 2024-10-10 15:00:01 Functions: 0 33 0.0 %

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