casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef MS_MSFITSINPUT_H
27#define MS_MSFITSINPUT_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/Matrix.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/casa/Containers/Block.h>
33#include <casacore/casa/Containers/Record.h>
34#include <casacore/fits/FITS/fits.h>
35#include <casacore/fits/FITS/hdu.h>
36#include <casacore/casa/Logging/LogIO.h>
37#include <casacore/ms/MeasurementSets/MeasurementSet.h>
38#include <casacore/measures/Measures/MDirection.h>
39#include <casacore/measures/Measures/MFrequency.h>
40#include <casacore/casa/BasicSL/String.h>
41#include <casacore/ms/MeasurementSets/MSTileLayout.h>
42#include <casacore/tables/Tables/BaseTable.h>
43
44namespace casacore { //# NAMESPACE CASACORE - BEGIN
45
46class FitsInput;
47class BinaryTable;
48class MSColumns;
49template <class T> class ScalarColumn;
50
51// <summary>
52// A helper class for MSFitsInput
53// </summary>
54// <use visibility=local>
55// <etymology>
56// This class can hold a primary array of several datatypes
57// </etymology>
58// <synopsis>
59// This is a helper class to avoid cumbersome switch statements on the
60// template type of the primary array
61// It forwards all the PrimaryArray member functions we need in the filler.
62// </synopsis>
64{
65 // This is a helper class to avoid cumbersome switch statements on the
66 // template type of the primary array
67 // It forwards all the PrimaryTable member function we need in the filler.
68public:
69 // Construct an empty holder, used to attach to later
71
72 // Construct from an input file containing a FITS primary group hdu.
73 // Throws an exception if the datatype is not Short, FitsLong or Float
75
77
78 // Attach to the input file, create the appropriate PrimaryArray.
79 // Throws an exception if the datatype is not Short, FitsLong or Float
80 void attach(FitsInput& infile);
81
82 // Detach from the input file
83 void detach();
84
85 //# forwarding functions
86
87 // Number of dimensions
89 {return hdu_p->dims();}
90
91 // Length of i'th axis
93 {return hdu_p->dim(i);}
94
95 // Coordinate type
97 { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i));}
98
99 // Coordinate reference value
101 { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i));}
102
103 // Coordinate reference pixel
105 { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i));}
106
107 // Coordinate delta
109 { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i));}
110
111 // Keyword of given type
113 { return hdu_p->kw(n);}
114
115 // All keywords
118
119 // Advance to next keyword
121 { return hdu_p->nextkw();}
122
123 // Read the next group
125 if (pf) return pf->read();
126 else if (pl) return pl->read();
127 else if (ps) return ps->read();
128 else if (pb) return pb->read();
129 else cout << "can not read the table" << endl;
130 return 0;
131 }
132
133private:
139};
140
141// <summary>
142// A helper class for MSFitsInput
143// </summary>
144// <use visibility=local>
145// <etymology>
146// This class can hold a primary group of several datatypes
147// </etymology>
148// <synopsis>
149// This is a helper class to avoid cumbersome switch statements on the
150// template type of the primary group
151// It forwards all the PrimaryGroup member functions we need in the filler.
152// </synopsis>
154{
155 // This is a helper class to avoid cumbersome switch statements on the
156 // template type of the primary group
157 // It forwards all the PrimaryGroup member function we need in the filler.
158public:
159 // Construct an empty holder, used to attach to later
161
162 // Construct from an input file containing a FITS primary group hdu.
163 // Throws an exception if the datatype is not Short, FitsLong or Float
165
167
168 // Attach to the input file, create the appropriate PrimaryGroup.
169 // Throws an exception if the datatype is not Short, FitsLong or Float
170 void attach(FitsInput& infile);
171
172 // Detach from the input file
173 void detach();
174
175 //# forwarding functions
176
177 // Number of dimensions
179 {return hdu_p->dims();}
180
181 // Length of i'th axis
183 {return hdu_p->dim(i);}
184
185 // Coordinate type
187 { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i));}
188
189 // Coordinate reference value
191 { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i));}
192
193 // Coordinate reference pixel
195 { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i));}
196
197 // Coordinate delta
199 { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i));}
200
201 // Keyword of given type
203 { return hdu_p->kw(n);}
204
205 // All keywords
208
209 // Advance to next keyword
211 { return hdu_p->nextkw();}
212
213 // Number of groups
214 Int gcount() const
215 { return pf ? pf->gcount() : ( pl ? pl->gcount() : ps->gcount());}
216
217 // Number of parameters
218 Int pcount() const
219 { return pf ? pf->pcount() : ( pl ? pl->pcount() : ps->pcount());}
220
221 // Parameter type
222 Char* ptype(Int i) const
223 { return pf ? pf->ptype(i) : ( pl ? pl->ptype(i) : ps->ptype(i));}
224
225 // Read the next group
227 { return pf ? pf->read() : ( pl ? pl->read() : ps->read());}
228
229 // Get i'th parameter
231 { return pf ? pf->parm(i) : ( pl ? pl->parm(i) : ps->parm(i));}
232
233 // Get group data with index i, scaled and converted to Double
235 { return pf ? (*pf)(i) : ( pl ? (*pl)(i) : (*ps)(i));}
236
237private:
242};
243
244// <summary>
245// UV FITS to MeasurementSet filler
246// </summary>
247
248// <use visibility=export>
249
250// <prerequisite>
251// <li> MeasurementSet
252// <li> FITS classes
253// </prerequisite>
254//
255// <etymology>
256// MSFitsInput handles the conversion of FITS files to MeasurementSets
257// </etymology>
258//
259// <synopsis>
260// UV FITS to MeasurementSet filler. This can handle single source fits and
261// multi source fits as written by classic AIPS. Also copes with multiple
262// arrays (i.e. multiple AN tables) but doesn't correct for 5 day offsets
263// introduced by DBCON.
264// </synopsis>
265
267{
268 // This is an implementation helper class used to store 'local' data
269 // during the filling process.
270public:
271 MSFitsInput() = delete;
272
273 // Create from output and input file names. This function opens the input
274 // file, and checks the output file is writable.
275 MSFitsInput(const String& msFile, const String& fitsFile, const Bool NewNameStyle=False);
276
277 MSFitsInput(const MSFitsInput& other) = delete;
278
279 // The destructor is fairly trivial.
281
282 MSFitsInput& operator=(const MSFitsInput& other) = delete;
283
284 // Read all the data from the FITS file and create the MeasurementSet. Throws
285 // an exception when it has severe trouble interpreting the FITS file.
286 //
288
289private:
304 MDirection::Types _epochRef; // This is a direction measure reference code
305 // determined by epoch_p, hence the name and type.
306 // unique antennas found in the visibility data
307 // NOTE These are 1-based
308 std::set<Int> _uniqueAnts;
309 // number of rows in the created MS ANTENNA table
314 Double _restfreq; // used for images
323
324 Matrix<Double> _restFreq; // used for UVFITS
327
328 // Check that the input is a UV fits file with required contents.
329 // Returns False if not ok.
331
332 // Read the axis info of the primary group, throws an exception if required
333 // axes are missing.
335
336 // Set up the MeasurementSet, including StorageManagers and fixed columns.
337 // If useTSM is True, the Tiled Storage Manager will be used to store
338 // DATA, FLAG and WEIGHT_SPECTRUM. Use obsType to choose the tiling
339 // scheme.
340 void setupMeasurementSet(const String& MSFileName, Bool useTSM=True,
341 Int obsType = MSTileLayout::Standard);
342
344 // Read a binary table extension of type AIPS AN and create an antenna table
346
347 // Read a binary table extension and update history table
349
350 // Read a binary table extension and update history table
352
353 //extract axis information
355
356 //extract axis information
358
360
361 //verify that the fits contains visibility data
363
365
366 // fill Field table
368 void fillFieldTable(double, double, String);
369
371
373
375
376 // fill the Feed table with minimal info needed for synthesis processing
378
380 // Fill the Observation and ObsLog tables
382
383 // Fill the main table from the Primary group data
384 // if we have enough memory try to do it in mem
385 void fillMSMainTableColWise(Int& nField, Int& nSpW);
386 //else do it row by row
387 void fillMSMainTable(Int& nField, Int& nSpW);
388
389 // fill spectralwindow table from FITS FQ table + header info
391
392 // fill spectralwindow table from header
394
395 // fill Field table from FITS SU table
396 void fillFieldTable(BinaryTable& bt, Int nField);
397
398 // fill Field table from header (single source fits)
399 void fillFieldTable(Int nField);
400
401 // fill the Pointing table (from Field table, all antennas are assumed
402 // to point in the field direction) and possibly the Source table.
404
405 // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
406 // in the (last) AN table
408
409 // Returns the Direction Measure reference for UVW and other appropriate columns
410 // in msc_p (which must exist but have empty columns before you can set it!).
412
413 // Check the frame if there is an SU table
415
416 // update a the Spectral window post filling if necessary
418
421
422 std::pair<Int, Int> _extractAntennas(Int antenna1, Int antenna2);
423 std::pair<Int, Int> _extractAntennas(Float baseline);
424
426
428 const String& casaTableName, const ScalarColumn<Double>& timeCol,
429 const ScalarColumn<Float>& intervalCol,
430 const ScalarColumn<Int>& antNoCol, const ScalarColumn<Int>& freqIDCol,
431 const ScalarColumn<Float>& powerDif1Col,
432 const ScalarColumn<Float>& powerSum1Col,
433 const ScalarColumn<Float>& postGain1Col,
434 const ScalarColumn<Float>& powerDif2Col,
435 const ScalarColumn<Float>& powerSum2Col,
436 const ScalarColumn<Float>& postGain2Col
437 );
438
439};
440
441
442} //# NAMESPACE CASACORE - END
443
444#endif
simple 1-D array
Definition Block.h:198
list of read-only FITS keywords
Definition fits.h:949
ReservedName
FITS Reserved Names.
Definition fits.h:236
fixed-length sequential blocked FITS input
Definition fitsio.h:154
FITS keyword.
Definition fits.h:513
const FitsKeyword * kw(int n)
Definition hdu.h:127
ConstFitsKeywordList & kwlist()
Operations on the HDU's keyword list.
Definition hdu.h:118
Int dims() const
Definition hdu.h:74
Int dim(int n) const
Definition hdu.h:75
const FitsKeyword * nextkw()
Definition hdu.h:124
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition MDirection.h:185
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition MFrequency.h:173
UV FITS to MeasurementSet filler.
MDirection::Types _epochRef
Vector< String > _coordType
Vector< Double > _refPix
std::set< Int > _uniqueAnts
determined by epoch_p, hence the name and type.
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
void readFitsFile(Int obsType=MSTileLayout::Standard)
Read all the data from the FITS file and create the MeasurementSet.
Matrix< Int > _corrProduct
void fillMSMainTable(Int &nField, Int &nSpW)
else do it row by row
MeasurementSet _ms
void fillSpectralWindowTable(BinaryTable &bt, Int nSpW)
fill spectralwindow table from FITS FQ table + header info
MSPrimaryTableHolder _priTable
MSFitsInput & operator=(const MSFitsInput &other)=delete
Vector< Int > _nPixel
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
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
void fillSpectralWindowTable()
fill spectralwindow table from header
Matrix< Double > _sysVel
MSFitsInput(const MSFitsInput &other)=delete
void getAxisInfo(ConstFitsKeywordList &)
extract axis information
Vector< Double > _chanFreq
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
void fillMSMainTable(BinaryTable &bt)
Vector< Double > _receptorAngle
Vector< Double > _refVal
Matrix< Double > _restFreq
void fillFieldTable(Int nField)
fill Field table from header (single source fits)
Vector< Double > _delta
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
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
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.
PrimaryGroup< Float > * pf
Int gcount() const
Number of groups.
Char * ctype(Int i)
Coordinate type.
MSPrimaryGroupHolder(FitsInput &infile)
Construct from an input file containing a FITS primary group hdu.
ConstFitsKeywordList & kwlist()
All keywords.
void detach()
Detach from the input file.
Double crval(Int i)
Coordinate reference value.
Int dim(Int i)
Length of i'th axis.
Double operator()(Int i) const
Get group data with index i, scaled and converted to Double.
Double crpix(Int i)
Coordinate reference pixel.
Char * ptype(Int i) const
Parameter type.
Int pcount() const
Number of parameters.
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
const FitsKeyword * nextkw()
Advance to next keyword.
Int dims()
Number of dimensions.
Double cdelt(Int i)
Coordinate delta.
PrimaryGroup< FitsLong > * pl
PrimaryGroup< Short > * ps
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.
void attach(FitsInput &infile)
Attach to the input file, create the appropriate PrimaryGroup.
Double parm(Int i)
Get i'th parameter.
PrimaryTable< Float > * pf
Int read()
Read the next group.
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
const FitsKeyword * nextkw()
Advance to next keyword.
PrimaryTable< FitsLong > * pl
PrimaryTable< uChar > * pb
Int dim(Int i)
Length of i'th axis.
Definition MSFitsInput.h:92
Char * ctype(Int i)
Coordinate type.
Definition MSFitsInput.h:96
Int dims()
Number of dimensions.
Definition MSFitsInput.h:88
ConstFitsKeywordList & kwlist()
All keywords.
void detach()
Detach from the input file.
Double crpix(Int i)
Coordinate reference pixel.
PrimaryTable< Short > * ps
void attach(FitsInput &infile)
Attach to the input file, create the appropriate PrimaryArray.
Double cdelt(Int i)
Coordinate delta.
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.
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)
double cdelt(int n) const
Definition hdu.h:364
double crpix(int n) const
Definition hdu.h:361
double crval(int n) const
Definition hdu.h:363
char * ctype(int n) const
Definition hdu.h:360
Random Group datastructure.
Definition hdu.h:592
Int pcount() const
Definition hdu.h:606
int read()
read, or write the next group
Int gcount() const
Return basic parameters of a random group.
Definition hdu.h:605
char * ptype(int n) const
Definition hdu.h:607
Primary Table structure.
Definition hdu.h:704
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:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44