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  Bool addGainCurve=False);
241 
242  // Fill the main table from the Primary group data
243  void fillMSMainTable(const String& MSFileName, Int& nField, Int& nSpW);
244 
245  private:
246  //
247  //# Data Members
248  //
249 
250  // The scratch table containing the current row
252 
253  // The number of elements for each column of the
254  // BinaryTableExtension
256 
257  // For each column: is it an array?
259 
260  // Table keyword set
262 
263  // Table descriptor for construction
265 
266  // Table info
268 
269  // The MS version.
271 
272  //
273  // Buffer for storing the MSK's, MS-specific FITS keywords.
274  //
280 
281 
282  //# FitsInput &infile_p;
289  static String array_p;
292  static Double rdate;
298  //# Int nIF_p;
305  static Bool firstMain;
316  static std::map<Int,Int> antIdFromNo;
317  static std::map<Int,Int> digiLevels;
319 
320  //
321  //# Member Functions
322  //
323 
324  // Fill in each row as needed
325  void fillRow();
326 
327  // Build part of the keywords of the itsCurRowTab
329 
330  // Convert FITS field descriptions to TableColumn descriptions.
332 
333  // Convert the MS-specific keywords in the FITS binary table.
335 };
336 
337 
338 } //# NAMESPACE CASACORE - END
339 
340 #endif
341 
342 
BINTABLE extension
Definition: hdu.h:1035
void convertKeywords()
Build part of the keywords of the itsCurRowTab.
Float msVersion() const
Get the version of the archived MS.
Definition: FitsIDItoMS.h:219
Bool readFitsFile(const String &msFile)
Read all the data from the FITS file and create the MeasurementSet.
TableRecord & getKeywords()
Return the Table keywords (this is the same TableRecord used in any Table objects returned by this cl...
Bool fillSysCalTable()
fill the optional SysCal table with the content of SYSTEM_TEMPERATURE
Vector< Double > receptorAngle_p
Definition: FitsIDItoMS.h:294
static Bool firstWeather
Definition: FitsIDItoMS.h:307
TableDesc itsTableDesc
Table descriptor for construction.
Definition: FitsIDItoMS.h:264
Vector< String > itsMSKV
Definition: FitsIDItoMS.h:278
MeasurementSet ms_p
Definition: FitsIDItoMS.h:303
void updateTables(const String &tabName)
update the Polarization table
Bool handlePhaseCal()
store the information from the PHASE-CAL table in a calibration table
Vector< Int > itsNelem
The number of elements for each column of the BinaryTableExtension.
Definition: FitsIDItoMS.h:255
Block< Int > corrIndex_p
Definition: FitsIDItoMS.h:285
Vector< Double > refPix_p
Definition: FitsIDItoMS.h:288
void fillSpectralWindowTable()
fill the Spectral Window table with the content of FREQUENCY
FITSIDItoMS1(FitsInput &in, const String &correlat, const Int &obsType=0, const Bool &initFirstMain=True)
The only constructor is from a FitsInput.
static Bool firstGainCurve
Definition: FitsIDItoMS.h:308
void setupMeasurementSet(const String &MSFileName, Bool useTSM=True, Bool mainTbl=False, Bool addCorrMod=False, Bool addSyscal=False, Bool addWeather=False, Bool addGainCurve=False)
Set up the MeasurementSet, including StorageManagers and fixed columns.
void fillMSMainTable(const String &MSFileName, Int &nField, Int &nSpW)
Fill the main table from the Primary group data.
uInt itsNrMSKs
Buffer for storing the MSK's, MS-specific FITS keywords.
Definition: FitsIDItoMS.h:275
Table oldfullTable(const String &tabName)
Get the full table, using the supplied arguments to construct the table.
Vector< String > itsMSKN
Definition: FitsIDItoMS.h:277
Vector< Int > corrType_p
Definition: FitsIDItoMS.h:284
TableRecord itsKwSet
Table keyword set.
Definition: FitsIDItoMS.h:261
const TableDesc & getDescriptor()
Get an appropriate TableDesc (this is the same TableDesc used to construct any Table objects returned...
void fillObsTables()
Fill the Observation and ObsLog tables.
static std::map< Int, Int > digiLevels
Definition: FitsIDItoMS.h:317
TableInfo itsTableInfo
Table info.
Definition: FitsIDItoMS.h:267
Vector< Double > refVal_p
Definition: FitsIDItoMS.h:288
void getAxisInfo()
Read the axis info, throws an exception if required axes are missing.
Bool fillFlagCmdTable()
fill the optional FlagCmd table with the content of FLAG
void fixEpochReferences()
fix up the EPOCH MEASURE_REFERENCE keywords
Vector< String > coordType_p
Definition: FitsIDItoMS.h:287
static Vector< Double > effChBw
Definition: FitsIDItoMS.h:318
Matrix< Int > corrProduct_p
Definition: FitsIDItoMS.h:286
Bool handleGainCurve()
store the information from the GAIN_CURVE table in a calibration table
Vector< Bool > itsIsArray
For each column: is it an array?
Definition: FitsIDItoMS.h:258
static String array_p
Definition: FitsIDItoMS.h:289
Vector< Int > nPixel_p
Definition: FitsIDItoMS.h:284
Bool fillWeatherTable()
fill the optional Weather table with the content of WEATHER
const Table & thisRow()
Get a Table with a single row, the current row of the FITS table.
void describeColumns()
Convert FITS field descriptions to TableColumn descriptions.
Table itsCurRowTab
The scratch table containing the current row.
Definition: FitsIDItoMS.h:251
void fillFieldTable()
fill the Field table void fillFieldTable(Int nField);
MFrequency::Types freqsys_p
Definition: FitsIDItoMS.h:295
Block< Int > corrSwapIndex_p
Definition: FitsIDItoMS.h:285
Bool handleModelComps()
store the information from the MODEL_COMPS table
void fillAntennaTable()
Read a binary table extension of type ANTENNA and create an antenna table void fillAntennaTable(Binar...
Bool fillCorrelatorModelTable()
fill the optional Correlator Model table with the content of INTERFEROMETER_MODEL
static Bool firstSyscal
Definition: FitsIDItoMS.h:306
Bool isfirstMain()
is this the first UV_DATA extension
Definition: FitsIDItoMS.h:228
void convertMSKeywords()
Convert the MS-specific keywords in the FITS binary table.
void fillRow()
Fill in each row as needed.
const Table & nextRow()
Get a Table with a single row, the next row of the FITS table.
static Double rdate
Definition: FitsIDItoMS.h:292
Float itsVersion
The MS version.
Definition: FitsIDItoMS.h:270
void fillFeedTable()
fill the Feed table with minimal info needed for synthesis processing
Vector< Double > delta_p
Definition: FitsIDItoMS.h:288
Vector< String > itsMSKC
Definition: FitsIDItoMS.h:276
Vector< Bool > itsgotMSK
Definition: FitsIDItoMS.h:279
static std::map< Int, Int > antIdFromNo
Definition: FitsIDItoMS.h:316
fixed-length sequential blocked FITS input
Definition: fitsio.h:156
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition: MFrequency.h:176
String: the storage and methods of handling collections of characters.
Definition: String.h:225
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
unsigned int uInt
Definition: aipstype.h:51
float Float
Definition: aipstype.h:54
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55