LCOV - code coverage report
Current view: top level - msvis/MSVis - AveragingVi2Factory.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 14 14 100.0 %
Date: 2024-12-11 20:54:31 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  * AveragingViFactory.h
       3             :  *
       4             :  *  Created on: Feb 25, 2013
       5             :  *      Author: jjacobs
       6             :  */
       7             : 
       8             : #ifndef MSVIS_AVERAGINGVIFACTORY_H_
       9             : #define MSVIS_AVERAGINGVIFACTORY_H_
      10             : 
      11             : #include <msvis/MSVis/VisibilityIterator2.h>
      12             : 
      13             : namespace casa {
      14             : 
      15             : class MeasurementSet2;
      16             : 
      17             : namespace vi {
      18             : 
      19             : // AveragingOptions
      20             : //
      21             : // A container for the options that can be specified when creating
      22             : // an AveragingTvi2 based VI.  The user can specify which of the
      23             : // data cubes (observed, model and corrected) are to be averaged.
      24             : // The source of the weights applied to each cube can also be specified.
      25             : // See enum Options below for the symbols to use; the symbols are usually
      26             : // combined using bitwise-and ("|") in the constructor.
      27             : 
      28             : class AveragingOptions {
      29             : 
      30             : public:
      31             : 
      32             :     enum Options {Nothing = 0,
      33             :                   AverageObserved = 1 << 0,  // Average the observed data
      34             :                   AverageModel = 1 << 1,     // Average the model data
      35             :                   AverageCorrected = 1 << 2, // Average the corrected data
      36             :                   AverageFloat = 1 << 3,   // Average float (single dish) data
      37             :                   ObservedPlainAvg = 1 << 4,
      38             :                   ObservedFlagAvg = 1 << 5,
      39             :                   ObservedWeightAvgFromSIGMA = 1 << 6,
      40             :                   ObservedFlagWeightAvgFromSIGMA = 1 << 7,
      41             :                   ModelPlainAvg = 1 << 8,
      42             :                   ModelFlagAvg = 1 << 9,
      43             :                   ModelWeightAvgFromWEIGHT = 1 << 10,
      44             :                   ModelWeightAvgFromSIGMA = 1 << 11,
      45             :                   ModelFlagWeightAvgFromWEIGHT = 1 << 12,
      46             :                   ModelFlagWeightAvgFromSIGMA = 1 << 13,
      47             :                   CorrectedPlainAvg = 1 << 14,
      48             :                   CorrectedFlagAvg = 1 << 15,
      49             :                   CorrectedWeightAvgFromWEIGHT = 1 << 16,
      50             :                   CorrectedFlagWeightAvgFromWEIGHT = 1 << 17,
      51             :                   BaselineDependentAveraging = 1 << 18, // Do averaging with lengths dependent on baselines
      52             :                                                         // Requires specifying a max uvw distance parameter
      53             :                   phaseShifting = 1 << 19,
      54             :                   flagdataFlagPropagation = 1 << 20, // CAS-12737 - preserve existing flags
      55             :                   MarksLast
      56             :     };
      57             : 
      58        4361 :     AveragingOptions () : options_p (AverageObserved) {}
      59        4261 :     AveragingOptions (casacore::Int options) : options_p ((Options) options) {}
      60        5525 :     explicit AveragingOptions (Options o) : options_p (o) {}
      61             : 
      62             :     AveragingOptions operator& (const AveragingOptions & other) const
      63             :     {
      64             :         return AveragingOptions (other.options_p & options_p);
      65             :     }
      66             : 
      67             :     AveragingOptions operator| (const AveragingOptions & other) const
      68             :     {
      69             :         return AveragingOptions (other.options_p | options_p);
      70             :     }
      71             : 
      72             :     AveragingOptions & operator|= (const AveragingOptions & other)
      73             :     {
      74             :         * this = AveragingOptions (options_p | other.options_p);
      75             : 
      76             :         return * this;
      77             :     }
      78             : 
      79        4131 :     AveragingOptions & operator|= (Options options)
      80             :     {
      81        4131 :         * this = AveragingOptions (options_p | options);
      82             : 
      83        4131 :         return * this;
      84             :     }
      85             : 
      86             :     AveragingOptions operator~ () const
      87             :     {
      88             :         return AveragingOptions (~ options_p);
      89             :     }
      90             : 
      91      632584 :     casacore::Bool contains (Options o) const { return (o & options_p) != 0; }
      92             : 
      93             :     casacore::Int
      94        1470 :     nSet (casacore::Int o) const
      95             :     {
      96        1470 :         casacore::Int result = o & options_p;
      97        1470 :         casacore::Int nSet = 0;
      98             : 
      99       32340 :         for (casacore::Int mask = 1; mask < MarksLast; mask = mask << 1){
     100             : 
     101       30870 :             nSet += (result & mask) != 0 ? 1 : 0;
     102             : 
     103             :         }
     104             : 
     105        1470 :         return nSet;
     106             :     }
     107             : 
     108             : private:
     109             : 
     110             : 
     111             :     Options options_p;
     112             : };
     113             : 
     114             : class AveragingParameters {
     115             : 
     116             : public:
     117             : 
     118             :     AveragingParameters ();
     119             : 
     120             :     AveragingParameters (casacore::Double averagingInterval,
     121             :                          casacore::Double chunkInterval,
     122             :                          const SortColumns & sortColumns = SortColumns (),
     123             :                          const AveragingOptions & options = AveragingOptions (),
     124             :                          casacore::Double maxUvwDistance = 0,
     125             :                          WeightScaling * weightScalingForAveraging = 0,
     126             :                          casacore::Bool isWriteable = false,
     127             :                          casacore::Double dx = 0,
     128             :                          casacore::Double dy = 0);
     129             : 
     130             :     AveragingParameters (const AveragingParameters & other);
     131             : 
     132             :     AveragingParameters & operator= (const AveragingParameters & other);
     133             : 
     134             :     casacore::Double getAveragingInterval () const;
     135             :     casacore::Double getChunkInterval () const;
     136             :     casacore::Double getMaxUvwDistance () const;
     137             :     const AveragingOptions & getOptions() const;
     138             :     const SortColumns & getSortColumns () const;
     139             :     WeightScaling * getWeightScaling () const;
     140             :     casacore::Double getXpcOffset () const;
     141             :     casacore::Double getYpcOffset () const;
     142             :     casacore::Bool isWriteable () const;
     143             : 
     144             :     void setAveragingInterval (casacore::Double);
     145             :     void setChunkInterval (casacore::Double);
     146             :     void setSortColumns (const SortColumns &);
     147             :     void setOptions (const AveragingOptions &);
     148             :     void setMaxUvwDistance (casacore::Double);
     149             :     void setWeightScaling (WeightScaling *);
     150             :     void setWritable (casacore::Bool isWritable);
     151             :     void setPhaseShift (casacore::Double dx, casacore::Double dy);
     152             : 
     153             : private:
     154             : 
     155             :     void validate ();
     156             :     void validateOptions ();
     157             : 
     158             :     casacore::Double averagingInterval_p;
     159             :     AveragingOptions averagingOptions_p;
     160             :     casacore::Double chunkInterval_p;
     161             :     casacore::Double maxUvwDistance_p;
     162             :     SortColumns sortColumns_p;
     163             :     WeightScaling * weightScaling_p;
     164             :     casacore::Bool isWritable_p;
     165             :     casacore::Double XpcOffset_p;
     166             :     casacore::Double YpcOffset_p;
     167             : 
     168             :     VisBufferComponents2 allDataColumns () const;
     169             : 
     170             : };
     171             : 
     172             : // The AveragingVi2Factory is used to initialize a VisibilityIterator2 so that
     173             : // it performs time averaging.  The parameters are fairly straightforward:
     174             : //
     175             : // averagingInterval - the time period to average over
     176             : // chunkInterval - the time interval of an averaged chunk
     177             : // sortColumns - the usual set of sort columns.  The sort columns also determine
     178             : //               the boundaries of a chunk.  If a column is present in the sort
     179             : //               columns, then there will be no averaging across values with different
     180             : //               values of that column (e.g., scan_number, array_id, etc.).  This is
     181             : //               because a chunk is defined to be the set of records having the same
     182             : //               values for all of the sort columns except for time.  The time column
     183             : //               is used to select rows having the same sort-column values but within
     184             : //               a specified interval of time.
     185             : 
     186             : class AveragingVi2Factory : public ViFactory {
     187             : 
     188             : public:
     189             : 
     190             :     AveragingVi2Factory (const AveragingParameters & parameters,
     191             :                          casacore::MeasurementSet * ms);
     192             : 
     193             :     AveragingVi2Factory (const AveragingParameters & parameters,
     194             :                          casacore::MeasurementSet * ms1,
     195             :                          casacore::MeasurementSet * ms2,
     196             :                          ...);
     197             :     // use 0 to mark end of MSs
     198             : 
     199             :     AveragingVi2Factory (const AveragingParameters & parameters,
     200             :                          const casacore::Block<const casacore::MeasurementSet *> & mss);
     201             : 
     202             :     ~AveragingVi2Factory ();
     203             : 
     204             : protected:
     205             : 
     206             :     virtual ViImplementation2 * createVi () const;
     207             : 
     208             : private:
     209             : 
     210             :     void initialize (const AveragingParameters & parameters,
     211             :                      const casacore::Block<const casacore::MeasurementSet *> & mss);
     212             : 
     213             :     casacore::Block<const casacore::MeasurementSet *> mss_p;
     214             :     AveragingParameters parameters_p;
     215             : };
     216             : 
     217             : 
     218             : class AveragingVi2LayerFactory : public ViiLayerFactory {
     219             : 
     220             : public:
     221             : 
     222             :   AveragingVi2LayerFactory(const AveragingParameters& avepars);
     223             : 
     224         294 :   virtual ~AveragingVi2LayerFactory() {};
     225             : 
     226             :  protected:
     227             : 
     228             :   
     229             :   virtual ViImplementation2 * createInstance(ViImplementation2* vii0) const;
     230             : 
     231             :   const AveragingParameters avepars_p;
     232             : 
     233             : };
     234             : 
     235             : 
     236             : } // end namesapce vi
     237             : } // end namespace casa
     238             : 
     239             : 
     240             : #endif /* MSVIS_AVERAGINGVIFACTORY_H_ */

Generated by: LCOV version 1.16