CalAnalysis.h

Go to the documentation of this file.
00001 
00002 // -----------------------------------------------------------------------------
00003 
00004 /*
00005 
00006 CalAnalysis.h
00007 
00008 Description:
00009 ------------
00010 This header file contains definitions for the CalStats class.
00011 
00012 Classes:
00013 --------
00014 CalAnalysis - This class acts as the interface between the ROCTIter and CalStats
00015               classes.
00016 
00017 Modification history:
00018 ---------------------
00019 2012 Jan 20 - Nick Elias, NRAO
00020               Initial version.
00021 2012 Jan 25 - Nick Elias, NRAO
00022               Logging capability added.  Error checking added.
00023 2012 Feb 14 - Nick Elias, NRAO
00024               Updated this code to reflect changes in NewCalTabIter (now
00025               ROCTIter) and other classes.
00026 
00027 */
00028 
00029 // -----------------------------------------------------------------------------
00030 // Start of define macro to prevent multiple loading
00031 // -----------------------------------------------------------------------------
00032 
00033 #ifndef CAL_ANALYSIS_H
00034 #define CAL_ANALYSIS_H
00035 
00036 // -----------------------------------------------------------------------------
00037 // Includes
00038 // -----------------------------------------------------------------------------
00039 
00040 #include <casa/BasicSL/String.h>
00041 
00042 #include <iostream>
00043 #include <sstream>
00044 using namespace std;
00045 
00046 #include <casa/Exceptions/Error.h>
00047 #include <casa/Logging/LogIO.h>
00048 
00049 #include <casa/Containers/Block.h>
00050 
00051 #include <casa/Arrays/Array.h>
00052 #include <casa/Arrays/ArrayIter.h>
00053 #include <casa/Arrays/Cube.h>
00054 #include <casa/Arrays/Slicer.h>
00055 #include <casa/Arrays/ArrayMath.h>
00056 
00057 #include <tables/Tables/Table.h>
00058 #include <tables/Tables/TableProxy.h>
00059 
00060 #include <casa/Containers/Record.h>
00061 #include <casa/Containers/RecordField.h>
00062 
00063 #include <casa/Utilities/GenSort.h>
00064 
00065 #include <ms/MeasurementSets/MSSpectralWindow.h>
00066 #include <ms/MeasurementSets/MSSpWindowColumns.h>
00067 
00068 #include <synthesis/CalTables/NewCalTable.h>
00069 #include <synthesis/CalTables/CTIter.h>
00070 
00071 #include <calanalysis/CalAnalysis/CalStats.h>
00072 #include <calanalysis/CalAnalysis/CalStatsDerived.h>
00073 #include <calanalysis/CalAnalysis/CalStatsFitter.h>
00074 
00075 // -----------------------------------------------------------------------------
00076 // Start of casa namespace
00077 // -----------------------------------------------------------------------------
00078 
00079 namespace casa {
00080 
00081 // -----------------------------------------------------------------------------
00082 // Start of CalAnalysis class definition
00083 // -----------------------------------------------------------------------------
00084 
00085 /*
00086 
00087 CalAnalysis
00088 
00089 Description:
00090 ------------
00091 This class acts as the interface between the ROCTIter and CalAnalysis classes.
00092 
00093 In a nutshell:
00094 --------------
00095 * The constructor gets the information from the new format calibration table
00096   and initializes the class.
00097 * The stats<T>() function calculates statistics (the type depends on T) and
00098   returns the results.
00099   - The user can specify the field(s), antenna 1s, antenna 2s, time range,
00100     feeds, spectral windows, channels, the second iteration axis for the 
00101     CalStats class (time or frequency), normalization, and unwrapping.
00102   - The inputs are checked and fixed, if possible.
00103   - The data are grouped according to unique (field,antenna1,antenna2).
00104   - The resulting group-based information is fed to the CalStats class and its
00105     stats<T>() function calculates the desired statistics which are stored in a
00106     vector of OUTPUT<T>() instances.  Each OUTPUT<T>() element corresponds to a
00107     group.
00108 
00109 NB: There are a lot of get/set member functions.  Unfortunately, they could not
00110     be overloaded with the same names because of conflicts with corresponding
00111     member functions without get/set in their names.  Plus, some get functions
00112     need to call other get functions.
00113 
00114 NB: When an instance of this class is created from the python binding, input
00115     parameters are mostly checked there.  There is checking in this class as
00116     well, just in case that the class is not called from the python binding.
00117     There does not appear to be a significant speed penalty.
00118 
00119 Nested classes:
00120 ---------------
00121 OUTPUT<T> - This nested class contains the outputs for the
00122             CalAnalysis::stats<T>() template member function.
00123 
00124 Class public member functions:
00125 ------------------------------
00126 CalAnalysis  - This constructor gets information from the new format calibration
00127                table for further processing by the stats<T>() function.
00128 ~CalAnalysis - This destructor deallocates the internal memory of an instance.
00129 calName      - This member function returns the new format calibration table
00130                name.
00131 msName       - This member function returns the associated MS name.
00132 visCal       - This member function returns the visibility calibration type.
00133 parType      - This member function returns the parameter type ("Complex" or
00134                "Float").
00135 polBasis     - This member function returns the polarization basis ("L" or "C").
00136 field        - This member function returns the field numbers.
00137 antenna      - This member function returns the antenna numbers.
00138 antenna1     - This member function returns the antenna 1 numbers.
00139 antenna2     - This member function returns the antenna 2 numbers.
00140 time         - This member function returns the times.
00141 feed         - This member function returns the feeds.
00142 numspw       - This member function returns the number of spectral windows.
00143 spw          - This member function returns the spectral windows.
00144 numChannel   - This member function returns the number of channels for each
00145                spectral window.
00146 freq         - This member function returns the frequencies for each spectral
00147                window.
00148 
00149 Class template public member functions:
00150 ---------------------------------------
00151 stats<T> - This member function is the main user interface for calculating the
00152            statistics for all iterations.  Allowed T: CalStats::NONE only
00153            returns the input data, CalStatsFitter::FIT calculates fit
00154            statistics, and CalStatsHist::HIST calculates histogram statistics.
00155 
00156 Class template static public member functions:
00157 ----------------------------------------------
00158 exists<T> - This member function determines whether a value appears in a vector.
00159 where<T>  - This member function returns the index of a search value in a
00160             vector.
00161 unique<T> - This member function returns a unique vector from an input vector.
00162 
00163 Class private member functions:
00164 -------------------------------
00165 calNameGet      - This member function gets the new format calibration table
00166                   name from the new format calibration table.
00167 calNameSet      - This member function sets the new format calibration table
00168                   name private variable.
00169 msNameGet       - This member function gets the associated MS name from the new
00170                   format calibration table.
00171 msNameSet       - This member function sets the associated MS name private
00172                   variable.
00173 visCalGet       - This member function gets the visibility calibration type from
00174                   the new format calibration table.
00175 visCalSet       - This member function sets the visibility calibration type
00176                   private variable.
00177 parTypeGet      - This member function gets the parameter type ("Complex" or
00178                   "Float") from the new format calibration table.
00179 parTypeSet      - This member function sets the parameter type ("Complex" or
00180                   "Float") private variable.
00181 polBasisGet     - This member function gets the polarization basis ("L" or "C")
00182                   from the new format calibration table.
00183 polBasisSet     - This member function sets the polarization basis ("L" or "C")
00184                   private variable.
00185 fieldGet        - This member function gets the field numbers from the new
00186                   format calibration table.
00187 fieldSet        - This member function sets the field numbers private variables.
00188 fieldCheck      - This member function checks the input field vector and returns
00189                   the fixed field vector.
00190 antennaGet      - This member function gets the antenna numbers from the new
00191                   format calibration table.
00192 antennaSet      - This member function sets the antenna numbers private
00193                   variables.
00194 antenna1Get     - This member function gets the antenna 1 numbers from the new
00195                   format calibration table.
00196 antenna1Set     - This member function sets the antenna 1 numbers private
00197                   variables.
00198 antenna1Check   - This member function checks the input antenna 1 vector and
00199                   returns the fixed antenna 1 vector.
00200 antenna2Get     - This member function gets the antenna 2 numbers from the new
00201                   format calibration table.
00202 antenna2Set     - This member function sets the antenna 2 numbers private
00203                   variables.
00204 antenna2Check   - This member function checks the input antenna 2 vector and
00205                   returns the fixed antenna 2 vector.
00206 timeGet         - This member function gets the times from the new format
00207                   calibration table.
00208 timeSet         - This member function sets the times private variables.
00209 timeCheck       - This member function checks the time range and returns the
00210                   corresponding time vector.
00211 feedGet         - This member function gets the feeds from the new format
00212                   calibration table.
00213 feedSet         - This member function sets the feeds private variables.
00214 feedCheck       - This member function checks the input feed vector and returns
00215                   the fixed feed vector.
00216 spwInfoGet      - This member function gets the spectral window information from
00217                   the new format calibration table.
00218 spwInfoSet      - This member function sets the spectral window information
00219                   private variables.
00220 statsCheckInput - This member function checks and fixes (if possible) the inputs
00221                   to the CalAnalysis::stats<T>() member function.
00222 getGroup        - This member function gets input selected rows from a new
00223                   format calibration table and groups them according to unique
00224                   (field,antenna1,antenna2).
00225 rowSelect       - This member function returns the rows selected by the input
00226                   parameters.
00227 rowGroup        - This member function returns the row numbers, fields, antenna
00228                   1s, antenna 2s, spectral windows, unique spectral windows,
00229                   times, and unique times grouped according to selected rows and
00230                   input selection.
00231 chanSPW         - This member function maps the spectral windows to the input
00232                   spectral windows (to get the correct channels) and forms the
00233                   start channels so that spectral windows can be concatenated.
00234 freqGroup       - This member function concatenates the frequencies from
00235                   multiple spectral windows for each group.
00236 cubeGroup       - This member function concatenates data from multiple rows into
00237                   groups according to unique (field,antenna1,antenna2).
00238 
00239 Class protected member functions:
00240 ---------------------------------
00241 CalAnalysis - This default constructor is unused by this class and unavailable
00242               when an instance is created.
00243 CalAnalysis - This copy constructor is unused by this class and unavailable when
00244               an instance is created.
00245 operator=   - This operator= function is unused by this class and unavailable
00246               when an instance is created.
00247 
00248 Modification history:
00249 ---------------------
00250 2012 Jan 20 - Nick Elias, NRAO
00251               Initial version created with public member functions CalAnalysis()
00252               (generic), ~CalAnalysis(); template static public member function
00253               stats<T>(); template public member functions exists<T>() and
00254               unique<T>(); private member functions tableType(), polBasisGet(),
00255               feedCheck(), timeCheck(), spw_channel(), freq(); template private
00256               member functions parse<T>(), and select<T>(); and protected member
00257               functions CalAnalysis() (default), CalAnalysis() (copy), and
00258               operator=().
00259 2012 Feb 14 - Nick Elias, NRAO
00260               Updated this code to reflect changes in NewCalTabIter (now
00261               ROCTIter) and other classes.  Added the RAP enum.
00262 2012 Mar 13 - Nick Elias, NRAO
00263               Public member function tableType() renamed to parTypeGet().
00264               Private member functions msNameGet() and visCalGet() added.
00265 2012 Mar 14 - Nick Elias, NRAO
00266               Spectral window ID, start channel, and stop channel added to the
00267               nested OUTPUT<T> class.
00268 2012 Apr 03 - Nick Elias, NRAO
00269               Private member function calNameGet() added.  Public member
00270               functions calName(), msName(), visCal(), parType(), and polBasis()
00271               added.
00272 2012 Apr 04 - Nick Elias, NRAO
00273               Private member functions calNameSet(), msNameSet(), visCalSet(),
00274               parTypeSet(), polBasisSet(), feedGet(), feedSet(), timeGet(),
00275               timeSet(), spwGet(), and spwSet() added.  Public member functions
00276               feed(), time(), spw(), and numspw() added.
00277 2012 Apr 17 - Nick Elias, NRAO
00278               Nested class CalAnalysis::SPW_INFO() added.  Private member
00279               functions fieldGet(), fieldSet(), fieldCheck(), antennaGet(),
00280               antennaSet(), antennaCheck(), spwInfoGet(), and spwInfoSet()
00281               added.  Public member functions field(), antenna(), numChannel(),
00282               and freq() added.  Private member functions spwGet(), spwSet(),
00283               and spw_channel() removed.
00284 2012 Apr 25 - Nick Elias, NRAO
00285               Private member function antennaCheck() renamed to antenna1Check().
00286               private member function antenna2Check() added.  The start and stop
00287               channel lists versus spectral window are replaced with a channel
00288               list versus spectral window.
00289 2012 Apr 26 - Nick Elias, NRAO
00290               Nested class INPUT added (for the stats<T>() member function).
00291               Spectral window ID, start channel, and stop channel removed from
00292               the nested OUTPUT<T> class.
00293 2012 Apr 27 - Nick Elias, NRAO
00294               Private member function statsCheckInput() added.  The member
00295               functions of the nested class CalAnalysis::SPW_INFO() have been
00296               moved to a separate file CalAnalysisSPW_INFO.cc.
00297 2012 May 02 - Nick Elias, NRAO
00298               Private member functions antenna1Get(), antenna1Set(),
00299               antenna2Get(), and antenna2Set() added.
00300 2012 May 06 - Nick Elias, NRAO
00301               Template private member functions parse<T>() and select<T>()
00302               removed.  Template static public member function where<T>() added.
00303               Private member functions getGroup(), rowSelect(), rowGroup(),
00304               chanSPW(), freqGroup(), and cubeGroup() added.
00305 2012 May 07 - Nick Elias, NRAO
00306               Public member functions antenna1() and antenna2() added.
00307 
00308 */
00309 
00310 // -----------------------------------------------------------------------------
00311 
00312 class CalAnalysis {
00313 
00314   public:
00315 
00316     // Real/Amplitude/Phase enums
00317     typedef enum RAP {
00318       INIT=-1, REAL=0, AMPLITUDE, PHASE
00319     } RAP;
00320 
00321     // SPW_INFO nested class
00322     class SPW_INFO {
00323       public:
00324         Bool bValid;
00325         uInt uiNumSPW;
00326         Vector<uInt> oSPW;
00327         Vector<uInt> oNumChannel;
00328         Vector<Vector<Double> > oFrequency;
00329         SPW_INFO( const String& oTableName );
00330         SPW_INFO( const SPW_INFO& oSPWInfoIn );
00331         SPW_INFO( void );
00332         ~SPW_INFO( void );
00333         SPW_INFO& operator=( const SPW_INFO& oSPWInfoIn );
00334         Bool& freq( const Vector<uInt>& oSPWIn,
00335             const Vector<Vector<uInt> >& oChannelIn,
00336             Vector<Double>& oFreqOut ) const;
00337         Bool& spwInfoCheck( const Vector<uInt>& oSPWIn,
00338             const Vector<Vector<uInt> >& oChannelIn, Vector<uInt>& oSPWOut,
00339             Vector<Vector<uInt> >& oChannelOut ) const;
00340     };
00341 
00342     // INPUT nested class (allowed T: CalStats::NONE, CalStatsFitter::FIT, or
00343     // CalStatsHist::HIST), used to hold the vector output of stats<T>()
00344     class INPUT {
00345       public:
00346         Vector<uInt> oField;
00347         Vector<uInt> oAntenna1;
00348         Vector<Int> oAntenna2;
00349         Double dStartTime;
00350         Double dStopTime;
00351         Vector<Double> oTime;
00352         Vector<uInt> oSPW;
00353         Vector<Vector<uInt> > oChannel;
00354         Vector<String> oFeed;
00355         CalStats::AXIS eAxisIterUserID;
00356         RAP eRAP;
00357         Bool bNorm;
00358         Bool bUnwrap;
00359         Double dJumpMax;
00360     };
00361 
00362     // OUTPUT nested class (allowed T: CalStats::NONE, CalStatsFitter::FIT, or
00363     // CalStatsHist::HIST), used to hold the vector output of stats<T>()
00364     template <typename T>
00365     class OUTPUT {
00366       public:
00367         uInt uiField;
00368         uInt uiAntenna1;
00369         Int iAntenna2;
00370         RAP eRAP;
00371         Bool bNorm;
00372         Bool bUnwrap;
00373         Double dJumpMax;
00374         Matrix<CalStats::OUT<T> > oOut;
00375     };
00376 
00377     // Generic constructor
00378     CalAnalysis( const String& oTableName );
00379 
00380     // Destructor
00381     virtual ~CalAnalysis( void );
00382 
00383     // Return the calibration table name and keyword private variables
00384     String& calName( void ) const;
00385     String& msName( void ) const;
00386     String& visCal( void ) const;
00387     String& parType( void ) const;
00388     String& polBasis( void ) const;
00389 
00390     // Get the fields, antennas, times, and feeds
00391     // spectral windows
00392     Vector<uInt>& field( void ) const;
00393     Vector<uInt>& antenna( void ) const;
00394     Vector<uInt>& antenna1( void ) const;
00395     Vector<Int>& antenna2( void ) const;
00396     Vector<Double>& time( void ) const;
00397     Vector<String>& feed( void ) const;
00398 
00399     // Get the number of spectral windows, spectral windows, number of channels
00400     // for each spectral window, and frequencies for each spectral window
00401     uInt& numspw( void ) const;
00402     Vector<uInt>& spw( void ) const;
00403     Vector<uInt>& numChannel( void ) const;
00404     Vector<Vector<Double> >& freq( void ) const;
00405 
00406     // Calculate statistics for the specified fields, antennas, time range,
00407     // feeds, spectral windows, and channels (allowed T: CalStats::NONE gets
00408     // data without calculating statistics, CalStatsFitter::FIT calculates fits,
00409     // and CalStatsHist::HIST calculates histogram statistics).
00410     template <typename T>
00411     Vector<OUTPUT<T> >& stats( const INPUT& oInput,
00412         const CalStats::ARG<T>& oArg );
00413 
00414     // Function to determine whether a value is present in an array
00415     template <typename T>
00416     static Bool& exists( const T& tValue, const Vector<T>& oValue );
00417 
00418     // Function to determine the index of a value present in an array
00419     template <typename T>
00420     static Bool& where( const T& tValue, const Vector<T>& oInput,
00421         uInt& uiIndex );
00422 
00423     // Function to return sorted unique values of a vector
00424     template <typename T>
00425     static Vector<T>& unique( const Vector<T>& oVector );
00426 
00427   private:
00428     
00429     // Get the calibration table name and set the private variable
00430     String oCalName;
00431     String& calNameGet( const String& oTableName );
00432     void calNameSet( const String& oCalNameIn );
00433 
00434     // Get the associated MS name and set the private variable
00435     String oMSName;
00436     String& msNameGet( const String& oTableName );
00437     void msNameSet( const String& oMSNameIn );
00438 
00439     // Get the visibility calibration type and set the private variable
00440     String oVisCal;
00441     String& visCalGet( const String& oTableName );
00442     void visCalSet( const String& oVisCalIn );
00443 
00444     // Get the parameter column type and set the private variable
00445     String oParType;
00446     String& parTypeGet( const String& oTableName );
00447     void parTypeSet( const String& oParTypeIn );
00448 
00449     // Get the polarization basis and set the private variable
00450     String oPolBasis;
00451     String& polBasisGet( const String& oTableName );
00452     void polBasisSet( const String& oPolBasisIn );
00453 
00454     // Get the field numbers and set the private variables
00455     uInt uiNumField; Vector<uInt> oField;
00456     Vector<uInt>& fieldGet( const String& oTableName );
00457     void fieldSet( const Vector<uInt>& oFieldIn );
00458     Bool& fieldCheck( const Vector<uInt>& oFieldIn,
00459         Vector<uInt>& oFieldOut ) const;
00460 
00461     // Get the antenna numbers and set the private variables
00462     uInt uiNumAntenna; Vector<uInt> oAntenna;
00463     Vector<uInt>& antennaGet( const String& oTableName );
00464     void antennaSet( const Vector<uInt>& oAntennaIn );
00465 
00466     // Get the antenna 1 numbers and set the private variables
00467     uInt uiNumAntenna1; Vector<uInt> oAntenna1;
00468     Vector<uInt>& antenna1Get( const String& oTableName );
00469     void antenna1Set( const Vector<uInt>& oAntenna1In );
00470     Bool& antenna1Check( const Vector<uInt>& oAntenna1In,
00471         Vector<uInt>& oAntenna1Out ) const;
00472 
00473     // Get the antenna 2 numbers and set the private variables
00474     uInt uiNumAntenna2; Vector<Int> oAntenna2;
00475     Vector<Int>& antenna2Get( const String& oTableName );
00476     void antenna2Set( const Vector<Int>& oAntenna2In );
00477     Bool& antenna2Check( const Vector<Int>& oAntenna2In,
00478         Vector<Int>& oAntenna2Out ) const;
00479 
00480     // Get the times and set the private variables
00481     uInt uiNumTime; Vector<Double> oTime;
00482     Vector<Double>& timeGet( const String& oTableName );
00483     void timeSet( const Vector<Double>& oTimeIn );
00484     Bool& timeCheck( const Double& dStartTimeIn, const Double& dStopTimeIn,
00485         Double& dStartTimeOut, Double& dStopTimeOut,
00486         Vector<Double>& oTimeOut ) const;
00487 
00488     // Get the feeds and set the private variables
00489     uInt uiNumFeed; Vector<String> oFeed;
00490     Vector<String>& feedGet( const String& oTableName );
00491     void feedSet( const Vector<String>& oFeedIn );
00492     Bool& feedCheck( const Vector<String>& oFeedIn,
00493         Vector<String>& oFeedOut ) const;
00494 
00495     // Get the spectral window information and set the private variables
00496     SPW_INFO oSPWInfo;
00497     SPW_INFO& spwInfoGet( const String& oTableName );
00498     void spwInfoSet( const SPW_INFO& oSPWInfoIn );
00499 
00500     // Check and possibly fix the inputs to the stats<T>() member function
00501     Bool& statsCheckInput( const CalAnalysis::INPUT& oInputIn,
00502         CalAnalysis::INPUT& oInputOut );
00503 
00504     // Gets the data from the new format calibration table grouped according to
00505     // unique combinations of (field,antenna1,antenna2)
00506     Bool& getGroup( const NewCalTable& oNCT, const CalAnalysis::INPUT& oInput,
00507         Vector<uInt>& oFieldGroup, Vector<uInt>& oAntenna1Group,
00508         Vector<Int>& oAntenna2Group, Vector<Vector<Double> >& oTimeUniqueGroup,
00509         Vector<Vector<Double> >& oFreqGroup,
00510         Vector<Cube<DComplex> >& oCParamGroup,
00511         Vector<Cube<Double> >& oFParamGroup,
00512         Vector<Cube<Double> >& oParamErrGroup,
00513         Vector<Cube<Bool> >& oFlagGroup ) const;
00514 
00515     // Select the rows based on the inputs
00516     Bool& rowSelect( const NewCalTable& oNCT, const CalAnalysis::INPUT& oInput,
00517         Vector<uInt>& oRowSelect ) const;
00518 
00519     // Return rows and other quantities for each group
00520     Bool& rowGroup( const NewCalTable& oNCT, const Vector<uInt>& oRowSelect,
00521         Vector<Vector<uInt> >& oRowGroup, Vector<uInt>& oFieldGroup,
00522         Vector<uInt>& oAntenna1Group, Vector<Int>& oAntenna2Group,
00523         Vector<Vector<uInt> >& oSPWGroup,
00524         Vector<Vector<uInt> >& oSPWUniqueGroup,
00525         Vector<Vector<Double> >& oTimeGroup,
00526         Vector<Vector<Double> >& oTimeUniqueGroup ) const;
00527 
00528     // Map the spectral windows and determine the start channels (for
00529     // concatenating frequencies from different spectral windows)
00530     Bool& chanSPW( const Vector<uInt>& oSPW, const INPUT& oInput,
00531         Vector<uInt>& oSPWMap, Vector<uInt>& oChanStart ) const;
00532 
00533     // Get the frequencies for each goup
00534     Bool& freqGroup( const INPUT& oInput,
00535         const Vector<Vector<uInt> >& oSPWUniqueGroup,
00536         Vector<Vector<Double> >& oFreqGroup ) const;
00537 
00538     // Get the data cubes for each group
00539     Bool& cubeGroup( const NewCalTable& oNCT, const INPUT& oInput,
00540         const Vector<Vector<uInt> >& oRowGroup,
00541         const Vector<Vector<uInt> >& oSPWGroup,
00542         const Vector<Vector<uInt> >& oSPWUniqueGroup,
00543         const Vector<Vector<Double> >& oTimeGroup,
00544         const Vector<Vector<Double> >& oTimeUniqueGroup,
00545         const Vector<Vector<Double> >& oFreqGroup,
00546         Vector<Cube<DComplex> >& oCParamGroup,
00547         Vector<Cube<Double> >& oFParamGroup,
00548         Vector<Cube<Double> >& oParamErrGroup,
00549         Vector<Cube<Bool> >& oFlagGroup ) const;
00550 
00551   protected:
00552 
00553     // Unused constructors
00554     CalAnalysis( void );
00555     CalAnalysis( const CalAnalysis& oCalAnalysis );
00556 
00557     // Unused operator=() function
00558     CalAnalysis& operator=( const CalAnalysis& oCalAnalysis );
00559 
00560 };
00561 
00562 // -----------------------------------------------------------------------------
00563 // End of CalAnalysis class definition
00564 // -----------------------------------------------------------------------------
00565 
00566 // -----------------------------------------------------------------------------
00567 // Start of CalAnalysis template public member functions
00568 // -----------------------------------------------------------------------------
00569 
00570 /*
00571 
00572 CalAnalysis::stats<T>
00573 
00574 Description:
00575 ------------
00576 This member function is the main user interface for calculating the statistics
00577 for all unique groups of (field,antenna1,antenna2).  Allowed T:
00578 CalStats::NONE() only returns the input data, CalStatsFitter::FIT() calculates
00579 fit statistics, and CalStatsHist::HIST() calculates histogram statistics.
00580 
00581 NB: The stats<T>() function calculates statistics (the type depends on T) and
00582     returns the results.
00583   - The user can specify the field(s), antenna 1s, antenna 2s, time range,
00584     feeds, spectral windows, channels, the second iteration axis for the 
00585     CalStats class (time or frequency), normalization, and unwrapping.
00586   - The inputs are checked and fixed, if possible.
00587   - The data are grouped according to unique (field,antenna1,antenna2).
00588   - The resulting group-based information is fed to the CalStats class and its
00589     stats<T>() function calculates the desired statistics which are stored in a
00590     vector of OUTPUT<T>() instances.  Each OUTPUT<T>() element corresponds to a
00591     group.
00592 
00593 Inputs:
00594 -------
00595 oInput  - This reference to an CalAnalysis::INPUT() instance contains all of the
00596           input parameters.
00597 oArg<T> - This reference to a CalStats::ARG<T>() instance contains the extra
00598           input parameters.
00599 
00600 Outputs:
00601 --------
00602 The reference to the Vector<CalAnalysis::OUTPUT<T> >() instance containing the
00603 statistics, returned via the function value.
00604 
00605 Modification history:
00606 ---------------------
00607 2012 Jan 20 - Nick Elias, NRAO
00608               Initial version.
00609 2012 Jan 25 - Nick Elias, NRAO
00610               Logging capability added.
00611 2012 Feb 14 - Nick Elias, NRAO
00612               Updated this code to reflect changes in NewCalTabIter() (now
00613               ROCTIter()) and other classes.  Added a RAP enum as an input
00614               parameter.
00615 2012 Apr 02 - Nick Elias, NRAO
00616               Input parameter dJumpMax added.
00617 2012 Apr 25 - Nick Elias, NRAO
00618               The start and stop channel lists versus spectral window are
00619               replaced with a channel list versus spectral window.
00620 2012 Apr 26 - Nick Elias, NRAO
00621               All input parameter instances grouped together as a INPUT()
00622               instance.
00623 2012 Apr 27 - Nick Elias, NRAO
00624               Input parameters are now checked and fixed by the
00625               statsCheckInput() member function.
00626 2012 May 03 - Nick Elias, NRAO
00627               Replaced the new format calibration table iterator with straight
00628               calls to the NewCalTable() class and column accessor classes.
00629               There is a lot of data reorganization so that they can be fed to
00630               CalStats<T>().
00631 2012 May 06 - Nick Elias, NRAO
00632               The data reorganization has been moved to private member function
00633               getGroup() and is called from here.
00634 
00635 */
00636 
00637 // -----------------------------------------------------------------------------
00638 
00639 template <typename T>
00640 Vector<CalAnalysis::OUTPUT<T> >& CalAnalysis::stats(
00641     const CalAnalysis::INPUT& oInput, const CalStats::ARG<T>& oArg ) {
00642 
00643   // Initialize the output vector containing statistics for each field ID,
00644   // antenna 1, and antenna 2
00645 
00646   Vector<CalAnalysis::OUTPUT<T> >* poOutput =
00647       new Vector<CalAnalysis::OUTPUT<T> >();
00648 
00649 
00650   // Check and fix the inputs
00651 
00652   INPUT oInputNew;
00653 
00654   Bool bCheck = statsCheckInput( oInput, oInputNew );
00655 
00656   if ( !bCheck ) {
00657     LogIO log( LogOrigin( "CalAnalysis", "stats<T>()", WHERE ) );
00658     log << LogIO::WARN << "Invalid parameter(s)" << LogIO::POST;
00659     return( *poOutput );
00660   }
00661 
00662 
00663   // Create an instance of the new format calibration table class
00664   // Use createCT to enforce backward compatibility
00665   NewCalTable oNCT =  NewCalTable::createCT( oCalName, Table::Old, Table::Memory );
00666 
00667 
00668   // Get the cubes for each group
00669 
00670   Vector<uInt> oFieldGroup;
00671   Vector<uInt> oAntenna1Group;
00672   Vector<Int> oAntenna2Group;
00673 
00674   Vector<Vector<Double> > oTimeUniqueGroup;
00675   Vector<Vector<Double> > oFreqGroup;
00676 
00677   Vector<Cube<DComplex> > oCParamGroup;
00678   Vector<Cube<Double> > oFParamGroup;
00679   Vector<Cube<Double> > oParamErrGroup;
00680   Vector<Cube<Bool> > oFlagGroup;
00681 
00682   Bool bGetGroup = getGroup( oNCT, oInputNew, oFieldGroup, oAntenna1Group,
00683       oAntenna2Group, oTimeUniqueGroup, oFreqGroup, oCParamGroup, oFParamGroup,
00684       oParamErrGroup, oFlagGroup );
00685 
00686   if ( !bGetGroup ) {
00687     LogIO log( LogOrigin( "CalAnalysis", "stats<T>()", WHERE ) );
00688     log << LogIO::WARN << "Cannot parse group(s)" << LogIO::POST;
00689     return( *poOutput );
00690   }
00691 
00692 
00693   // Resize the output vector (each group corresponds to an element of
00694   // Vector<OUTPUT<T> >())
00695 
00696   uInt uiNumGroup = oFieldGroup.nelements();
00697 
00698   poOutput->resize( uiNumGroup, False );
00699 
00700 
00701   // Send each group to CalStats<T>() and perform the desired operation
00702 
00703   for ( uInt g=0; g<uiNumGroup; g++ ) {
00704 
00705     poOutput->operator[](g).uiField = oFieldGroup[g];
00706     poOutput->operator[](g).uiAntenna1 = oAntenna1Group[g];
00707     poOutput->operator[](g).iAntenna2 = oAntenna2Group[g];
00708     poOutput->operator[](g).eRAP = oInputNew.eRAP;
00709     poOutput->operator[](g).bNorm = oInputNew.bNorm;
00710     poOutput->operator[](g).bUnwrap = oInputNew.bUnwrap;
00711     poOutput->operator[](g).dJumpMax = oInputNew.dJumpMax;
00712 
00713     CalStats* poCS = NULL;
00714 
00715     try {
00716 
00717       switch ((uInt) oInputNew.eRAP) {
00718         case (uInt) REAL:
00719           poCS = (CalStats*) new CalStatsReal( oFParamGroup[g],
00720               oParamErrGroup[g], oFlagGroup[g], oInputNew.oFeed, oFreqGroup[g],
00721               oTimeUniqueGroup[g], oInputNew.eAxisIterUserID );
00722           break;
00723         case (uInt) AMPLITUDE:
00724           poCS = (CalStats*) new CalStatsAmp( oCParamGroup[g],
00725               oParamErrGroup[g], oFlagGroup[g], oInputNew.oFeed, oFreqGroup[g],
00726               oTimeUniqueGroup[g], oInputNew.eAxisIterUserID, oInputNew.bNorm );
00727           break;
00728         case (uInt) PHASE:
00729           poCS = (CalStats*) new CalStatsPhase( oCParamGroup[g],
00730               oParamErrGroup[g], oFlagGroup[g], oInputNew.oFeed, oFreqGroup[g],
00731               oTimeUniqueGroup[g], oInputNew.eAxisIterUserID, oInputNew.bUnwrap,
00732               oInputNew.dJumpMax );
00733           break;
00734         default:
00735           throw( AipsError( "Invalid parameter (REAL, AMPLITUDE, or PHASE)" ) );
00736       }
00737 
00738       poOutput->operator[](g).oOut = poCS->stats<T>( oArg );
00739 
00740       delete poCS;
00741 
00742     }
00743 
00744     catch ( AipsError oAE ) {
00745       LogIO log( LogOrigin( "CalAnalysis", "stats<T>()", WHERE ) );
00746       log << LogIO::WARN << oAE.getMesg()
00747           << ", iteration (field,antenna1,antenna2) = (" << oFieldGroup[g]
00748           << "," << oAntenna1Group[g] << "," << oAntenna2Group[g]
00749           << "), continuing ..." << LogIO::POST;
00750       poOutput->operator[](g).oOut = CalStats::OUT<T>();
00751     }
00752 
00753   }
00754 
00755 
00756   // Return the reference to the Vector<CalAnalysis::OUTPUT<T> > instance
00757 
00758   return( *poOutput );
00759 
00760 }
00761 
00762 // -----------------------------------------------------------------------------
00763 // End of CalAnalysis template public member functions
00764 // -----------------------------------------------------------------------------
00765 
00766 // -----------------------------------------------------------------------------
00767 // Start of CalAnalysis template static public member functions
00768 // -----------------------------------------------------------------------------
00769 
00770 /*
00771 
00772 CalAnalysis::exists<T>
00773 
00774 Description:
00775 ------------
00776 This member function determines whether a value appears in a vector.
00777 
00778 Inputs:
00779 -------
00780 tValue - This reference to a T variable contains the desired value.
00781 oValue - This reference to a Vector<T> instance contains the values.
00782 
00783 Outputs:
00784 --------
00785 The reference to the existance Bool variable, returned via the function value.
00786 
00787 Modification history:
00788 ---------------------
00789 2012 Jan 20 - Nick Elias, NRAO
00790               Initial version.
00791 
00792 */
00793 
00794 // -----------------------------------------------------------------------------
00795 
00796 template <typename T>
00797 Bool& CalAnalysis::exists( const T& tValue, const Vector<T>& oValue ) {
00798 
00799   // Determine whether the value is present in an array and return the boolean
00800 
00801   Bool* pbValue = new Bool( False );
00802 
00803   for ( uInt v=0; v<oValue.nelements(); v++ ) {
00804     if ( tValue == oValue[v] ) *pbValue = True;
00805   }
00806 
00807   return( *pbValue );
00808 
00809 }
00810 
00811 // -----------------------------------------------------------------------------
00812 
00813 /*
00814 
00815 CalAnalysis::where<T>
00816 
00817 Description:
00818 ------------
00819 This member function returns the index of a search value in a vector.
00820 
00821 Inputs:
00822 -------
00823 tValue - The T instance containing the value for which to search.
00824 oInput - The Vector<T> instance containing the values to be searched.
00825 
00826 Outputs:
00827 --------
00828 uiIndex - The uInt instance containing the index of the search T instance in the
00829           searched Vector<T> instance.
00830 The reference to the Bool containing the success boolean, returned via the
00831 function value.
00832 
00833 Modification history:
00834 ---------------------
00835 2012 May 06 - Nick Elias, NRAO
00836               Initial version.
00837 
00838 */
00839 
00840 // -----------------------------------------------------------------------------
00841 
00842 template <typename T>
00843 Bool& CalAnalysis::where( const T& tValue, const Vector<T>& oInput,
00844     uInt& uiIndex ) {
00845 
00846   // Find the index in the input vector
00847 
00848   for ( uInt i=0; i<oInput.nelements(); i++ ) {
00849     if ( oInput[i] == tValue ) {
00850       uiIndex = i;
00851       break;
00852     }
00853   }
00854 
00855 
00856   // If the value was found return True, otherwise return False
00857 
00858   Bool* pbSuccess = new Bool;
00859 
00860   if ( uiIndex < oInput.nelements() ) {
00861     *pbSuccess = True;
00862   } else {
00863     *pbSuccess = False;
00864   }
00865 
00866   return( *pbSuccess );
00867 
00868 }
00869 
00870 // -----------------------------------------------------------------------------
00871 
00872 /*
00873 
00874 CalAnalysis::unique<T>
00875 
00876 Description:
00877 ------------
00878 This member function returns a unique sorted vector from an input vector.
00879 
00880 Inputs:
00881 -------
00882 oVector - This reference to a Vector<T> instance contains the values.
00883 
00884 Outputs:
00885 --------
00886 The reference to the unique sorted Vector<T> instance, returned via the function
00887 value.
00888 
00889 Modification history:
00890 ---------------------
00891 2012 Jan 20 - Nick Elias, NRAO
00892               Initial version.
00893 
00894 */
00895 
00896 // -----------------------------------------------------------------------------
00897 
00898 template <typename T>
00899 Vector<T>& CalAnalysis::unique( const Vector<T>& oVector ) {
00900 
00901   // Initialize the unique vector
00902 
00903   Vector<T>* poVectorUnique = new Vector<T>();
00904 
00905 
00906   // Form the unique vector
00907 
00908   for ( uInt v1=0; v1<oVector.nelements(); v1++ ) {
00909 
00910     Bool bDupe = False;
00911 
00912     for ( uInt v2=0; v2<v1; v2++ ) {
00913       if ( oVector[v1] == oVector[v2] ) {
00914         bDupe = True;
00915         break;
00916       }
00917     }
00918 
00919     if ( !bDupe ) {
00920       poVectorUnique->resize( poVectorUnique->nelements()+1, True );
00921       poVectorUnique->operator[](poVectorUnique->nelements()-1) = oVector[v1];
00922     }
00923 
00924   }
00925 
00926 
00927   // Sort the unique vector
00928 
00929   Sort::Order eOrder = Sort::Ascending;
00930   Int iOptions = Sort::QuickSort;
00931 
00932   GenSort<T>::sort( *poVectorUnique, eOrder, (int) iOptions );
00933 
00934 
00935   // Return the unique sorted vector
00936 
00937   return( *poVectorUnique );
00938 
00939 }
00940 
00941 // -----------------------------------------------------------------------------
00942 // End of CalAnalysis template static public member functions
00943 // -----------------------------------------------------------------------------
00944 
00945 };
00946 
00947 // -----------------------------------------------------------------------------
00948 // End of casa namespace
00949 // -----------------------------------------------------------------------------
00950 
00951 #endif
00952 
00953 // -----------------------------------------------------------------------------
00954 // End of define macro to prevent multiple loading
00955 // -----------------------------------------------------------------------------
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1