casacore
MSCalEngine.h
Go to the documentation of this file.
1 //# MSCalEngine.h: Engine to calculate derived MS values
2 //# Copyright (C) 2010
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef DERIVEDMSCAL_MSCALENGINE_H
29 #define DERIVEDMSCAL_MSCALENGINE_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/tables/Tables/Table.h>
34 #include <casacore/tables/Tables/ScalarColumn.h>
35 #include <casacore/measures/Measures/MDirection.h>
36 #include <casacore/measures/Measures/MPosition.h>
37 #include <casacore/measures/Measures/MEpoch.h>
38 #include <casacore/measures/Measures/MBaseline.h>
39 #include <casacore/measures/Measures/MeasConvert.h>
40 #include <casacore/measures/TableMeasures/ScalarMeasColumn.h>
41 #include <casacore/casa/vector.h>
42 #include <casacore/casa/stdmap.h>
43 
44 namespace casacore {
45 
46 // <summary>
47 // Engine to calculate derived MS values
48 // </summary>
49 
50 // <use visibility=export>
51 
52 // <reviewed reviewer="" date="" tests="tDerivedMSCal.cc">
53 // </reviewed>
54 
55 // <prerequisite>
56 //# Classes you should understand before using this one.
57 // <li> MeasurementSet
58 // </prerequisite>
59 
60 // <synopsis>
61 // MSCalEngine is a class used to calculate derived MeasurementSet
62 // values hourangle, parallactic angle, azimuth/elevation,
63 // local sidereal time, and UVW coordinates.
64 // It is used by the DerivedMSCal virtual columns and UDFs, but can
65 // be used by other software as well.
66 //
67 // The following values can be obtained:
68 // <ul>
69 // <li> HA is the hourangle of the array center (observatory position).
70 // <li> HA1 is the hourangle of ANTENNA1.
71 // <li> HA2 is the hourangle of ANTENNA2.
72 // <li> HADEC is the hourangle/DEC of the array center (observatory position).
73 // <li> HADEC1 is the hourangle/DEC of ANTENNA1.
74 // <li> HADEC2 is the hourangle/DEC of ANTENNA2.
75 // <li> LAST is the local sidereal time of the array center.
76 // <li> LAST1 is the local sidereal time of ANTENNA1.
77 // <li> LAST2 is the local sidereal time of ANTENNA2.
78 // <li> PA1 is the parallactic angle of ANTENNA1.
79 // <li> PA2 is the parallactic angle of ANTENNA2.
80 // <li> AZEL1 is the azimuth/elevation of ANTENNA1.
81 // <li> AZEL2 is the azimuth/elevation of ANTENNA2.
82 // <li> UVW_J2000 is the UVW coordinates in J2000 (in meters)
83 // </ul>
84 // All values have data type double and unit radian (except UVW). The HADEC,
85 // AZEL, and UVW cvalues are arrays while the others are scalars.
86 //
87 // This engine is meant for a MeasurementSet, but can be used for any table
88 // containing an ANTENNA and FIELD subtable and the relevant columns in the
89 // main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME).
90 // It also looks if columns FEED1 and/or FEED2 exist. They are not used yet,
91 // but might be in the future for support of multi-feed arrays.
92 // <br>In principle the array center is the Observatory position, which is
93 // taken from the Measures Observatory table using the telescope name found
94 // in the OBSERVATION subtable or in the table keyword TELESCOPE_NAME.
95 // However, if the telescope name cannot be found or is unknown, the position
96 // of the middle antenna is used as the array position.
97 //
98 // The new CASA Calibration Table format obeys the rules mentioned above,
99 // so these tables are fully supported. Note they do not contain an
100 // OBSERVATION subtable, but use keyword TELESCOPE_NAME.
101 //
102 // The engine can also be used for old CASA Calibration Tables. It understands
103 // how they reference the MeasurementSets. Because these calibration tables
104 // contain no ANTENNA2 columns, columns XX2 are the same as XX1.
105 // </synopsis>
106 
107 // <motivation>
108 // Factor out common code.
109 // </motivation>
110 
111 // <todo asof="$DATE:$">
112 // <li> Take care of the feeds and their offsets.
113 // <li> Have a conversion engine per field/antenna/feed?
114 // </todo>
115 
117 {
118 public:
119  // Default constructor.
120  MSCalEngine();
121 
122  // Destructor.
123  ~MSCalEngine();
124 
125  // Get the table used.
126  Table getTable() const
127  { return itsTable; }
128 
129  // Use the given table (MS or CalTable) in the engine.
130  void setTable (const Table&);
131 
132  // Set the direction to be used instead of a direction from the FIELD table.
133  void setDirection (const MDirection&);
134 
135  // Set the direction column name to use in the FIELD table.
136  void setDirColName (const String& colName);
137 
138  // Get the hourangle for the given row.
139  double getHA (Int antnr, uInt rownr);
140 
141  // Get the hourangle/DEC for the given row.
142  void getHaDec (Int antnr, uInt rownr, Array<Double>&);
143 
144  // Get the parallatic angle for the given row.
145  double getPA (Int antnr, uInt rownr);
146 
147  // Get the local sidereal time for the given row.
148  double getLAST (Int antnr, uInt rownr);
149 
150  // Get the azimuth/elevation for the given row.
151  void getAzEl (Int antnr, uInt rownr, Array<Double>&);
152 
153  // Get the UVW in J2000 for the given row.
154  void getUVWJ2000 (uInt rownr, Array<Double>&);
155 
156 private:
157  // Copy constructor cannot be used.
158  MSCalEngine (const MSCalEngine& that);
159 
160  // Assignment cannot be used.
161  MSCalEngine& operator= (const MSCalEngine& that);
162 
163  // Set the data in the measure converter machines.
164  // It returns the mount of the antenna.
165  Int setData (Int antnr, uInt rownr);
166 
167  // Initialize the column objects, etc.
168  void init();
169 
170  // Fill the CalDesc info for calibration tables.
171  void fillCalDesc();
172 
173  // Fill or update the antenna positions from the ANTENNA subtable at
174  // row calDescId. It is stored in the calInx-th entry of itsAntPos/itsMount.
175  void fillAntPos (Int calDescId, Int calInx);
176 
177  // Fill or update the field directions from the FIELD subtable at
178  // row calDescId. It is stored in the calInx-th entry of itsFieldDir.
179  void fillFieldDir (Int calDescId, Int calInx);
180 
181  // Get a calibration MS subtable for the given id.
182  Table getSubTable (Int calDescId, const String& subTabName,
183  Bool mustExist=True);
184 
185  //# Declare member variables.
186  Table itsTable; //# MS or CalTable to use
187  Int itsLastCalInx; //# id of CAL_DESC last used
188  Int itsLastFieldId; //# id of the field last used
189  Int itsLastAntId; //# -1 is array position used
191  ScalarColumn<Int> itsAntCol[2]; //# ANTENNA1 and ANTENNA2
192  ScalarColumn<Int> itsFeedCol[2]; //# FEED1 and FEED2
196  ScalarColumn<Int> itsCalCol; //# CAL_DESC_ID
197  map<string,int> itsCalMap; //# map of MS name to index
198  vector<Int> itsCalIdMap; //# map of calId to index
200  vector<vector<MPosition> > itsAntPos; //# ITRF antenna positions
201  vector<vector<Int> > itsMount; //# 1=alt-az 0=else
202  vector<vector<MDirection> > itsFieldDir; //# J2000 field directions
203  Bool itsReadFieldDir; //# False: explicit directions
204  String itsDirColName; //# FIELD DIR column to read
205  vector<vector<MBaseline> > itsAntMB; //# J2000 MBaseline per antenna
206  vector<vector<Vector<double> > > itsAntUvw; //# J2000 UVW per antenna
207  vector<Block<bool> > itsUvwFilled; //# is UVW filled for antenna i?
208  MDirection::Convert itsRADecToAzEl; //# converter ra/dec to az/el
209  MDirection::Convert itsPoleToAzEl; //# converter pole to az/el
210  MDirection::Convert itsRADecToHADec; //# converter ra/dec to ha/dec
211  MDirection::Convert itsDirToJ2000; //# converter direction to J2000
212  MEpoch::Convert itsUTCToLAST; //# converter UTC to LAST
213  MBaseline::Convert itsBLToJ2000; //# convert ITRF to J2000
214  MeasFrame itsFrame; //# frame used by the converters
215  MDirection itsLastDirJ2000; //# itsLastFieldId dir in J2000
216 };
217 
218 
219 } //# end namespace
220 
221 #endif
~MSCalEngine()
Destructor.
A Measure: astronomical direction.
Definition: MDirection.h:174
MSCalEngine & operator=(const MSCalEngine &that)
Assignment cannot be used.
A Measure: position on Earth.
Definition: MPosition.h:79
int Int
Definition: aipstype.h:47
vector< vector< MBaseline > > itsAntMB
Definition: MSCalEngine.h:205
vector< vector< MPosition > > itsAntPos
Definition: MSCalEngine.h:200
Main interface class to a read/write table.
Definition: Table.h:149
void setDirColName(const String &colName)
Set the direction column name to use in the FIELD table.
void fillCalDesc()
Fill the CalDesc info for calibration tables.
vector< vector< Vector< double > > > itsAntUvw
Definition: MSCalEngine.h:206
void setDirection(const MDirection &)
Set the direction to be used instead of a direction from the FIELD table.
Container for Measure frame.
Definition: MeasFrame.h:137
vector< Block< bool > > itsUvwFilled
Definition: MSCalEngine.h:207
map< string, int > itsCalMap
Definition: MSCalEngine.h:197
double getHA(Int antnr, uInt rownr)
Get the hourangle for the given row.
ScalarColumn< Int > itsAntCol[2]
Definition: MSCalEngine.h:191
void getUVWJ2000(uInt rownr, Array< Double > &)
Get the UVW in J2000 for the given row.
ScalarColumn< Int > itsFeedCol[2]
Definition: MSCalEngine.h:192
Table getTable() const
Get the table used.
Definition: MSCalEngine.h:126
vector< vector< MDirection > > itsFieldDir
Definition: MSCalEngine.h:202
ScalarMeasColumn< MEpoch > itsTimeMeasCol
Definition: MSCalEngine.h:195
MDirection::Convert itsRADecToHADec
Definition: MSCalEngine.h:210
void getHaDec(Int antnr, uInt rownr, Array< Double > &)
Get the hourangle/DEC for the given row.
double Double
Definition: aipstype.h:52
ScalarColumn< Int > itsFieldCol
Definition: MSCalEngine.h:193
Table getSubTable(Int calDescId, const String &subTabName, Bool mustExist=True)
Get a calibration MS subtable for the given id.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:39
ScalarColumn< Int > itsCalCol
Definition: MSCalEngine.h:196
void fillFieldDir(Int calDescId, Int calInx)
Fill or update the field directions from the FIELD subtable at row calDescId.
void setTable(const Table &)
Use the given table (MS or CalTable) in the engine.
MEpoch::Convert itsUTCToLAST
Definition: MSCalEngine.h:212
MDirection::Convert itsPoleToAzEl
Definition: MSCalEngine.h:209
vector< Int > itsCalIdMap
Definition: MSCalEngine.h:198
MDirection::Convert itsRADecToAzEl
Definition: MSCalEngine.h:208
double getPA(Int antnr, uInt rownr)
Get the parallatic angle for the given row.
void init()
Initialize the column objects, etc.
void getAzEl(Int antnr, uInt rownr, Array< Double > &)
Get the azimuth/elevation for the given row.
MBaseline::Convert itsBLToJ2000
Definition: MSCalEngine.h:213
MDirection::Convert itsDirToJ2000
Definition: MSCalEngine.h:211
String: the storage and methods of handling collections of characters.
Definition: String.h:223
MSCalEngine()
Default constructor.
Read only access to table scalar Measure columns.
Definition: MBaseline.h:46
Int setData(Int antnr, uInt rownr)
Set the data in the measure converter machines.
double getLAST(Int antnr, uInt rownr)
Get the local sidereal time for the given row.
const Bool True
Definition: aipstype.h:40
this file contains all the compiler specific defines
Definition: mainpage.dox:28
ScalarColumn< Double > itsTimeCol
Definition: MSCalEngine.h:194
void fillAntPos(Int calDescId, Int calInx)
Fill or update the antenna positions from the ANTENNA subtable at row calDescId.
unsigned int uInt
Definition: aipstype.h:48
MDirection itsLastDirJ2000
Definition: MSCalEngine.h:215
vector< vector< Int > > itsMount
Definition: MSCalEngine.h:201
Engine to calculate derived MS values.
Definition: MSCalEngine.h:116