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