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> AZEL is the azimuth/elevation of the array center.
81 // <li> AZEL1 is the azimuth/elevation of ANTENNA1.
82 // <li> AZEL2 is the azimuth/elevation of ANTENNA2.
83 // <li> ITRF is the direction in (time-dependent) ITRF coordinates.
84 // <li> UVW_J2000 is the UVW coordinates in J2000 (in meters).
85 // </ul>
86 // All values have data type double and unit radian (except UVW). The HADEC,
87 // AZEL, ITRF and UVW cvalues are arrays while the others are scalars.
88 //
89 // This engine is meant for a MeasurementSet, but can be used for any table
90 // containing an ANTENNA and FIELD subtable and the relevant columns in the
91 // main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME).
92 // It also looks if columns FEED1 and/or FEED2 exist. They are not used yet,
93 // but might be in the future for support of multi-feed arrays.
94 // <br>In principle the array center is the Observatory position, which is
95 // taken from the Measures Observatory table using the telescope name found
96 // in the OBSERVATION subtable or in the table keyword TELESCOPE_NAME.
97 // However, if the telescope name cannot be found or is unknown, the position
98 // of the middle antenna is used as the array position.
99 //
100 // The new CASA Calibration Table format obeys the rules mentioned above,
101 // so these tables are fully supported. Note they do not contain an
102 // OBSERVATION subtable, but use keyword TELESCOPE_NAME.
103 //
104 // The engine can also be used for old CASA Calibration Tables. It understands
105 // how they reference the MeasurementSets. Because these calibration tables
106 // contain no ANTENNA2 columns, columns XX2 are the same as XX1.
107 // </synopsis>
108 
109 // <motivation>
110 // Factor out common code.
111 // </motivation>
112 
113 // <todo asof="$DATE:$">
114 // <li> Take care of the feeds and their offsets.
115 // <li> Have a conversion engine per field/antenna/feed?
116 // </todo>
117 
119 {
120 public:
121  // Default constructor.
122  MSCalEngine();
123 
124  // Destructor.
125  ~MSCalEngine();
126 
127  // Get the table used.
128  Table getTable() const
129  { return itsTable; }
130 
131  // Use the given table (MS or CalTable) in the engine.
132  void setTable (const Table&);
133 
134  // Set the direction to be used instead of a direction from the FIELD table.
135  void setDirection (const MDirection&);
136 
137  // Set the direction column name to use in the FIELD table.
138  void setDirColName (const String& colName);
139 
140  // Get the hourangle for the given row.
141  double getHA (Int antnr, uInt rownr);
142 
143  // Get the hourangle/DEC for the given row.
144  void getHaDec (Int antnr, uInt rownr, Array<Double>&);
145 
146  // Get the parallatic angle for the given row.
147  double getPA (Int antnr, uInt rownr);
148 
149  // Get the local sidereal time for the given row.
150  double getLAST (Int antnr, uInt rownr);
151 
152  // Get the azimuth/elevation for the given row.
153  void getAzEl (Int antnr, uInt rownr, Array<Double>&);
154 
155  // Get the ITRF coordinates for the given row.
156  void getItrf (Int antnr, uInt rownr, Array<Double>&);
157 
158  // Get the UVW in J2000 for the given row.
159  void getUVWJ2000 (uInt rownr, Array<Double>&);
160 
161 private:
162  // Copy constructor cannot be used.
163  MSCalEngine (const MSCalEngine& that);
164 
165  // Assignment cannot be used.
166  MSCalEngine& operator= (const MSCalEngine& that);
167 
168  // Set the data in the measure converter machines.
169  // It returns the mount of the antenna.
170  Int setData (Int antnr, uInt rownr);
171 
172  // Initialize the column objects, etc.
173  void init();
174 
175  // Fill the CalDesc info for calibration tables.
176  void fillCalDesc();
177 
178  // Fill or update the antenna positions from the ANTENNA subtable at
179  // row calDescId. It is stored in the calInx-th entry of itsAntPos/itsMount.
180  void fillAntPos (Int calDescId, Int calInx);
181 
182  // Fill or update the field directions from the FIELD subtable at
183  // row calDescId. It is stored in the calInx-th entry of itsFieldDir.
184  void fillFieldDir (Int calDescId, Int calInx);
185 
186  // Get a calibration MS subtable for the given id.
187  Table getSubTable (Int calDescId, const String& subTabName,
188  Bool mustExist=True);
189 
190  //# Declare member variables.
191  Table itsTable; //# MS or CalTable to use
192  Int itsLastCalInx; //# id of CAL_DESC last used
193  Int itsLastFieldId; //# id of the field last used
194  Int itsLastAntId; //# -1 is array position used
196  ScalarColumn<Int> itsAntCol[2]; //# ANTENNA1 and ANTENNA2
197  ScalarColumn<Int> itsFeedCol[2]; //# FEED1 and FEED2
201  ScalarColumn<Int> itsCalCol; //# CAL_DESC_ID
202  map<string,int> itsCalMap; //# map of MS name to index
203  vector<Int> itsCalIdMap; //# map of calId to index
205  vector<vector<MPosition> > itsAntPos; //# ITRF antenna positions
206  vector<vector<Int> > itsMount; //# 1=alt-az 0=else
207  vector<vector<MDirection> > itsFieldDir; //# J2000 field directions
208  Bool itsReadFieldDir; //# False: explicit directions
209  String itsDirColName; //# FIELD DIR column to read
210  vector<vector<MBaseline> > itsAntMB; //# J2000 MBaseline per antenna
211  vector<vector<Vector<double> > > itsAntUvw; //# J2000 UVW per antenna
212  vector<Block<bool> > itsUvwFilled; //# is UVW filled for antenna i?
213  MDirection::Convert itsRADecToAzEl; //# converter ra/dec to az/el
214  MDirection::Convert itsPoleToAzEl; //# converter pole to az/el
215  MDirection::Convert itsRADecToHADec; //# converter ra/dec to ha/dec
216  MDirection::Convert itsRADecToItrf; //# converter ra/dec to itrf
217  MDirection::Convert itsDirToJ2000; //# converter direction to J2000
218  MEpoch::Convert itsUTCToLAST; //# converter UTC to LAST
219  MBaseline::Convert itsBLToJ2000; //# convert ITRF to J2000
220  MeasFrame itsFrame; //# frame used by the converters
221  MDirection itsLastDirJ2000; //# itsLastFieldId dir in J2000
222 };
223 
224 
225 } //# end namespace
226 
227 #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:50
vector< vector< MBaseline > > itsAntMB
Definition: MSCalEngine.h:210
vector< vector< MPosition > > itsAntPos
Definition: MSCalEngine.h:205
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:211
void setDirection(const MDirection &)
Set the direction to be used instead of a direction from the FIELD table.
void getItrf(Int antnr, uInt rownr, Array< Double > &)
Get the ITRF coordinates for the given row.
Container for Measure frame.
Definition: MeasFrame.h:137
vector< Block< bool > > itsUvwFilled
Definition: MSCalEngine.h:212
map< string, int > itsCalMap
Definition: MSCalEngine.h:202
double getHA(Int antnr, uInt rownr)
Get the hourangle for the given row.
ScalarColumn< Int > itsAntCol[2]
Definition: MSCalEngine.h:196
void getUVWJ2000(uInt rownr, Array< Double > &)
Get the UVW in J2000 for the given row.
ScalarColumn< Int > itsFeedCol[2]
Definition: MSCalEngine.h:197
Table getTable() const
Get the table used.
Definition: MSCalEngine.h:128
vector< vector< MDirection > > itsFieldDir
Definition: MSCalEngine.h:207
ScalarMeasColumn< MEpoch > itsTimeMeasCol
Definition: MSCalEngine.h:200
MDirection::Convert itsRADecToHADec
Definition: MSCalEngine.h:215
void getHaDec(Int antnr, uInt rownr, Array< Double > &)
Get the hourangle/DEC for the given row.
double Double
Definition: aipstype.h:55
ScalarColumn< Int > itsFieldCol
Definition: MSCalEngine.h:198
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:42
ScalarColumn< Int > itsCalCol
Definition: MSCalEngine.h:201
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:218
MDirection::Convert itsPoleToAzEl
Definition: MSCalEngine.h:214
vector< Int > itsCalIdMap
Definition: MSCalEngine.h:203
MDirection::Convert itsRADecToAzEl
Definition: MSCalEngine.h:213
double getPA(Int antnr, uInt rownr)
Get the parallatic angle for the given row.
MDirection::Convert itsRADecToItrf
Definition: MSCalEngine.h:216
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:219
MDirection::Convert itsDirToJ2000
Definition: MSCalEngine.h:217
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:43
this file contains all the compiler specific defines
Definition: mainpage.dox:28
ScalarColumn< Double > itsTimeCol
Definition: MSCalEngine.h:199
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:51
MDirection itsLastDirJ2000
Definition: MSCalEngine.h:221
vector< vector< Int > > itsMount
Definition: MSCalEngine.h:206
Engine to calculate derived MS values.
Definition: MSCalEngine.h:118