casacore
FitsIDItoMS.h
Go to the documentation of this file.
1 //# FITSIDItoMS.h: Convert a FITS-IDI binary table to an AIPS++ Table.
2 //# Copyright (C) 1995,1996,2000,2001
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 //# Mod 2010: DP
28 
29 #ifndef MS_FITSIDITOMS_H
30 #define MS_FITSIDITOMS_H
31 
32 #include <casacore/casa/aips.h>
33 #include <casacore/fits/FITS/hdu.h>
34 #include <casacore/tables/Tables/Table.h> //
35 #include <casacore/tables/Tables/TableDesc.h> //
36 #include <casacore/tables/Tables/TableRecord.h> //
37 #include <casacore/tables/Tables/TableColumn.h> //
38 #include <casacore/casa/Arrays/Vector.h>
39 #include <casacore/casa/Arrays/Matrix.h>
40 #include <casacore/casa/Containers/Block.h>
41 #include <casacore/casa/Logging/LogIO.h>
42 #include <casacore/measures/Measures/MFrequency.h>
43 #include <casacore/ms/MeasurementSets/MeasurementSet.h>
44 #include <casacore/casa/BasicSL/String.h>
45 #include <map>
46 
47 namespace casacore { //# NAMESPACE CASACORE - BEGIN
48 
49 class MSColumns;
50 class FitsInput;
51 
52 
53 // <summary>
54 // FITSIDItoMS converts a FITS-IDI file to a CASA Measurement Set
55 // </summary>
56 
57 // <use visibility=export>
58 
59 // <reviewed reviewer="" date="" tests="">
60 
61 // <prerequisite>
62 //# Classes you should understand before using this one.
63 // <li> FitsInput
64 // <li> HeaderDataUnit
65 // <li> BinaryTableExtension
66 // <li> Tables module
67 // </prerequisite>
68 
69 // <etymology>
70 
71 // FITSIDItoMS inherits from the FITS BinaryTableExtension class and
72 // its primary use is to convert such an object to a CASA Table.
73 // This explains it's use but not its name. A better name should be
74 // found.
75 
76 // </etymology>
77 
78 // <synopsis>
79 // The class starts with an already existing FitsInput object, which
80 // should be set at a BinaryTableExtension HDU. Member functions
81 // provide a TableDesc appropriate for the FITS data (to help in
82 // constructing a CASA Table compatible with the
83 // BinaryTableExtension), a Table containing the current row of FITS
84 // data and a Table containing the next row of FITS data (which can be
85 // used to step through the FitsInput, copying each row using the
86 // RowCopier class), and a Table containin the entire FITS binary
87 // table from the current row to the end of the table.
88 // </synopsis>
89 
90 // <motivation>
91 // We need a way to get FITS-IDI data (typically from VLBI observations) into CASA.
92 // </motivation>
93 
94 // <example>
95 // Open a FitsInput from a disk file, if the HDU is a
96 // BinaryTableExtension, then instantiate a MSBinaryTable object and
97 // get the entire table. A fair amount of error checking has been
98 // eliminated from this example.
99 // <srcblock>
100 // FitsInput infits("myFITSFile", FITS::Disk);
101 // switch (infits.hdutype()) {
102 // case FITS::BinaryTableHDU:
103 // MSBinaryTable bintab(infits);
104 // Table tab = bintab.fullTable("myTable");
105 // break;
106 // }
107 // </srcblock>
108 // There would obviously be other cases to the switch to deal with any
109 // other HDUs (e.g. skip them via infits.skip_hdu()). The Table
110 // destructor would write "myTable" to disk.
111 // </example>
112 
113 // <todo>
114 //
115 // </todo>
116 
118 {
119 public:
120 
121  //
122  // The only constructor is from a FitsInput. The correlat string
123  // should be set to the correlator name/type as contained in the
124  // CORRELAT keyword from the FITS-IDI primary header. If it is set
125  // to "DIFX" (case-sensitive) additional digital corrections
126  // appropriate for the DiFX software correlator will be applied.
127  // Other valid values include "VLBA" (for the original VLBA hardware
128  // correlator; currently unsupported) and "SFXC" (for the SFXC
129  // software correlator used by the EVN).
130  //
131 
132  FITSIDItoMS1(FitsInput& in, const String& correlat, const Int& obsType=0, const Bool& initFirstMain=True);
133 
135 
136  //
137  // Get the full table, using the supplied arguments to construct
138  // the table. The table will contain all data from the current
139  // row to the end of the BinaryTableExtension.
140  //
141 
142  Table oldfullTable(const String& tabName);
143 
144 
145  // Fill the Observation and ObsLog tables
147 
148  // Read a binary table extension of type ANTENNA and create an antenna table
149  //void fillAntennaTable(BinaryTable& bt);
151 
152  // fill the Feed table with minimal info needed for synthesis processing
154 
155  //fill the Field table
156  //void fillFieldTable(Int nField);
158 
159  //fill the Spectral Window table with the content of FREQUENCY
161 
162  //fill the optional Correlator Model table with the content of INTERFEROMETER_MODEL
164 
165  //fill the optional SysCal table with the content of SYSTEM_TEMPERATURE
167 
168  //fill the optional FlagCmd table with the content of FLAG
170 
171  //fill the optional Weather table with the content of WEATHER
173 
174  //store the information from the GAIN_CURVE table in a calibration table
176 
177  //store the information from the PHASE-CAL table in a calibration table
179 
180  //store the information from the MODEL_COMPS table
182 
183  // fix up the EPOCH MEASURE_REFERENCE keywords
185 
186  //update the Polarization table
187  void updateTables(const String& tabName);
188 
189 
190  //
191  // Get an appropriate TableDesc (this is the same TableDesc used
192  // to construct any Table objects returned by this class.
193  //
195 
196  //
197  // Return the Table keywords (this is the same TableRecord used in
198  // any Table objects returned by this class.
199  //
201 
202  //
203  // Get a Table with a single row, the current row of the FITS
204  // table. The returned Table is a Scratch table. The standard
205  // BinaryTableExtension manipulation functions are available to
206  // position the FITS input at the desired location.
207  //
208  const Table &thisRow();
209 
210  //
211  // Get a Table with a single row, the next row of the FITS table.
212  // The returned Table is a Scratch table. The FITS input is
213  // positioned to the next row and the values translated and
214  // returned in a Table object.
215  //
216  const Table &nextRow();
217 
218  // Get the version of the archived MS.
219  Float msVersion() const
220  { return itsVersion; }
221 
222  // Read all the data from the FITS file and create the MeasurementSet. Throws
223  // an exception when it has severe trouble interpreting the FITS file.
224  // Returns False if it encounters an unsupported extension.
225  Bool readFitsFile(const String& msFile);
226 
227  //is this the first UV_DATA extension
229 
230 protected:
231  // Read the axis info, throws an exception if required axes are missing.
232  void getAxisInfo();
233 
234  // Set up the MeasurementSet, including StorageManagers and fixed columns.
235  // If useTSM is True, the Tiled Storage Manager will be used to store
236  // DATA, FLAG and WEIGHT_SPECTRUM
237  void setupMeasurementSet(const String& MSFileName, Bool useTSM=True,
238  Bool mainTbl=False, Bool addCorrMod=False,
239  Bool addSyscal=False, Bool addWeather=False);
240 
241  // Fill the main table from the Primary group data
242  void fillMSMainTable(const String& MSFileName, Int& nField, Int& nSpW);
243 
244  private:
245  //
246  //# Data Members
247  //
248 
249  // The scratch table containing the current row
251 
252  // The number of elements for each column of the
253  // BinaryTableExtension
255 
256  // For each column: is it an array?
258 
259  // Table keyword set
261 
262  // Table descriptor for construction
264 
265  // Table info
267 
268  // The MS version.
270 
271  //
272  // Buffer for storing the MSK's, MS-specific FITS keywords.
273  //
279 
280 
281  //# FitsInput &infile_p;
288  static String array_p;
291  static Double rdate;
297  //# Int nIF_p;
304  static Bool firstMain;
314  static std::map<Int,Int> antIdFromNo;
315  static std::map<Int,Int> digiLevels;
317 
318  //
319  //# Member Functions
320  //
321 
322  // Fill in each row as needed
323  void fillRow();
324 
325  // Build part of the keywords of the itsCurRowTab
327 
328  // Convert FITS field descriptions to TableColumn descriptions.
330 
331  // Convert the MS-specific keywords in the FITS binary table.
333 };
334 
335 
336 } //# NAMESPACE CASACORE - END
337 
338 #endif
339 
340 
casacore::FITSIDItoMS1::fillCorrelatorModelTable
Bool fillCorrelatorModelTable()
fill the optional Correlator Model table with the content of INTERFEROMETER_MODEL
casacore::TableDesc
Define the structure of a Casacore table.
Definition: TableDesc.h:188
casacore::FITSIDItoMS1
FITSIDItoMS converts a FITS-IDI file to a CASA Measurement Set
Definition: FitsIDItoMS.h:118
casacore::FITSIDItoMS1::corrProduct_p
Matrix< Int > corrProduct_p
Definition: FitsIDItoMS.h:285
casacore::FITSIDItoMS1::itsNrMSKs
uInt itsNrMSKs
Buffer for storing the MSK's, MS-specific FITS keywords.
Definition: FitsIDItoMS.h:274
casacore::Matrix< Int >
casacore::FITSIDItoMS1::refVal_p
Vector< Double > refVal_p
Definition: FitsIDItoMS.h:287
casacore::FITSIDItoMS1::weather_hasWater_p
Bool weather_hasWater_p
Definition: FitsIDItoMS.h:307
casacore::FITSIDItoMS1::corrType_p
Vector< Int > corrType_p
Definition: FitsIDItoMS.h:283
casacore::FITSIDItoMS1::updateTables
void updateTables(const String &tabName)
update the Polarization table
casacore::FITSIDItoMS1::fillObsTables
void fillObsTables()
Fill the Observation and ObsLog tables.
casacore::FITSIDItoMS1::fillWeatherTable
Bool fillWeatherTable()
fill the optional Weather table with the content of WEATHER
casacore::FITSIDItoMS1::fillFieldTable
void fillFieldTable()
fill the Field table void fillFieldTable(Int nField);
casacore::FITSIDItoMS1::weightyp_p
String weightyp_p
Definition: FitsIDItoMS.h:311
casacore::TableRecord
A hierarchical collection of named fields of various types.
Definition: TableRecord.h:183
casacore::FITSIDItoMS1::corrIndex_p
Block< Int > corrIndex_p
Definition: FitsIDItoMS.h:284
casacore::FITSIDItoMS1::array_p
static String array_p
Definition: FitsIDItoMS.h:288
casacore::FITSIDItoMS1::epoch_p
Double epoch_p
Definition: FitsIDItoMS.h:290
casacore::FITSIDItoMS1::refPix_p
Vector< Double > refPix_p
Definition: FitsIDItoMS.h:287
casacore::FITSIDItoMS1::getDescriptor
const TableDesc & getDescriptor()
Get an appropriate TableDesc (this is the same TableDesc used to construct any Table objects returned...
casacore::FITSIDItoMS1::itsTableInfo
TableInfo itsTableInfo
Table info.
Definition: FitsIDItoMS.h:266
casacore::FITSIDItoMS1::nStokes_p
Int nStokes_p
Definition: FitsIDItoMS.h:312
casacore::FITSIDItoMS1::itsMSKV
Vector< String > itsMSKV
Definition: FitsIDItoMS.h:277
casacore::FITSIDItoMS1::itsNelem
Vector< Int > itsNelem
The number of elements for each column of the BinaryTableExtension.
Definition: FitsIDItoMS.h:254
casacore::FITSIDItoMS1::ms_p
MeasurementSet ms_p
Definition: FitsIDItoMS.h:302
casacore::FITSIDItoMS1::firstMain
static Bool firstMain
Definition: FitsIDItoMS.h:304
casacore::FITSIDItoMS1::nPixel_p
Vector< Int > nPixel_p
Definition: FitsIDItoMS.h:283
casacore::FITSIDItoMS1::oldfullTable
Table oldfullTable(const String &tabName)
Get the full table, using the supplied arguments to construct the table.
casacore::FITSIDItoMS1::nextRow
const Table & nextRow()
Get a Table with a single row, the next row of the FITS table.
casacore::FITSIDItoMS1::itsLog
LogIO * itsLog
Definition: FitsIDItoMS.h:296
casacore::FITSIDItoMS1::itsTableDesc
TableDesc itsTableDesc
Table descriptor for construction.
Definition: FitsIDItoMS.h:263
casacore::FITSIDItoMS1::readFitsFile
Bool readFitsFile(const String &msFile)
Read all the data from the FITS file and create the MeasurementSet.
casacore::FITSIDItoMS1::itsCurRowTab
Table itsCurRowTab
The scratch table containing the current row.
Definition: FitsIDItoMS.h:250
casacore::FITSIDItoMS1::fillSysCalTable
Bool fillSysCalTable()
fill the optional SysCal table with the content of SYSTEM_TEMPERATURE
casacore::FITSIDItoMS1::lastTime_p
Double lastTime_p
Definition: FitsIDItoMS.h:299
casacore::FITSIDItoMS1::firstSyscal
static Bool firstSyscal
Definition: FitsIDItoMS.h:305
casacore::BinaryTableExtension
BINTABLE extension
Definition: hdu.h:1035
casacore::FITSIDItoMS1::nAnt_p
Int nAnt_p
Definition: FitsIDItoMS.h:292
casacore::FITSIDItoMS1::getKeywords
TableRecord & getKeywords()
Return the Table keywords (this is the same TableRecord used in any Table objects returned by this cl...
casacore::FITSIDItoMS1::isfirstMain
Bool isfirstMain()
is this the first UV_DATA extension
Definition: FitsIDItoMS.h:228
casacore::FITSIDItoMS1::fillSpectralWindowTable
void fillSpectralWindowTable()
fill the Spectral Window table with the content of FREQUENCY
casacore::FITSIDItoMS1::fillFeedTable
void fillFeedTable()
fill the Feed table with minimal info needed for synthesis processing
casacore::FITSIDItoMS1::firstWeather
static Bool firstWeather
Definition: FitsIDItoMS.h:306
casacore::FITSIDItoMS1::fillMSMainTable
void fillMSMainTable(const String &MSFileName, Int &nField, Int &nSpW)
Fill the main table from the Primary group data.
casacore::FITSIDItoMS1::itsVersion
Float itsVersion
The MS version.
Definition: FitsIDItoMS.h:269
casacore::LogIO
ostream-like interface to creating log messages.
Definition: LogIO.h:168
casacore::FITSIDItoMS1::convertKeywords
void convertKeywords()
Build part of the keywords of the itsCurRowTab.
casacore::FITSIDItoMS1::delta_p
Vector< Double > delta_p
Definition: FitsIDItoMS.h:287
casacore::Float
float Float
Definition: aipstype.h:54
casacore::Table
Main interface class to a read/write table.
Definition: Table.h:154
casacore::Double
double Double
Definition: aipstype.h:55
casacore::FITSIDItoMS1::handlePhaseCal
Bool handlePhaseCal()
store the information from the PHASE-CAL table in a calibration table
casacore::FITSIDItoMS1::itsMSKC
Vector< String > itsMSKC
Definition: FitsIDItoMS.h:275
casacore::FITSIDItoMS1::uv_data_hasWeights_p
Bool uv_data_hasWeights_p
Definition: FitsIDItoMS.h:309
casacore::False
const Bool False
Definition: aipstype.h:44
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::FITSIDItoMS1::thisRow
const Table & thisRow()
Get a Table with a single row, the current row of the FITS table.
casacore::FITSIDItoMS1::itsKwSet
TableRecord itsKwSet
Table keyword set.
Definition: FitsIDItoMS.h:260
casacore::FITSIDItoMS1::msFile_p
String msFile_p
Definition: FitsIDItoMS.h:282
casacore::FITSIDItoMS1::fillFlagCmdTable
Bool fillFlagCmdTable()
fill the optional FlagCmd table with the content of FLAG
casacore::FITSIDItoMS1::weightypKwPresent_p
Bool weightypKwPresent_p
Definition: FitsIDItoMS.h:310
casacore::FITSIDItoMS1::msVersion
Float msVersion() const
Get the version of the archived MS.
Definition: FitsIDItoMS.h:219
casacore::FITSIDItoMS1::freqsys_p
MFrequency::Types freqsys_p
Definition: FitsIDItoMS.h:294
casacore::FITSIDItoMS1::fillAntennaTable
void fillAntennaTable()
Read a binary table extension of type ANTENNA and create an antenna table void fillAntennaTable(Binar...
casacore::FITSIDItoMS1::effChBw
static Vector< Double > effChBw
Definition: FitsIDItoMS.h:316
casacore::TableInfo
Table type, subtype and further info.
Definition: TableInfo.h:131
casacore::FITSIDItoMS1::fillRow
void fillRow()
Fill in each row as needed.
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::FITSIDItoMS1::itsMSKN
Vector< String > itsMSKN
Definition: FitsIDItoMS.h:276
casacore::MFrequency::Types
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition: MFrequency.h:176
casacore::FITSIDItoMS1::itsCorrelat
String itsCorrelat
Definition: FitsIDItoMS.h:301
casacore::True
const Bool True
Definition: aipstype.h:43
casacore::FITSIDItoMS1::digiLevels
static std::map< Int, Int > digiLevels
Definition: FitsIDItoMS.h:315
casacore::FITSIDItoMS1::startTime_p
Double startTime_p
Definition: FitsIDItoMS.h:298
casacore::FITSIDItoMS1::itsIsArray
Vector< Bool > itsIsArray
For each column: is it an array?
Definition: FitsIDItoMS.h:257
casacore::FITSIDItoMS1::handleModelComps
Bool handleModelComps()
store the information from the MODEL_COMPS table
casacore::FitsInput
fixed-length sequential blocked FITS input
Definition: fitsio.h:156
casacore::FITSIDItoMS1::~FITSIDItoMS1
~FITSIDItoMS1()
casacore::FITSIDItoMS1::timsys_p
String timsys_p
Definition: FitsIDItoMS.h:289
casacore::MeasurementSet
A Table intended to hold astronomical data (a set of Measurements).
Definition: MeasurementSet.h:243
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::FITSIDItoMS1::fixEpochReferences
void fixEpochReferences()
fix up the EPOCH MEASURE_REFERENCE keywords
casacore::FITSIDItoMS1::coordType_p
Vector< String > coordType_p
Definition: FitsIDItoMS.h:286
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Block< Int >
casacore::FITSIDItoMS1::nBand_p
Int nBand_p
Definition: FitsIDItoMS.h:313
casacore::FITSIDItoMS1::itsObsType
Int itsObsType
Definition: FitsIDItoMS.h:300
casacore::FITSIDItoMS1::convertMSKeywords
void convertMSKeywords()
Convert the MS-specific keywords in the FITS binary table.
casacore::FITSIDItoMS1::weather_hasElectron_p
Bool weather_hasElectron_p
Definition: FitsIDItoMS.h:308
casacore::MSColumns
A class to provide easy access to MeasurementSet columns.
Definition: MSColumns.h:117
casacore::Vector< Int >
casacore::FITSIDItoMS1::itsgotMSK
Vector< Bool > itsgotMSK
Definition: FitsIDItoMS.h:278
casacore::FITSIDItoMS1::msc_p
MSColumns * msc_p
Definition: FitsIDItoMS.h:303
casacore::FITSIDItoMS1::antIdFromNo
static std::map< Int, Int > antIdFromNo
Definition: FitsIDItoMS.h:314
casacore::FITSIDItoMS1::setupMeasurementSet
void setupMeasurementSet(const String &MSFileName, Bool useTSM=True, Bool mainTbl=False, Bool addCorrMod=False, Bool addSyscal=False, Bool addWeather=False)
Set up the MeasurementSet, including StorageManagers and fixed columns.
casacore::FITSIDItoMS1::describeColumns
void describeColumns()
Convert FITS field descriptions to TableColumn descriptions.
casacore::FITSIDItoMS1::FITSIDItoMS1
FITSIDItoMS1(FitsInput &in, const String &correlat, const Int &obsType=0, const Bool &initFirstMain=True)
The only constructor is from a FitsInput.
casacore::FITSIDItoMS1::rdate
static Double rdate
Definition: FitsIDItoMS.h:291
casacore::FITSIDItoMS1::getAxisInfo
void getAxisInfo()
Read the axis info, throws an exception if required axes are missing.
casacore::FITSIDItoMS1::restfreq_p
Double restfreq_p
Definition: FitsIDItoMS.h:295
casacore::FITSIDItoMS1::object_p
String object_p
Definition: FitsIDItoMS.h:289
casacore::FITSIDItoMS1::handleGainCurve
Bool handleGainCurve()
store the information from the GAIN_CURVE table in a calibration table
casacore::FITSIDItoMS1::receptorAngle_p
Vector< Double > receptorAngle_p
Definition: FitsIDItoMS.h:293