LCOV - code coverage report
Current view: top level - calanalysis/CalAnalysis - CalAnalysis.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 29 0.0 %
Date: 2024-10-10 19:51:30 Functions: 0 10 0.0 %

          Line data    Source code
       1             : 
       2             : // -----------------------------------------------------------------------------
       3             : 
       4             : /*
       5             : 
       6             : CalAnalysis.h
       7             : 
       8             : Description:
       9             : ------------
      10             : This header file contains definitions for the CalStats class.
      11             : 
      12             : Classes:
      13             : --------
      14             : CalAnalysis - This class acts as the interface between the ROCTIter and CalStats
      15             :               classes.
      16             : 
      17             : Modification history:
      18             : ---------------------
      19             : 2012 Jan 20 - Nick Elias, NRAO
      20             :               Initial version.
      21             : 2012 Jan 25 - Nick Elias, NRAO
      22             :               Logging capability added.  Error checking added.
      23             : 2012 Feb 14 - Nick Elias, NRAO
      24             :               Updated this code to reflect changes in NewCalTabIter (now
      25             :               ROCTIter) and other classes.
      26             : 
      27             : */
      28             : 
      29             : // -----------------------------------------------------------------------------
      30             : // Start of define macro to prevent multiple loading
      31             : // -----------------------------------------------------------------------------
      32             : 
      33             : #ifndef CAL_ANALYSIS_H
      34             : #define CAL_ANALYSIS_H
      35             : 
      36             : // -----------------------------------------------------------------------------
      37             : // Includes
      38             : // -----------------------------------------------------------------------------
      39             : 
      40             : #include <casacore/casa/BasicSL/String.h>
      41             : 
      42             : #include <iostream>
      43             : #include <sstream>
      44             : using namespace std;
      45             : 
      46             : #include <casacore/casa/Exceptions/Error.h>
      47             : #include <casacore/casa/Logging/LogIO.h>
      48             : 
      49             : #include <casacore/casa/Containers/Block.h>
      50             : 
      51             : #include <casacore/casa/Arrays/Array.h>
      52             : #include <casacore/casa/Arrays/ArrayIter.h>
      53             : #include <casacore/casa/Arrays/Cube.h>
      54             : #include <casacore/casa/Arrays/Slicer.h>
      55             : #include <casacore/casa/Arrays/ArrayMath.h>
      56             : 
      57             : #include <casacore/tables/Tables/Table.h>
      58             : #include <casacore/tables/Tables/TableProxy.h>
      59             : 
      60             : #include <casacore/casa/Containers/Record.h>
      61             : #include <casacore/casa/Containers/RecordField.h>
      62             : 
      63             : #include <casacore/casa/Utilities/GenSort.h>
      64             : 
      65             : #include <casacore/ms/MeasurementSets/MSSpectralWindow.h>
      66             : #include <casacore/ms/MeasurementSets/MSSpWindowColumns.h>
      67             : 
      68             : #include <synthesis/CalTables/NewCalTable.h>
      69             : #include <synthesis/CalTables/CTIter.h>
      70             : 
      71             : #include <calanalysis/CalAnalysis/CalStats.h>
      72             : #include <calanalysis/CalAnalysis/CalStatsDerived.h>
      73             : #include <calanalysis/CalAnalysis/CalStatsFitter.h>
      74             : 
      75             : // -----------------------------------------------------------------------------
      76             : // Start of casa namespace
      77             : // -----------------------------------------------------------------------------
      78             : 
      79             : namespace casa {
      80             : 
      81             : // -----------------------------------------------------------------------------
      82             : // Start of CalAnalysis class definition
      83             : // -----------------------------------------------------------------------------
      84             : 
      85             : /*
      86             : 
      87             : CalAnalysis
      88             : 
      89             : Description:
      90             : ------------
      91             : This class acts as the interface between the ROCTIter and CalAnalysis classes.
      92             : 
      93             : In a nutshell:
      94             : --------------
      95             : * The constructor gets the information from the new format calibration table
      96             :   and initializes the class.
      97             : * The stats<T>() function calculates statistics (the type depends on T) and
      98             :   returns the results.
      99             :   - The user can specify the field(s), antenna 1s, antenna 2s, time range,
     100             :     feeds, spectral windows, channels, the second iteration axis for the 
     101             :     CalStats class (time or frequency), normalization, and unwrapping.
     102             :   - The inputs are checked and fixed, if possible.
     103             :   - The data are grouped according to unique (field,antenna1,antenna2).
     104             :   - The resulting group-based information is fed to the CalStats class and its
     105             :     stats<T>() function calculates the desired statistics which are stored in a
     106             :     vector of OUTPUT<T>() instances.  Each OUTPUT<T>() element corresponds to a
     107             :     group.
     108             : 
     109             : NB: There are a lot of get/set member functions.  Unfortunately, they could not
     110             :     be overloaded with the same names because of conflicts with corresponding
     111             :     member functions without get/set in their names.  Plus, some get functions
     112             :     need to call other get functions.
     113             : 
     114             : NB: When an instance of this class is created from the python binding, input
     115             :     parameters are mostly checked there.  There is checking in this class as
     116             :     well, just in case that the class is not called from the python binding.
     117             :     There does not appear to be a significant speed penalty.
     118             : 
     119             : Nested classes:
     120             : ---------------
     121             : OUTPUT<T> - This nested class contains the outputs for the
     122             :             CalAnalysis::stats<T>() template member function.
     123             : 
     124             : Class public member functions:
     125             : ------------------------------
     126             : CalAnalysis  - This constructor gets information from the new format calibration
     127             :                table for further processing by the stats<T>() function.
     128             : ~CalAnalysis - This destructor deallocates the internal memory of an instance.
     129             : calName      - This member function returns the new format calibration table
     130             :                name.
     131             : msName       - This member function returns the associated casacore::MS name.
     132             : visCal       - This member function returns the visibility calibration type.
     133             : parType      - This member function returns the parameter type ("Complex" or
     134             :                "Float").
     135             : polBasis     - This member function returns the polarization basis ("L" or "C").
     136             : field        - This member function returns the field numbers.
     137             : antenna      - This member function returns the antenna numbers.
     138             : antenna1     - This member function returns the antenna 1 numbers.
     139             : antenna2     - This member function returns the antenna 2 numbers.
     140             : time         - This member function returns the times.
     141             : feed         - This member function returns the feeds.
     142             : numspw       - This member function returns the number of spectral windows.
     143             : spw          - This member function returns the spectral windows.
     144             : numChannel   - This member function returns the number of channels for each
     145             :                spectral window.
     146             : freq         - This member function returns the frequencies for each spectral
     147             :                window.
     148             : 
     149             : Class template public member functions:
     150             : ---------------------------------------
     151             : stats<T> - This member function is the main user interface for calculating the
     152             :            statistics for all iterations.  Allowed T: CalStats::NONE only
     153             :            returns the input data, CalStatsFitter::FIT calculates fit
     154             :            statistics, and CalStatsHist::HIST calculates histogram statistics.
     155             : 
     156             : Class template static public member functions:
     157             : ----------------------------------------------
     158             : exists<T> - This member function determines whether a value appears in a vector.
     159             : where<T>  - This member function returns the index of a search value in a
     160             :             vector.
     161             : unique<T> - This member function returns a unique vector from an input vector.
     162             : 
     163             : Class private member functions:
     164             : -------------------------------
     165             : calNameGet      - This member function gets the new format calibration table
     166             :                   name from the new format calibration table.
     167             : calNameSet      - This member function sets the new format calibration table
     168             :                   name private variable.
     169             : msNameGet       - This member function gets the associated casacore::MS name from the new
     170             :                   format calibration table.
     171             : msNameSet       - This member function sets the associated casacore::MS name private
     172             :                   variable.
     173             : visCalGet       - This member function gets the visibility calibration type from
     174             :                   the new format calibration table.
     175             : visCalSet       - This member function sets the visibility calibration type
     176             :                   private variable.
     177             : parTypeGet      - This member function gets the parameter type ("Complex" or
     178             :                   "Float") from the new format calibration table.
     179             : parTypeSet      - This member function sets the parameter type ("Complex" or
     180             :                   "Float") private variable.
     181             : polBasisGet     - This member function gets the polarization basis ("L" or "C")
     182             :                   from the new format calibration table.
     183             : polBasisSet     - This member function sets the polarization basis ("L" or "C")
     184             :                   private variable.
     185             : fieldGet        - This member function gets the field numbers from the new
     186             :                   format calibration table.
     187             : fieldSet        - This member function sets the field numbers private variables.
     188             : fieldCheck      - This member function checks the input field vector and returns
     189             :                   the fixed field vector.
     190             : antennaGet      - This member function gets the antenna numbers from the new
     191             :                   format calibration table.
     192             : antennaSet      - This member function sets the antenna numbers private
     193             :                   variables.
     194             : antenna1Get     - This member function gets the antenna 1 numbers from the new
     195             :                   format calibration table.
     196             : antenna1Set     - This member function sets the antenna 1 numbers private
     197             :                   variables.
     198             : antenna1Check   - This member function checks the input antenna 1 vector and
     199             :                   returns the fixed antenna 1 vector.
     200             : antenna2Get     - This member function gets the antenna 2 numbers from the new
     201             :                   format calibration table.
     202             : antenna2Set     - This member function sets the antenna 2 numbers private
     203             :                   variables.
     204             : antenna2Check   - This member function checks the input antenna 2 vector and
     205             :                   returns the fixed antenna 2 vector.
     206             : timeGet         - This member function gets the times from the new format
     207             :                   calibration table.
     208             : timeSet         - This member function sets the times private variables.
     209             : timeCheck       - This member function checks the time range and returns the
     210             :                   corresponding time vector.
     211             : feedGet         - This member function gets the feeds from the new format
     212             :                   calibration table.
     213             : feedSet         - This member function sets the feeds private variables.
     214             : feedCheck       - This member function checks the input feed vector and returns
     215             :                   the fixed feed vector.
     216             : spwInfoGet      - This member function gets the spectral window information from
     217             :                   the new format calibration table.
     218             : spwInfoSet      - This member function sets the spectral window information
     219             :                   private variables.
     220             : statsCheckInput - This member function checks and fixes (if possible) the inputs
     221             :                   to the CalAnalysis::stats<T>() member function.
     222             : getGroup        - This member function gets input selected rows from a new
     223             :                   format calibration table and groups them according to unique
     224             :                   (field,antenna1,antenna2).
     225             : rowSelect       - This member function returns the rows selected by the input
     226             :                   parameters.
     227             : rowGroup        - This member function returns the row numbers, fields, antenna
     228             :                   1s, antenna 2s, spectral windows, unique spectral windows,
     229             :                   times, and unique times grouped according to selected rows and
     230             :                   input selection.
     231             : chanSPW         - This member function maps the spectral windows to the input
     232             :                   spectral windows (to get the correct channels) and forms the
     233             :                   start channels so that spectral windows can be concatenated.
     234             : freqGroup       - This member function concatenates the frequencies from
     235             :                   multiple spectral windows for each group.
     236             : cubeGroup       - This member function concatenates data from multiple rows into
     237             :                   groups according to unique (field,antenna1,antenna2).
     238             : 
     239             : Class protected member functions:
     240             : ---------------------------------
     241             : CalAnalysis - This default constructor is unused by this class and unavailable
     242             :               when an instance is created.
     243             : CalAnalysis - This copy constructor is unused by this class and unavailable when
     244             :               an instance is created.
     245             : operator=   - This operator= function is unused by this class and unavailable
     246             :               when an instance is created.
     247             : 
     248             : Modification history:
     249             : ---------------------
     250             : 2012 Jan 20 - Nick Elias, NRAO
     251             :               Initial version created with public member functions CalAnalysis()
     252             :               (generic), ~CalAnalysis(); template static public member function
     253             :               stats<T>(); template public member functions exists<T>() and
     254             :               unique<T>(); private member functions tableType(), polBasisGet(),
     255             :               feedCheck(), timeCheck(), spw_channel(), freq(); template private
     256             :               member functions parse<T>(), and select<T>(); and protected member
     257             :               functions CalAnalysis() (default), CalAnalysis() (copy), and
     258             :               operator=().
     259             : 2012 Feb 14 - Nick Elias, NRAO
     260             :               Updated this code to reflect changes in NewCalTabIter (now
     261             :               ROCTIter) and other classes.  Added the RAP enum.
     262             : 2012 Mar 13 - Nick Elias, NRAO
     263             :               Public member function tableType() renamed to parTypeGet().
     264             :               Private member functions msNameGet() and visCalGet() added.
     265             : 2012 Mar 14 - Nick Elias, NRAO
     266             :               Spectral window ID, start channel, and stop channel added to the
     267             :               nested OUTPUT<T> class.
     268             : 2012 Apr 03 - Nick Elias, NRAO
     269             :               Private member function calNameGet() added.  Public member
     270             :               functions calName(), msName(), visCal(), parType(), and polBasis()
     271             :               added.
     272             : 2012 Apr 04 - Nick Elias, NRAO
     273             :               Private member functions calNameSet(), msNameSet(), visCalSet(),
     274             :               parTypeSet(), polBasisSet(), feedGet(), feedSet(), timeGet(),
     275             :               timeSet(), spwGet(), and spwSet() added.  Public member functions
     276             :               feed(), time(), spw(), and numspw() added.
     277             : 2012 Apr 17 - Nick Elias, NRAO
     278             :               Nested class CalAnalysis::SPW_INFO() added.  Private member
     279             :               functions fieldGet(), fieldSet(), fieldCheck(), antennaGet(),
     280             :               antennaSet(), antennaCheck(), spwInfoGet(), and spwInfoSet()
     281             :               added.  Public member functions field(), antenna(), numChannel(),
     282             :               and freq() added.  Private member functions spwGet(), spwSet(),
     283             :               and spw_channel() removed.
     284             : 2012 Apr 25 - Nick Elias, NRAO
     285             :               Private member function antennaCheck() renamed to antenna1Check().
     286             :               private member function antenna2Check() added.  The start and stop
     287             :               channel lists versus spectral window are replaced with a channel
     288             :               list versus spectral window.
     289             : 2012 Apr 26 - Nick Elias, NRAO
     290             :               Nested class INPUT added (for the stats<T>() member function).
     291             :               Spectral window ID, start channel, and stop channel removed from
     292             :               the nested OUTPUT<T> class.
     293             : 2012 Apr 27 - Nick Elias, NRAO
     294             :               Private member function statsCheckInput() added.  The member
     295             :               functions of the nested class CalAnalysis::SPW_INFO() have been
     296             :               moved to a separate file CalAnalysisSPW_INFO.cc.
     297             : 2012 May 02 - Nick Elias, NRAO
     298             :               Private member functions antenna1Get(), antenna1Set(),
     299             :               antenna2Get(), and antenna2Set() added.
     300             : 2012 May 06 - Nick Elias, NRAO
     301             :               casacore::Template private member functions parse<T>() and select<T>()
     302             :               removed.  casacore::Template static public member function where<T>() added.
     303             :               Private member functions getGroup(), rowSelect(), rowGroup(),
     304             :               chanSPW(), freqGroup(), and cubeGroup() added.
     305             : 2012 May 07 - Nick Elias, NRAO
     306             :               Public member functions antenna1() and antenna2() added.
     307             : 
     308             : */
     309             : 
     310             : // -----------------------------------------------------------------------------
     311             : 
     312             : class CalAnalysis {
     313             : 
     314             :   public:
     315             : 
     316             :     // Real/Amplitude/Phase enums
     317             :     typedef enum RAP {
     318             :       INIT=-1, REAL=0, AMPLITUDE, PHASE
     319             :     } RAP;
     320             : 
     321             :     // SPW_INFO nested class
     322             :     class SPW_INFO {
     323             :       public:
     324             :         casacore::Bool bValid;
     325             :         casacore::uInt uiNumSPW;
     326             :         casacore::Vector<casacore::uInt> oSPW;
     327             :         casacore::Vector<casacore::uInt> oNumChannel;
     328             :         casacore::Vector<casacore::Vector<casacore::Double> > oFrequency;
     329             :         SPW_INFO( const casacore::String& oTableName );
     330             :         SPW_INFO( const SPW_INFO& oSPWInfoIn );
     331             :         SPW_INFO( void );
     332             :         ~SPW_INFO( void );
     333             :         SPW_INFO& operator=( const SPW_INFO& oSPWInfoIn );
     334             :         casacore::Bool freq( const casacore::Vector<casacore::uInt>& oSPWIn,
     335             :             const casacore::Vector<casacore::Vector<casacore::uInt> >& oChannelIn,
     336             :             casacore::Vector<casacore::Double>& oFreqOut ) const;
     337             :         casacore::Bool spwInfoCheck( const casacore::Vector<casacore::uInt>& oSPWIn,
     338             :             const casacore::Vector<casacore::Vector<casacore::uInt> >& oChannelIn, casacore::Vector<casacore::uInt>& oSPWOut,
     339             :             casacore::Vector<casacore::Vector<casacore::uInt> >& oChannelOut ) const;
     340             :     };
     341             : 
     342             :     // INPUT nested class (allowed T: CalStats::NONE, CalStatsFitter::FIT, or
     343             :     // CalStatsHist::HIST), used to hold the vector output of stats<T>()
     344             :     class INPUT {
     345             :       public:
     346             :         casacore::Vector<casacore::uInt> oField;
     347             :         casacore::Vector<casacore::uInt> oAntenna1;
     348             :         casacore::Vector<casacore::Int> oAntenna2;
     349             :         casacore::Double dStartTime;
     350             :         casacore::Double dStopTime;
     351             :         casacore::Vector<casacore::Double> oTime;
     352             :         casacore::Vector<casacore::uInt> oSPW;
     353             :         casacore::Vector<casacore::Vector<casacore::uInt> > oChannel;
     354             :         casacore::Vector<casacore::String> oFeed;
     355             :         CalStats::AXIS eAxisIterUserID;
     356             :         RAP eRAP;
     357             :         casacore::Bool bNorm;
     358             :         casacore::Bool bUnwrap;
     359             :         casacore::Double dJumpMax;
     360             :     };
     361             : 
     362             :     // OUTPUT nested class (allowed T: CalStats::NONE, CalStatsFitter::FIT, or
     363             :     // CalStatsHist::HIST), used to hold the vector output of stats<T>()
     364             :     template <typename T>
     365             :     class OUTPUT {
     366             :       public:
     367             :         casacore::uInt uiField;
     368             :         casacore::uInt uiAntenna1;
     369             :         casacore::Int iAntenna2;
     370             :         RAP eRAP;
     371             :         casacore::Bool bNorm;
     372             :         casacore::Bool bUnwrap;
     373             :         casacore::Double dJumpMax;
     374             :         casacore::Matrix<CalStats::OUT<T> > oOut;
     375             :     };
     376             : 
     377             :     // Generic constructor
     378             :     CalAnalysis( const casacore::String& oTableName );
     379             : 
     380             :     // Destructor
     381             :     virtual ~CalAnalysis( void );
     382             : 
     383             :     // Return the calibration table name and keyword private variables
     384             :     casacore::String calName( void ) const;
     385             :     casacore::String msName( void ) const;
     386             :     casacore::String visCal( void ) const;
     387             :     casacore::String parType( void ) const;
     388             :     casacore::String polBasis( void ) const;
     389             : 
     390             :     // Get the fields, antennas, times, and feeds
     391             :     // spectral windows
     392             :     casacore::Vector<casacore::uInt> field( void ) const;
     393             :     casacore::Vector<casacore::uInt> antenna( void ) const;
     394             :     casacore::Vector<casacore::uInt> antenna1( void ) const;
     395             :     casacore::Vector<casacore::Int> antenna2( void ) const;
     396             :     casacore::Vector<casacore::Double> time( void ) const;
     397             :     casacore::Vector<casacore::String> feed( void ) const;
     398             : 
     399             :     // Get the number of spectral windows, spectral windows, number of channels
     400             :     // for each spectral window, and frequencies for each spectral window
     401             :     casacore::uInt numspw( void ) const;
     402             :     casacore::Vector<casacore::uInt> spw( void ) const;
     403             :     casacore::Vector<casacore::uInt> numChannel( void ) const;
     404             :     casacore::Vector<casacore::Vector<casacore::Double> > freq( void ) const;
     405             : 
     406             :     // Calculate statistics for the specified fields, antennas, time range,
     407             :     // feeds, spectral windows, and channels (allowed T: CalStats::NONE gets
     408             :     // data without calculating statistics, CalStatsFitter::FIT calculates fits,
     409             :     // and CalStatsHist::HIST calculates histogram statistics).
     410             :     template <typename T>
     411             :     casacore::Vector<OUTPUT<T> > stats( const INPUT& oInput,
     412             :         const CalStats::ARG<T>& oArg );
     413             : 
     414             :     // casacore::Function to determine whether a value is present in an array
     415             :     template <typename T>
     416             :     static casacore::Bool exists( const T& tValue, const casacore::Vector<T>& oValue );
     417             : 
     418             :     // casacore::Function to determine the index of a value present in an array
     419             :     template <typename T>
     420             :     static casacore::Bool where( const T& tValue, const casacore::Vector<T>& oInput,
     421             :         casacore::uInt& uiIndex );
     422             : 
     423             :     // casacore::Function to calculate sorted unique values of a vector
     424             :     template <typename T>
     425             :     static void unique( const casacore::Vector<T>& oVector, casacore::Vector<T>& unq);
     426             : 
     427             :   private:
     428             :     
     429             :     // Get the calibration table name and set the private variable
     430             :     casacore::String oCalName;
     431             :     casacore::String calNameGet( const casacore::String& oTableName );
     432             :     void calNameSet( const casacore::String& oCalNameIn );
     433             : 
     434             :     // Get the associated casacore::MS name and set the private variable
     435             :     casacore::String oMSName;
     436             :     casacore::String msNameGet( const casacore::String& oTableName );
     437             :     void msNameSet( const casacore::String& oMSNameIn );
     438             : 
     439             :     // Get the visibility calibration type and set the private variable
     440             :     casacore::String oVisCal;
     441             :     casacore::String visCalGet( const casacore::String& oTableName );
     442             :     void visCalSet( const casacore::String& oVisCalIn );
     443             : 
     444             :     // Get the parameter column type and set the private variable
     445             :     casacore::String oParType;
     446             :     casacore::String parTypeGet( const casacore::String& oTableName );
     447             :     void parTypeSet( const casacore::String& oParTypeIn );
     448             : 
     449             :     // Get the polarization basis and set the private variable
     450             :     casacore::String oPolBasis;
     451             :     casacore::String polBasisGet( const casacore::String& oTableName );
     452             :     void polBasisSet( const casacore::String& oPolBasisIn );
     453             : 
     454             :     // Get the field numbers and set the private variables
     455             :     casacore::uInt uiNumField; casacore::Vector<casacore::uInt> oField;
     456             :     casacore::Vector<casacore::uInt> fieldGet( const casacore::String& oTableName );
     457             :     void fieldSet( const casacore::Vector<casacore::uInt>& oFieldIn );
     458             :     casacore::Bool fieldCheck( const casacore::Vector<casacore::uInt>& oFieldIn,
     459             :         casacore::Vector<casacore::uInt>& oFieldOut ) const;
     460             : 
     461             :     // Get the antenna numbers and set the private variables
     462             :     casacore::uInt uiNumAntenna; casacore::Vector<casacore::uInt> oAntenna;
     463             :     casacore::Vector<casacore::uInt> antennaGet( const casacore::String& oTableName );
     464             :     void antennaSet( const casacore::Vector<casacore::uInt>& oAntennaIn );
     465             : 
     466             :     // Get the antenna 1 numbers and set the private variables
     467             :     casacore::uInt uiNumAntenna1; casacore::Vector<casacore::uInt> oAntenna1;
     468             :     casacore::Vector<casacore::uInt> antenna1Get( const casacore::String& oTableName );
     469             :     void antenna1Set( const casacore::Vector<casacore::uInt>& oAntenna1In );
     470             :     casacore::Bool antenna1Check( const casacore::Vector<casacore::uInt>& oAntenna1In,
     471             :         casacore::Vector<casacore::uInt>& oAntenna1Out ) const;
     472             : 
     473             :     // Get the antenna 2 numbers and set the private variables
     474             :     casacore::uInt uiNumAntenna2; casacore::Vector<casacore::Int> oAntenna2;
     475             :     casacore::Vector<casacore::Int> antenna2Get( const casacore::String& oTableName );
     476             :     void antenna2Set( const casacore::Vector<casacore::Int>& oAntenna2In );
     477             :     casacore::Bool antenna2Check( const casacore::Vector<casacore::Int>& oAntenna2In,
     478             :         casacore::Vector<casacore::Int>& oAntenna2Out ) const;
     479             : 
     480             :     // Get the times and set the private variables
     481             :     casacore::uInt uiNumTime; casacore::Vector<casacore::Double> oTime;
     482             :     casacore::Vector<casacore::Double> timeGet( const casacore::String& oTableName );
     483             :     void timeSet( const casacore::Vector<casacore::Double>& oTimeIn );
     484             :     casacore::Bool timeCheck( const casacore::Double& dStartTimeIn, const casacore::Double& dStopTimeIn,
     485             :         casacore::Double& dStartTimeOut, casacore::Double& dStopTimeOut,
     486             :         casacore::Vector<casacore::Double>& oTimeOut ) const;
     487             : 
     488             :     // Get the feeds and set the private variables
     489             :     casacore::uInt uiNumFeed; casacore::Vector<casacore::String> oFeed;
     490             :     casacore::Vector<casacore::String> feedGet( const casacore::String& oTableName );
     491             :     void feedSet( const casacore::Vector<casacore::String>& oFeedIn );
     492             :     casacore::Bool feedCheck( const casacore::Vector<casacore::String>& oFeedIn,
     493             :         casacore::Vector<casacore::String>& oFeedOut ) const;
     494             : 
     495             :     // Get the spectral window information and set the private variables
     496             :     SPW_INFO oSPWInfo;
     497             :     SPW_INFO& spwInfoGet( const casacore::String& oTableName );
     498             :     void spwInfoSet( const SPW_INFO& oSPWInfoIn );
     499             : 
     500             :     // Check and possibly fix the inputs to the stats<T>() member function
     501             :     casacore::Bool statsCheckInput( const CalAnalysis::INPUT& oInputIn,
     502             :         CalAnalysis::INPUT& oInputOut );
     503             : 
     504             :     // Gets the data from the new format calibration table grouped according to
     505             :     // unique combinations of (field,antenna1,antenna2)
     506             :     casacore::Bool getGroup( const NewCalTable& oNCT, const CalAnalysis::INPUT& oInput,
     507             :         casacore::Vector<casacore::uInt>& oFieldGroup, casacore::Vector<casacore::uInt>& oAntenna1Group,
     508             :         casacore::Vector<casacore::Int>& oAntenna2Group, casacore::Vector<casacore::Vector<casacore::Double> >& oTimeUniqueGroup,
     509             :         casacore::Vector<casacore::Vector<casacore::Double> >& oFreqGroup,
     510             :         casacore::Vector<casacore::Cube<casacore::DComplex> >& oCParamGroup,
     511             :         casacore::Vector<casacore::Cube<casacore::Double> >& oFParamGroup,
     512             :         casacore::Vector<casacore::Cube<casacore::Double> >& oParamErrGroup,
     513             :         casacore::Vector<casacore::Cube<casacore::Bool> >& oFlagGroup ) const;
     514             : 
     515             :     // Select the rows based on the inputs
     516             :     casacore::Bool rowSelect( const NewCalTable& oNCT, const CalAnalysis::INPUT& oInput,
     517             :         casacore::Vector<casacore::uInt>& oRowSelect ) const;
     518             : 
     519             :     // Return rows and other quantities for each group
     520             :     casacore::Bool rowGroup( const NewCalTable& oNCT, const casacore::Vector<casacore::uInt>& oRowSelect,
     521             :         casacore::Vector<casacore::Vector<casacore::uInt> >& oRowGroup, casacore::Vector<casacore::uInt>& oFieldGroup,
     522             :         casacore::Vector<casacore::uInt>& oAntenna1Group, casacore::Vector<casacore::Int>& oAntenna2Group,
     523             :         casacore::Vector<casacore::Vector<casacore::uInt> >& oSPWGroup,
     524             :         casacore::Vector<casacore::Vector<casacore::uInt> >& oSPWUniqueGroup,
     525             :         casacore::Vector<casacore::Vector<casacore::Double> >& oTimeGroup,
     526             :         casacore::Vector<casacore::Vector<casacore::Double> >& oTimeUniqueGroup ) const;
     527             : 
     528             :     // casacore::Map the spectral windows and determine the start channels (for
     529             :     // concatenating frequencies from different spectral windows)
     530             :     casacore::Bool chanSPW( const casacore::Vector<casacore::uInt>& oSPW, const INPUT& oInput,
     531             :         casacore::Vector<casacore::uInt>& oSPWMap, casacore::Vector<casacore::uInt>& oChanStart ) const;
     532             : 
     533             :     // Get the frequencies for each goup
     534             :     casacore::Bool freqGroup( const INPUT& oInput,
     535             :         const casacore::Vector<casacore::Vector<casacore::uInt> >& oSPWUniqueGroup,
     536             :         casacore::Vector<casacore::Vector<casacore::Double> >& oFreqGroup ) const;
     537             : 
     538             :     // Get the data cubes for each group
     539             :     casacore::Bool cubeGroup( const NewCalTable& oNCT, const INPUT& oInput,
     540             :         const casacore::Vector<casacore::Vector<casacore::uInt> >& oRowGroup,
     541             :         const casacore::Vector<casacore::Vector<casacore::uInt> >& oSPWGroup,
     542             :         const casacore::Vector<casacore::Vector<casacore::uInt> >& oSPWUniqueGroup,
     543             :         const casacore::Vector<casacore::Vector<casacore::Double> >& oTimeGroup,
     544             :         const casacore::Vector<casacore::Vector<casacore::Double> >& oTimeUniqueGroup,
     545             :         const casacore::Vector<casacore::Vector<casacore::Double> >& oFreqGroup,
     546             :         casacore::Vector<casacore::Cube<casacore::DComplex> >& oCParamGroup,
     547             :         casacore::Vector<casacore::Cube<casacore::Double> >& oFParamGroup,
     548             :         casacore::Vector<casacore::Cube<casacore::Double> >& oParamErrGroup,
     549             :         casacore::Vector<casacore::Cube<casacore::Bool> >& oFlagGroup ) const;
     550             : 
     551             :   protected:
     552             : 
     553             :     // Unused constructors
     554             :     CalAnalysis( void );
     555             :     CalAnalysis( const CalAnalysis& oCalAnalysis );
     556             : 
     557             :     // Unused operator=() function
     558             :     CalAnalysis& operator=( const CalAnalysis& oCalAnalysis );
     559             : 
     560             : };
     561             : 
     562             : // -----------------------------------------------------------------------------
     563             : // End of CalAnalysis class definition
     564             : // -----------------------------------------------------------------------------
     565             : 
     566             : // -----------------------------------------------------------------------------
     567             : // Start of CalAnalysis template public member functions
     568             : // -----------------------------------------------------------------------------
     569             : 
     570             : /*
     571             : 
     572             : CalAnalysis::stats<T>
     573             : 
     574             : Description:
     575             : ------------
     576             : This member function is the main user interface for calculating the statistics
     577             : for all unique groups of (field,antenna1,antenna2).  Allowed T:
     578             : CalStats::NONE() only returns the input data, CalStatsFitter::FIT() calculates
     579             : fit statistics, and CalStatsHist::HIST() calculates histogram statistics.
     580             : 
     581             : NB: The stats<T>() function calculates statistics (the type depends on T) and
     582             :     returns the results.
     583             :   - The user can specify the field(s), antenna 1s, antenna 2s, time range,
     584             :     feeds, spectral windows, channels, the second iteration axis for the 
     585             :     CalStats class (time or frequency), normalization, and unwrapping.
     586             :   - The inputs are checked and fixed, if possible.
     587             :   - The data are grouped according to unique (field,antenna1,antenna2).
     588             :   - The resulting group-based information is fed to the CalStats class and its
     589             :     stats<T>() function calculates the desired statistics which are stored in a
     590             :     vector of OUTPUT<T>() instances.  Each OUTPUT<T>() element corresponds to a
     591             :     group.
     592             : 
     593             : Inputs:
     594             : -------
     595             : oInput  - This reference to an CalAnalysis::INPUT() instance contains all of the
     596             :           input parameters.
     597             : oArg<T> - This reference to a CalStats::ARG<T>() instance contains the extra
     598             :           input parameters.
     599             : 
     600             : Outputs:
     601             : --------
     602             : The reference to the casacore::Vector<CalAnalysis::OUTPUT<T> >() instance containing the
     603             : statistics, returned via the function value.
     604             : 
     605             : Modification history:
     606             : ---------------------
     607             : 2012 Jan 20 - Nick Elias, NRAO
     608             :               Initial version.
     609             : 2012 Jan 25 - Nick Elias, NRAO
     610             :               Logging capability added.
     611             : 2012 Feb 14 - Nick Elias, NRAO
     612             :               Updated this code to reflect changes in NewCalTabIter() (now
     613             :               ROCTIter()) and other classes.  Added a RAP enum as an input
     614             :               parameter.
     615             : 2012 Apr 02 - Nick Elias, NRAO
     616             :               casacore::Input parameter dJumpMax added.
     617             : 2012 Apr 25 - Nick Elias, NRAO
     618             :               The start and stop channel lists versus spectral window are
     619             :               replaced with a channel list versus spectral window.
     620             : 2012 Apr 26 - Nick Elias, NRAO
     621             :               All input parameter instances grouped together as a INPUT()
     622             :               instance.
     623             : 2012 Apr 27 - Nick Elias, NRAO
     624             :               casacore::Input parameters are now checked and fixed by the
     625             :               statsCheckInput() member function.
     626             : 2012 May 03 - Nick Elias, NRAO
     627             :               Replaced the new format calibration table iterator with straight
     628             :               calls to the NewCalTable() class and column accessor classes.
     629             :               There is a lot of data reorganization so that they can be fed to
     630             :               CalStats<T>().
     631             : 2012 May 06 - Nick Elias, NRAO
     632             :               The data reorganization has been moved to private member function
     633             :               getGroup() and is called from here.
     634             : 
     635             : */
     636             : 
     637             : // -----------------------------------------------------------------------------
     638             : 
     639             : template <typename T>
     640             : casacore::Vector<CalAnalysis::OUTPUT<T> > CalAnalysis::stats(
     641             :     const CalAnalysis::INPUT& oInput, const CalStats::ARG<T>& oArg ) {
     642             : 
     643             :   // Initialize the output vector containing statistics for each field ID,
     644             :   // antenna 1, and antenna 2
     645             : 
     646             :   casacore::Vector<CalAnalysis::OUTPUT<T> > output;
     647             : 
     648             : 
     649             :   // Check and fix the inputs
     650             : 
     651             :   INPUT oInputNew;
     652             : 
     653             :   casacore::Bool bCheck = statsCheckInput( oInput, oInputNew );
     654             : 
     655             :   if ( !bCheck ) {
     656             :     casacore::LogIO log( casacore::LogOrigin( "CalAnalysis", "stats<T>()", WHERE ) );
     657             :     log << casacore::LogIO::WARN << "Invalid parameter(s)" << casacore::LogIO::POST;
     658             :     return output;
     659             :   }
     660             : 
     661             : 
     662             :   // Create an instance of the new format calibration table class
     663             :   // Use createCT to enforce backward compatibility
     664             :   NewCalTable oNCT =  NewCalTable::createCT( oCalName, casacore::Table::Old, casacore::Table::Memory );
     665             : 
     666             : 
     667             :   // Get the cubes for each group
     668             : 
     669             :   casacore::Vector<casacore::uInt> oFieldGroup;
     670             :   casacore::Vector<casacore::uInt> oAntenna1Group;
     671             :   casacore::Vector<casacore::Int> oAntenna2Group;
     672             : 
     673             :   casacore::Vector<casacore::Vector<casacore::Double> > oTimeUniqueGroup;
     674             :   casacore::Vector<casacore::Vector<casacore::Double> > oFreqGroup;
     675             : 
     676             :   casacore::Vector<casacore::Cube<casacore::DComplex> > oCParamGroup;
     677             :   casacore::Vector<casacore::Cube<casacore::Double> > oFParamGroup;
     678             :   casacore::Vector<casacore::Cube<casacore::Double> > oParamErrGroup;
     679             :   casacore::Vector<casacore::Cube<casacore::Bool> > oFlagGroup;
     680             : 
     681             :   casacore::Bool bGetGroup = getGroup( oNCT, oInputNew, oFieldGroup, oAntenna1Group,
     682             :       oAntenna2Group, oTimeUniqueGroup, oFreqGroup, oCParamGroup, oFParamGroup,
     683             :       oParamErrGroup, oFlagGroup );
     684             : 
     685             :   if ( !bGetGroup ) {
     686             :     casacore::LogIO log( casacore::LogOrigin( "CalAnalysis", "stats<T>()", WHERE ) );
     687             :     log << casacore::LogIO::WARN << "Cannot parse group(s)" << casacore::LogIO::POST;
     688             :     return output;
     689             :   }
     690             : 
     691             : 
     692             :   // Resize the output vector (each group corresponds to an element of
     693             :   // casacore::Vector<OUTPUT<T> >())
     694             : 
     695             :   casacore::uInt uiNumGroup = oFieldGroup.nelements();
     696             : 
     697             :   output.resize( uiNumGroup, false );
     698             : 
     699             : 
     700             :   // Send each group to CalStats<T>() and perform the desired operation
     701             : 
     702             :   for ( casacore::uInt g=0; g<uiNumGroup; g++ ) {
     703             : 
     704             :     output[g].uiField = oFieldGroup[g];
     705             :     output[g].uiAntenna1 = oAntenna1Group[g];
     706             :     output[g].iAntenna2 = oAntenna2Group[g];
     707             :     output[g].eRAP = oInputNew.eRAP;
     708             :     output[g].bNorm = oInputNew.bNorm;
     709             :     output[g].bUnwrap = oInputNew.bUnwrap;
     710             :     output[g].dJumpMax = oInputNew.dJumpMax;
     711             : 
     712             :     CalStats* poCS = NULL;
     713             : 
     714             :     try {
     715             : 
     716             :       switch ((casacore::uInt) oInputNew.eRAP) {
     717             :         case (casacore::uInt) REAL:
     718             :           poCS = (CalStats*) new CalStatsReal( oFParamGroup[g],
     719             :               oParamErrGroup[g], oFlagGroup[g], oInputNew.oFeed, oFreqGroup[g],
     720             :               oTimeUniqueGroup[g], oInputNew.eAxisIterUserID );
     721             :           break;
     722             :         case (casacore::uInt) AMPLITUDE:
     723             :           poCS = (CalStats*) new CalStatsAmp( oCParamGroup[g],
     724             :               oParamErrGroup[g], oFlagGroup[g], oInputNew.oFeed, oFreqGroup[g],
     725             :               oTimeUniqueGroup[g], oInputNew.eAxisIterUserID, oInputNew.bNorm );
     726             :           break;
     727             :         case (casacore::uInt) PHASE:
     728             :           poCS = (CalStats*) new CalStatsPhase( oCParamGroup[g],
     729             :               oParamErrGroup[g], oFlagGroup[g], oInputNew.oFeed, oFreqGroup[g],
     730             :               oTimeUniqueGroup[g], oInputNew.eAxisIterUserID, oInputNew.bUnwrap,
     731             :               oInputNew.dJumpMax );
     732             :           break;
     733             :         default:
     734             :           throw( casacore::AipsError( "Invalid parameter (REAL, AMPLITUDE, or PHASE)" ) );
     735             :       }
     736             : 
     737             :       output[g].oOut = poCS->stats<T>( oArg );
     738             : 
     739             :       delete poCS;
     740             : 
     741             :     }
     742             : 
     743             :     catch ( casacore::AipsError oAE ) {
     744             :       casacore::LogIO log( casacore::LogOrigin( "CalAnalysis", "stats<T>()", WHERE ) );
     745             :       log << casacore::LogIO::WARN << oAE.getMesg()
     746             :           << ", iteration (field,antenna1,antenna2) = (" << oFieldGroup[g]
     747             :           << "," << oAntenna1Group[g] << "," << oAntenna2Group[g]
     748             :           << "), continuing ..." << casacore::LogIO::POST;
     749             :       output[g].oOut = CalStats::OUT<T>();
     750             :     }
     751             : 
     752             :   }
     753             : 
     754             : 
     755             :   // Return the reference to the casacore::Vector<CalAnalysis::OUTPUT<T> > instance
     756             : 
     757             :   return output;
     758             : 
     759             : }
     760             : 
     761             : // -----------------------------------------------------------------------------
     762             : // End of CalAnalysis template public member functions
     763             : // -----------------------------------------------------------------------------
     764             : 
     765             : // -----------------------------------------------------------------------------
     766             : // Start of CalAnalysis template static public member functions
     767             : // -----------------------------------------------------------------------------
     768             : 
     769             : /*
     770             : 
     771             : CalAnalysis::exists<T>
     772             : 
     773             : Description:
     774             : ------------
     775             : This member function determines whether a value appears in a vector.
     776             : 
     777             : Inputs:
     778             : -------
     779             : tValue - This reference to a T variable contains the desired value.
     780             : oValue - This reference to a casacore::Vector<T> instance contains the values.
     781             : 
     782             : Outputs:
     783             : --------
     784             : The reference to the existance casacore::Bool variable, returned via the function value.
     785             : 
     786             : Modification history:
     787             : ---------------------
     788             : 2012 Jan 20 - Nick Elias, NRAO
     789             :               Initial version.
     790             : 
     791             : */
     792             : 
     793             : // -----------------------------------------------------------------------------
     794             : 
     795             : template <typename T>
     796           0 : casacore::Bool CalAnalysis::exists( const T& tValue, const casacore::Vector<T>& oValue ) {
     797             : 
     798             :   // Determine whether the value is present in an array and return the boolean
     799             : 
     800           0 :   casacore::Bool value = false;
     801             : 
     802           0 :   for ( casacore::uInt v=0; v<oValue.nelements(); v++ ) {
     803           0 :     if ( tValue == oValue[v] ) value = true;
     804             :   }
     805             : 
     806           0 :   return value;
     807             : 
     808             : }
     809             : 
     810             : // -----------------------------------------------------------------------------
     811             : 
     812             : /*
     813             : 
     814             : CalAnalysis::where<T>
     815             : 
     816             : Description:
     817             : ------------
     818             : This member function returns the index of a search value in a vector.
     819             : 
     820             : Inputs:
     821             : -------
     822             : tValue - The T instance containing the value for which to search.
     823             : oInput - The casacore::Vector<T> instance containing the values to be searched.
     824             : 
     825             : Outputs:
     826             : --------
     827             : uiIndex - The casacore::uInt instance containing the index of the search T instance in the
     828             :           searched casacore::Vector<T> instance.
     829             : The reference to the casacore::Bool containing the success boolean, returned via the
     830             : function value.
     831             : 
     832             : Modification history:
     833             : ---------------------
     834             : 2012 May 06 - Nick Elias, NRAO
     835             :               Initial version.
     836             : 
     837             : */
     838             : 
     839             : // -----------------------------------------------------------------------------
     840             : 
     841             : template <typename T>
     842           0 : casacore::Bool CalAnalysis::where( const T& tValue, const casacore::Vector<T>& oInput,
     843             :     casacore::uInt& uiIndex ) {
     844             : 
     845             :   // Find the index in the input vector
     846             : 
     847           0 :   for ( casacore::uInt i=0; i<oInput.nelements(); i++ ) {
     848           0 :     if ( oInput[i] == tValue ) {
     849           0 :       uiIndex = i;
     850           0 :       break;
     851             :     }
     852             :   }
     853             : 
     854             : 
     855             :   // If the value was found return true, otherwise return false
     856             : 
     857           0 :   casacore::Bool success = false;
     858             : 
     859           0 :   if ( uiIndex < oInput.nelements() ) {
     860           0 :     success = true;
     861             :   } else {
     862           0 :     success = false;
     863             :   }
     864             : 
     865           0 :   return success;
     866             : 
     867             : }
     868             : 
     869             : // -----------------------------------------------------------------------------
     870             : 
     871             : /*
     872             : 
     873             : CalAnalysis::unique<T>
     874             : 
     875             : Description:
     876             : ------------
     877             : This member function produces a unique sorted vector from an input vector.
     878             : 
     879             : Inputs:
     880             : -------
     881             : oVector - This reference to a casacore::Vector<T> instance contains the values.
     882             : 
     883             : Outputs:
     884             : --------
     885             : unq - The unique sorted casacore::Vector<T> instance
     886             : 
     887             : Modification history:
     888             : ---------------------
     889             : 2012 Jan 20 - Nick Elias, NRAO
     890             :               Initial version.
     891             : 
     892             : */
     893             : 
     894             : // -----------------------------------------------------------------------------
     895             : 
     896             : template <typename T>
     897           0 : void CalAnalysis::unique( const casacore::Vector<T>& oVector, casacore::Vector<T>& unq ) {
     898             : 
     899             :   // Form the unique vector
     900             : 
     901           0 :   for ( casacore::uInt v1=0; v1<oVector.nelements(); v1++ ) {
     902             : 
     903           0 :     casacore::Bool bDupe = false;
     904             : 
     905           0 :     for ( casacore::uInt v2=0; v2<v1; v2++ ) {
     906           0 :       if ( oVector[v1] == oVector[v2] ) {
     907           0 :         bDupe = true;
     908           0 :         break;
     909             :       }
     910             :     }
     911             : 
     912           0 :     if ( !bDupe ) {
     913           0 :       unq.resize( unq.nelements()+1, true );
     914           0 :       unq.operator[](unq.nelements()-1) = oVector[v1];
     915             :     }
     916             : 
     917             :   }
     918             : 
     919             : 
     920             :   // casacore::Sort the unique vector
     921             : 
     922           0 :   casacore::Sort::Order eOrder = casacore::Sort::Ascending;
     923           0 :   casacore::Int iOptions = casacore::Sort::QuickSort;
     924             : 
     925           0 :   casacore::GenSort<T>::sort( unq, eOrder, (int) iOptions );
     926           0 : }
     927             : 
     928             : // -----------------------------------------------------------------------------
     929             : // End of CalAnalysis template static public member functions
     930             : // -----------------------------------------------------------------------------
     931             : 
     932             : };
     933             : 
     934             : // -----------------------------------------------------------------------------
     935             : // End of casa namespace
     936             : // -----------------------------------------------------------------------------
     937             : 
     938             : #endif
     939             : 
     940             : // -----------------------------------------------------------------------------
     941             : // End of define macro to prevent multiple loading
     942             : // -----------------------------------------------------------------------------

Generated by: LCOV version 1.16