00001 //# MSCalEngine.h: Engine to calculate derived MS values 00002 //# Copyright (C) 2010 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id$ 00027 00028 #ifndef DERIVEDMSCAL_MSCALENGINE_H 00029 #define DERIVEDMSCAL_MSCALENGINE_H 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 #include <casacore/tables/Tables/Table.h> 00034 #include <casacore/tables/Tables/ScalarColumn.h> 00035 #include <casacore/measures/Measures/MDirection.h> 00036 #include <casacore/measures/Measures/MPosition.h> 00037 #include <casacore/measures/Measures/MEpoch.h> 00038 #include <casacore/measures/Measures/MBaseline.h> 00039 #include <casacore/measures/Measures/MeasConvert.h> 00040 #include <casacore/measures/TableMeasures/ScalarMeasColumn.h> 00041 #include <casacore/casa/vector.h> 00042 #include <casacore/casa/stdmap.h> 00043 00044 namespace casacore { 00045 00046 // <summary> 00047 // Engine to calculate derived MS values 00048 // </summary> 00049 00050 // <use visibility=export> 00051 00052 // <reviewed reviewer="" date="" tests="tDerivedMSCal.cc"> 00053 // </reviewed> 00054 00055 // <prerequisite> 00056 //# Classes you should understand before using this one. 00057 // <li> MeasurementSet 00058 // </prerequisite> 00059 00060 // <synopsis> 00061 // MSCalEngine is a class used to calculate derived MeasurementSet 00062 // values hourangle, parallactic angle, azimuth/elevation, 00063 // local sidereal time, and UVW coordinates. 00064 // It is used by the DerivedMSCal virtual columns and UDFs, but can 00065 // be used by other software as well. 00066 // 00067 // The following values can be obtained: 00068 // <ul> 00069 // <li> HA is the hourangle of the array center (observatory position). 00070 // <li> HA1 is the hourangle of ANTENNA1. 00071 // <li> HA2 is the hourangle of ANTENNA2. 00072 // <li> HADEC is the hourangle/DEC of the array center (observatory position). 00073 // <li> HADEC1 is the hourangle/DEC of ANTENNA1. 00074 // <li> HADEC2 is the hourangle/DEC of ANTENNA2. 00075 // <li> LAST is the local sidereal time of the array center. 00076 // <li> LAST1 is the local sidereal time of ANTENNA1. 00077 // <li> LAST2 is the local sidereal time of ANTENNA2. 00078 // <li> PA1 is the parallactic angle of ANTENNA1. 00079 // <li> PA2 is the parallactic angle of ANTENNA2. 00080 // <li> AZEL1 is the azimuth/elevation of ANTENNA1. 00081 // <li> AZEL2 is the azimuth/elevation of ANTENNA2. 00082 // <li> UVW_J2000 is the UVW coordinates in J2000 (in meters) 00083 // </ul> 00084 // All values have data type double and unit radian (except UVW). The HADEC, 00085 // AZEL, and UVW cvalues are arrays while the others are scalars. 00086 // 00087 // This engine is meant for a MeasurementSet, but can be used for any table 00088 // containing an ANTENNA and FIELD subtable and the relevant columns in the 00089 // main table (ANTENNA1 and/or ANTENNA2, FIELD_ID, and TIME). 00090 // It also looks if columns FEED1 and/or FEED2 exist. They are not used yet, 00091 // but might be in the future for support of multi-feed arrays. 00092 // <br>In principle the array center is the Observatory position, which is 00093 // taken from the Measures Observatory table using the telescope name found 00094 // in the OBSERVATION subtable or in the table keyword TELESCOPE_NAME. 00095 // However, if the telescope name cannot be found or is unknown, the position 00096 // of the middle antenna is used as the array position. 00097 // 00098 // The new CASA Calibration Table format obeys the rules mentioned above, 00099 // so these tables are fully supported. Note they do not contain an 00100 // OBSERVATION subtable, but use keyword TELESCOPE_NAME. 00101 // 00102 // The engine can also be used for old CASA Calibration Tables. It understands 00103 // how they reference the MeasurementSets. Because these calibration tables 00104 // contain no ANTENNA2 columns, columns XX2 are the same as XX1. 00105 // </synopsis> 00106 00107 // <motivation> 00108 // Factor out common code. 00109 // </motivation> 00110 00111 // <todo asof="$DATE:$"> 00112 // <li> Take care of the feeds and their offsets. 00113 // <li> Have a conversion engine per field/antenna/feed? 00114 // </todo> 00115 00116 class MSCalEngine 00117 { 00118 public: 00119 // Default constructor. 00120 MSCalEngine(); 00121 00122 // Destructor. 00123 ~MSCalEngine(); 00124 00125 // Get the table used. 00126 Table getTable() const 00127 { return itsTable; } 00128 00129 // Use the given table (MS or CalTable) in the engine. 00130 void setTable (const Table&); 00131 00132 // Set the direction to be used instead of a direction from the FIELD table. 00133 void setDirection (const MDirection&); 00134 00135 // Set the direction column name to use in the FIELD table. 00136 void setDirColName (const String& colName); 00137 00138 // Get the hourangle for the given row. 00139 double getHA (Int antnr, uInt rownr); 00140 00141 // Get the hourangle/DEC for the given row. 00142 void getHaDec (Int antnr, uInt rownr, Array<Double>&); 00143 00144 // Get the parallatic angle for the given row. 00145 double getPA (Int antnr, uInt rownr); 00146 00147 // Get the local sidereal time for the given row. 00148 double getLAST (Int antnr, uInt rownr); 00149 00150 // Get the azimuth/elevation for the given row. 00151 void getAzEl (Int antnr, uInt rownr, Array<Double>&); 00152 00153 // Get the UVW in J2000 for the given row. 00154 void getUVWJ2000 (uInt rownr, Array<Double>&); 00155 00156 private: 00157 // Copy constructor cannot be used. 00158 MSCalEngine (const MSCalEngine& that); 00159 00160 // Assignment cannot be used. 00161 MSCalEngine& operator= (const MSCalEngine& that); 00162 00163 // Set the data in the measure converter machines. 00164 // It returns the mount of the antenna. 00165 Int setData (Int antnr, uInt rownr); 00166 00167 // Initialize the column objects, etc. 00168 void init(); 00169 00170 // Fill the CalDesc info for calibration tables. 00171 void fillCalDesc(); 00172 00173 // Fill or update the antenna positions from the ANTENNA subtable at 00174 // row calDescId. It is stored in the calInx-th entry of itsAntPos/itsMount. 00175 void fillAntPos (Int calDescId, Int calInx); 00176 00177 // Fill or update the field directions from the FIELD subtable at 00178 // row calDescId. It is stored in the calInx-th entry of itsFieldDir. 00179 void fillFieldDir (Int calDescId, Int calInx); 00180 00181 // Get a calibration MS subtable for the given id. 00182 Table getSubTable (Int calDescId, const String& subTabName, 00183 Bool mustExist=True); 00184 00185 //# Declare member variables. 00186 Table itsTable; //# MS or CalTable to use 00187 Int itsLastCalInx; //# id of CAL_DESC last used 00188 Int itsLastFieldId; //# id of the field last used 00189 Int itsLastAntId; //# -1 is array position used 00190 Double itsLastTime; 00191 ScalarColumn<Int> itsAntCol[2]; //# ANTENNA1 and ANTENNA2 00192 ScalarColumn<Int> itsFeedCol[2]; //# FEED1 and FEED2 00193 ScalarColumn<Int> itsFieldCol; //# FIELD_ID 00194 ScalarColumn<Double> itsTimeCol; //# TIME 00195 ScalarMeasColumn<MEpoch> itsTimeMeasCol; //# TIME as Measure 00196 ScalarColumn<Int> itsCalCol; //# CAL_DESC_ID 00197 map<string,int> itsCalMap; //# map of MS name to index 00198 vector<Int> itsCalIdMap; //# map of calId to index 00199 MPosition itsArrayPos; 00200 vector<vector<MPosition> > itsAntPos; //# ITRF antenna positions 00201 vector<vector<Int> > itsMount; //# 1=alt-az 0=else 00202 vector<vector<MDirection> > itsFieldDir; //# J2000 field directions 00203 Bool itsReadFieldDir; //# False: explicit directions 00204 String itsDirColName; //# FIELD DIR column to read 00205 vector<vector<MBaseline> > itsAntMB; //# J2000 MBaseline per antenna 00206 vector<vector<Vector<double> > > itsAntUvw; //# J2000 UVW per antenna 00207 vector<Block<bool> > itsUvwFilled; //# is UVW filled for antenna i? 00208 MDirection::Convert itsRADecToAzEl; //# converter ra/dec to az/el 00209 MDirection::Convert itsPoleToAzEl; //# converter pole to az/el 00210 MDirection::Convert itsRADecToHADec; //# converter ra/dec to ha/dec 00211 MDirection::Convert itsDirToJ2000; //# converter direction to J2000 00212 MEpoch::Convert itsUTCToLAST; //# converter UTC to LAST 00213 MBaseline::Convert itsBLToJ2000; //# convert ITRF to J2000 00214 MeasFrame itsFrame; //# frame used by the converters 00215 MDirection itsLastDirJ2000; //# itsLastFieldId dir in J2000 00216 }; 00217 00218 00219 } //# end namespace 00220 00221 #endif