casacore
MSFitsInput.h
Go to the documentation of this file.
1//# MSFitsInput: simple uvfits (random group) to MeasurementSet conversion
2//# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This program is free software; you can redistribute it and/or modify
6//# it under the terms of the GNU General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or
8//# (at your option) any later version.
9//#
10//# This program is distributed in the hope that it will be useful,
11//# but WITHOUT ANY WARRANTY; without even the implied warranty of
12//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13//# GNU General Public License for more details.
14//#
15//# You should have received a copy of the GNU General Public License
16//# along with this program; if not, write to the Free Software
17//# Foundation, Inc., 675 Mass 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: MSFitsInput.h 21531 2014-12-24 11:46:02Z gervandiepen $
27
28#ifndef MS_MSFITSINPUT_H
29#define MS_MSFITSINPUT_H
30
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/Matrix.h>
33#include <casacore/casa/Arrays/Vector.h>
34#include <casacore/casa/Containers/Block.h>
35#include <casacore/casa/Containers/Record.h>
36#include <casacore/fits/FITS/fits.h>
37#include <casacore/fits/FITS/hdu.h>
38#include <casacore/casa/Logging/LogIO.h>
39#include <casacore/ms/MeasurementSets/MeasurementSet.h>
40#include <casacore/measures/Measures/MDirection.h>
41#include <casacore/measures/Measures/MFrequency.h>
42#include <casacore/casa/BasicSL/String.h>
43#include <casacore/ms/MeasurementSets/MSTileLayout.h>
44#include <casacore/tables/Tables/BaseTable.h>
45
46namespace casacore { //# NAMESPACE CASACORE - BEGIN
47
48class FitsInput;
49class BinaryTable;
50class MSColumns;
51template <class T> class ScalarColumn;
52
53// <summary>
54// A helper class for MSFitsInput
55// </summary>
56// <use visibility=local>
57// <etymology>
58// This class can hold a primary array of several datatypes
59// </etymology>
60// <synopsis>
61// This is a helper class to avoid cumbersome switch statements on the
62// template type of the primary array
63// It forwards all the PrimaryArray member functions we need in the filler.
64// </synopsis>
66{
67 // This is a helper class to avoid cumbersome switch statements on the
68 // template type of the primary array
69 // It forwards all the PrimaryTable member function we need in the filler.
70public:
71 // Construct an empty holder, used to attach to later
73
74 // Construct from an input file containing a FITS primary group hdu.
75 // Throws an exception if the datatype is not Short, FitsLong or Float
77
79
80 // Attach to the input file, create the appropriate PrimaryArray.
81 // Throws an exception if the datatype is not Short, FitsLong or Float
82 void attach(FitsInput& infile);
83
84 // Detach from the input file
85 void detach();
86
87 //# forwarding functions
88
89 // Number of dimensions
91 {return hdu_p->dims();}
92
93 // Length of i'th axis
95 {return hdu_p->dim(i);}
96
97 // Coordinate type
99 { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i));}
100
101 // Coordinate reference value
103 { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i));}
104
105 // Coordinate reference pixel
107 { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i));}
108
109 // Coordinate delta
111 { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i));}
112
113 // Keyword of given type
115 { return hdu_p->kw(n);}
116
117 // All keywords
119 { return hdu_p->kwlist();}
120
121 // Advance to next keyword
123 { return hdu_p->nextkw();}
124
125 // Read the next group
127 if (pf) return pf->read();
128 else if (pl) return pl->read();
129 else if (ps) return ps->read();
130 else if (pb) return pb->read();
131 else cout << "can not read the table" << endl;
132 return 0;
133 }
134
135private:
141};
142
143// <summary>
144// A helper class for MSFitsInput
145// </summary>
146// <use visibility=local>
147// <etymology>
148// This class can hold a primary group of several datatypes
149// </etymology>
150// <synopsis>
151// This is a helper class to avoid cumbersome switch statements on the
152// template type of the primary group
153// It forwards all the PrimaryGroup member functions we need in the filler.
154// </synopsis>
156{
157 // This is a helper class to avoid cumbersome switch statements on the
158 // template type of the primary group
159 // It forwards all the PrimaryGroup member function we need in the filler.
160public:
161 // Construct an empty holder, used to attach to later
163
164 // Construct from an input file containing a FITS primary group hdu.
165 // Throws an exception if the datatype is not Short, FitsLong or Float
167
169
170 // Attach to the input file, create the appropriate PrimaryGroup.
171 // Throws an exception if the datatype is not Short, FitsLong or Float
172 void attach(FitsInput& infile);
173
174 // Detach from the input file
175 void detach();
176
177 //# forwarding functions
178
179 // Number of dimensions
181 {return hdu_p->dims();}
182
183 // Length of i'th axis
185 {return hdu_p->dim(i);}
186
187 // Coordinate type
189 { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i));}
190
191 // Coordinate reference value
193 { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i));}
194
195 // Coordinate reference pixel
197 { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i));}
198
199 // Coordinate delta
201 { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i));}
202
203 // Keyword of given type
205 { return hdu_p->kw(n);}
206
207 // All keywords
209 { return hdu_p->kwlist();}
210
211 // Advance to next keyword
213 { return hdu_p->nextkw();}
214
215 // Number of groups
216 Int gcount() const
217 { return pf ? pf->gcount() : ( pl ? pl->gcount() : ps->gcount());}
218
219 // Number of parameters
220 Int pcount() const
221 { return pf ? pf->pcount() : ( pl ? pl->pcount() : ps->pcount());}
222
223 // Parameter type
224 Char* ptype(Int i) const
225 { return pf ? pf->ptype(i) : ( pl ? pl->ptype(i) : ps->ptype(i));}
226
227 // Read the next group
229 { return pf ? pf->read() : ( pl ? pl->read() : ps->read());}
230
231 // Get i'th parameter
233 { return pf ? pf->parm(i) : ( pl ? pl->parm(i) : ps->parm(i));}
234
235 // Get group data with index i, scaled and converted to Double
237 { return pf ? (*pf)(i) : ( pl ? (*pl)(i) : (*ps)(i));}
238
239private:
244};
245
246// <summary>
247// UV FITS to MeasurementSet filler
248// </summary>
249
250// <use visibility=export>
251
252// <prerequisite>
253// <li> MeasurementSet
254// <li> FITS classes
255// </prerequisite>
256//
257// <etymology>
258// MSFitsInput handles the conversion of FITS files to MeasurementSets
259// </etymology>
260//
261// <synopsis>
262// UV FITS to MeasurementSet filler. This can handle single source fits and
263// multi source fits as written by classic AIPS. Also copes with multiple
264// arrays (i.e. multiple AN tables) but doesn't correct for 5 day offsets
265// introduced by DBCON.
266// </synopsis>
267
269{
270 // This is an implementation helper class used to store 'local' data
271 // during the filling process.
272public:
273 MSFitsInput() = delete;
274
275 // Create from output and input file names. This function opens the input
276 // file, and checks the output file is writable.
277 MSFitsInput(const String& msFile, const String& fitsFile, const Bool NewNameStyle=False);
278
279 MSFitsInput(const MSFitsInput& other) = delete;
280
281 // The destructor is fairly trivial.
283
284 MSFitsInput& operator=(const MSFitsInput& other) = delete;
285
286 // Read all the data from the FITS file and create the MeasurementSet. Throws
287 // an exception when it has severe trouble interpreting the FITS file.
288 //
290
291private:
306 MDirection::Types _epochRef; // This is a direction measure reference code
307 // determined by epoch_p, hence the name and type.
308 // unique antennas found in the visibility data
309 // NOTE These are 1-based
310 std::set<Int> _uniqueAnts;
311 // number of rows in the created MS ANTENNA table
316 Double _restfreq; // used for images
325
326 Matrix<Double> _restFreq; // used for UVFITS
329
330 // Check that the input is a UV fits file with required contents.
331 // Returns False if not ok.
333
334 // Read the axis info of the primary group, throws an exception if required
335 // axes are missing.
337
338 // Set up the MeasurementSet, including StorageManagers and fixed columns.
339 // If useTSM is True, the Tiled Storage Manager will be used to store
340 // DATA, FLAG and WEIGHT_SPECTRUM. Use obsType to choose the tiling
341 // scheme.
342 void setupMeasurementSet(const String& MSFileName, Bool useTSM=True,
343 Int obsType = MSTileLayout::Standard);
344
346 // Read a binary table extension of type AIPS AN and create an antenna table
348
349 // Read a binary table extension and update history table
351
352 // Read a binary table extension and update history table
354
355 //extract axis information
357
358 //extract axis information
360
362
363 //verify that the fits contains visibility data
365
367
368 // fill Field table
370 void fillFieldTable(double, double, String);
371
373
375
377
378 // fill the Feed table with minimal info needed for synthesis processing
380
382 // Fill the Observation and ObsLog tables
384
385 // Fill the main table from the Primary group data
386 // if we have enough memory try to do it in mem
387 void fillMSMainTableColWise(Int& nField, Int& nSpW);
388 //else do it row by row
389 void fillMSMainTable(Int& nField, Int& nSpW);
390
391 // fill spectralwindow table from FITS FQ table + header info
393
394 // fill spectralwindow table from header
396
397 // fill Field table from FITS SU table
398 void fillFieldTable(BinaryTable& bt, Int nField);
399
400 // fill Field table from header (single source fits)
401 void fillFieldTable(Int nField);
402
403 // fill the Pointing table (from Field table, all antennas are assumed
404 // to point in the field direction) and possibly the Source table.
406
407 // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
408 // in the (last) AN table
410
411 // Returns the Direction Measure reference for UVW and other appropriate columns
412 // in msc_p (which must exist but have empty columns before you can set it!).
414
415 // Check the frame if there is an SU table
417
418 // update a the Spectral window post filling if necessary
420
423
424 std::pair<Int, Int> _extractAntennas(Int antenna1, Int antenna2);
425 std::pair<Int, Int> _extractAntennas(Float baseline);
426
428
430 const String& casaTableName, const ScalarColumn<Double>& timeCol,
431 const ScalarColumn<Float>& intervalCol,
432 const ScalarColumn<Int>& antNoCol, const ScalarColumn<Int>& freqIDCol,
433 const ScalarColumn<Float>& powerDif1Col,
434 const ScalarColumn<Float>& powerSum1Col,
435 const ScalarColumn<Float>& postGain1Col,
436 const ScalarColumn<Float>& powerDif2Col,
437 const ScalarColumn<Float>& powerSum2Col,
438 const ScalarColumn<Float>& postGain2Col
439 );
440
441};
442
443
444} //# NAMESPACE CASACORE - END
445
446#endif
list of read-only FITS keywords
Definition: fits.h:951
ReservedName
FITS Reserved Names.
Definition: fits.h:238
fixed-length sequential blocked FITS input
Definition: fitsio.h:156
FITS keyword.
Definition: fits.h:515
const FitsKeyword * kw(int n)
Definition: hdu.h:129
ConstFitsKeywordList & kwlist()
Operations on the HDU's keyword list.
Definition: hdu.h:120
Int dims() const
Definition: hdu.h:76
Int dim(int n) const
Definition: hdu.h:77
const FitsKeyword * nextkw()
Definition: hdu.h:126
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition: MFrequency.h:176
UV FITS to MeasurementSet filler.
Definition: MSFitsInput.h:269
MDirection::Types _epochRef
Definition: MSFitsInput.h:306
Vector< String > _coordType
Definition: MSFitsInput.h:302
Vector< Double > _refPix
Definition: MSFitsInput.h:303
std::set< Int > _uniqueAnts
determined by epoch_p, hence the name and type.
Definition: MSFitsInput.h:310
std::pair< Int, Int > _extractAntennas(Float baseline)
void fixEpochReferences()
fix up the EPOCH MEASURE_REFERENCE keywords using the value found in the (last) AN table
void readPrimaryTableUVFits(Int obsType)
Int _nAntRow
number of rows in the created MS ANTENNA table
Definition: MSFitsInput.h:312
void readFitsFile(Int obsType=MSTileLayout::Standard)
Read all the data from the FITS file and create the MeasurementSet.
Matrix< Int > _corrProduct
Definition: MSFitsInput.h:301
void fillMSMainTable(Int &nField, Int &nSpW)
else do it row by row
MeasurementSet _ms
Definition: MSFitsInput.h:296
void fillSpectralWindowTable(BinaryTable &bt, Int nSpW)
fill spectralwindow table from FITS FQ table + header info
MSPrimaryTableHolder _priTable
Definition: MSFitsInput.h:295
MSFitsInput & operator=(const MSFitsInput &other)=delete
Vector< Int > _nPixel
Definition: MSFitsInput.h:299
void _doFillSysPowerSingleIF(const String &casaTableName, const ScalarColumn< Double > &timeCol, const ScalarColumn< Float > &intervalCol, const ScalarColumn< Int > &antNoCol, const ScalarColumn< Int > &freqIDCol, const ScalarColumn< Float > &powerDif1Col, const ScalarColumn< Float > &powerSum1Col, const ScalarColumn< Float > &postGain1Col, const ScalarColumn< Float > &powerDif2Col, const ScalarColumn< Float > &powerSum2Col, const ScalarColumn< Float > &postGain2Col)
std::pair< Int, Int > _extractAntennas(Int antenna1, Int antenna2)
void readRandomGroupUVFits(Int obsType)
MSPrimaryGroupHolder _priGroup
Definition: MSFitsInput.h:294
MSFitsInput(const String &msFile, const String &fitsFile, const Bool NewNameStyle=False)
Create from output and input file names.
Fill the Observation and ObsLog tables *void fillObsTables()
void fillObservationTable(ConstFitsKeywordList &kwl)
Read a binary table extension and update history table.
Vector< Double > _obsTime
Definition: MSFitsInput.h:324
void fillSpectralWindowTable()
fill spectralwindow table from header
Matrix< Double > _sysVel
Definition: MSFitsInput.h:327
MSFitsInput(const MSFitsInput &other)=delete
void getAxisInfo(ConstFitsKeywordList &)
extract axis information
Vector< Double > _chanFreq
Definition: MSFitsInput.h:322
void fillHistoryTable(ConstFitsKeywordList &kwl)
Read a binary table extension and update history table.
void getPrimaryGroupAxisInfo()
Read the axis info of the primary group, throws an exception if required axes are missing.
void updateSpectralWindowTable()
update a the Spectral window post filling if necessary
Read a binary table extension of type AIPS AN and create an antenna table *void fillAntennaTable(BinaryTable &bt)
void fillExtraTables()
fill the Pointing table (from Field table, all antennas are assumed to point in the field direction) ...
void sortPolarizations()
extract axis information
void setupMeasurementSet(const String &MSFileName, Bool useTSM=True, Int obsType=MSTileLayout::Standard)
Set up the MeasurementSet, including StorageManagers and fixed columns.
Vector< Int > _corrType
Definition: MSFitsInput.h:299
void fillMSMainTable(BinaryTable &bt)
Vector< Double > _receptorAngle
Definition: MSFitsInput.h:314
Vector< Double > _refVal
Definition: MSFitsInput.h:303
Matrix< Double > _restFreq
Definition: MSFitsInput.h:326
void fillFieldTable(Int nField)
fill Field table from header (single source fits)
Vector< Double > _delta
Definition: MSFitsInput.h:303
void checkRequiredAxis()
verify that the fits contains visibility data
MDirection::Types getDirectionFrame(Double epoch)
Returns the Direction Measure reference for UVW and other appropriate columns in msc_p (which must ex...
void fillFieldTable(BinaryTable &bt, Int nField)
fill Field table from FITS SU table
void fillFeedTable()
fill the Feed table with minimal info needed for synthesis processing
void _fillSysPowerTable(BinaryTable &bt)
void fillSpectralWindowTable(BinaryTable &bt)
~MSFitsInput()
The destructor is fairly trivial.
Bool _checkInput(FitsInput &infile)
Check that the input is a UV fits file with required contents.
MFrequency::Types _freqsys
Definition: MSFitsInput.h:315
void fillFieldTable(BinaryTable &bt)
fill Field table
void fillFieldTable(double, double, String)
MSFitsInput()=delete
This is an implementation helper class used to store 'local' data during the filling process.
Block< Int > _corrIndex
Definition: MSFitsInput.h:300
void fillMSMainTableColWise(Int &nField, Int &nSpW)
Fill the main table from the Primary group data if we have enough memory try to do it in mem.
void setFreqFrameVar(BinaryTable &binTab)
Check the frame if there is an SU table.
A helper class for MSFitsInput.
Definition: MSFitsInput.h:156
PrimaryGroup< Float > * pf
Definition: MSFitsInput.h:243
Int gcount() const
Number of groups.
Definition: MSFitsInput.h:216
Char * ctype(Int i)
Coordinate type.
Definition: MSFitsInput.h:188
MSPrimaryGroupHolder(FitsInput &infile)
Construct from an input file containing a FITS primary group hdu.
ConstFitsKeywordList & kwlist()
All keywords.
Definition: MSFitsInput.h:208
void detach()
Detach from the input file.
Double crval(Int i)
Coordinate reference value.
Definition: MSFitsInput.h:192
Int dim(Int i)
Length of i'th axis.
Definition: MSFitsInput.h:184
Double operator()(Int i) const
Get group data with index i, scaled and converted to Double.
Definition: MSFitsInput.h:236
Double crpix(Int i)
Coordinate reference pixel.
Definition: MSFitsInput.h:196
Char * ptype(Int i) const
Parameter type.
Definition: MSFitsInput.h:224
Int pcount() const
Number of parameters.
Definition: MSFitsInput.h:220
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
Definition: MSFitsInput.h:204
const FitsKeyword * nextkw()
Advance to next keyword.
Definition: MSFitsInput.h:212
Int dims()
Number of dimensions.
Definition: MSFitsInput.h:180
Double cdelt(Int i)
Coordinate delta.
Definition: MSFitsInput.h:200
PrimaryGroup< FitsLong > * pl
Definition: MSFitsInput.h:242
PrimaryGroup< Short > * ps
Definition: MSFitsInput.h:241
MSPrimaryGroupHolder()
This is a helper class to avoid cumbersome switch statements on the template type of the primary grou...
Int read()
Read the next group.
Definition: MSFitsInput.h:228
void attach(FitsInput &infile)
Attach to the input file, create the appropriate PrimaryGroup.
Double parm(Int i)
Get i'th parameter.
Definition: MSFitsInput.h:232
PrimaryTable< Float > * pf
Definition: MSFitsInput.h:139
Int read()
Read the next group.
Definition: MSFitsInput.h:126
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
Definition: MSFitsInput.h:114
const FitsKeyword * nextkw()
Advance to next keyword.
Definition: MSFitsInput.h:122
PrimaryTable< FitsLong > * pl
Definition: MSFitsInput.h:138
PrimaryTable< uChar > * pb
Definition: MSFitsInput.h:140
Int dim(Int i)
Length of i'th axis.
Definition: MSFitsInput.h:94
Char * ctype(Int i)
Coordinate type.
Definition: MSFitsInput.h:98
Int dims()
Number of dimensions.
Definition: MSFitsInput.h:90
ConstFitsKeywordList & kwlist()
All keywords.
Definition: MSFitsInput.h:118
void detach()
Detach from the input file.
Double crpix(Int i)
Coordinate reference pixel.
Definition: MSFitsInput.h:106
PrimaryTable< Short > * ps
Definition: MSFitsInput.h:137
void attach(FitsInput &infile)
Attach to the input file, create the appropriate PrimaryArray.
Double cdelt(Int i)
Coordinate delta.
Definition: MSFitsInput.h:110
MSPrimaryTableHolder()
This is a helper class to avoid cumbersome switch statements on the template type of the primary arra...
Double crval(Int i)
Coordinate reference value.
Definition: MSFitsInput.h:102
MSPrimaryTableHolder(FitsInput &infile)
Construct from an input file containing a FITS primary group hdu.
@ Standard
Standard, optimizes i/o by using large tiles (128 kB)
Definition: MSTileLayout.h:87
double cdelt(int n) const
Definition: hdu.h:366
double crpix(int n) const
Definition: hdu.h:363
double crval(int n) const
Definition: hdu.h:365
char * ctype(int n) const
Definition: hdu.h:362
Int pcount() const
Definition: hdu.h:608
int read()
read, or write the next group
Int gcount() const
Return basic parameters of a random group.
Definition: hdu.h:607
char * ptype(int n) const
Definition: hdu.h:609
int read()
The ‘read()’ and ‘write()’ functions control reading and writing data from the external FITS I/O medi...
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
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
char Char
Definition: aipstype.h:46