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>
50class ScalarColumn;
51
52// <summary>
53// A helper class for MSFitsInput
54// </summary>
55// <use visibility=local>
56// <etymology>
57// This class can hold a primary array of several datatypes
58// </etymology>
59// <synopsis>
60// This is a helper class to avoid cumbersome switch statements on the
61// template type of the primary array
62// It forwards all the PrimaryArray member functions we need in the filler.
63// </synopsis>
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.
68 public:
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
88 Int dims() { return hdu_p->dims(); }
89
90 // Length of i'th axis
91 Int dim(Int i) { return hdu_p->dim(i); }
92
93 // Coordinate type
94 Char* ctype(Int i) { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i)); }
95
96 // Coordinate reference value
97 Double crval(Int i) { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i)); }
98
99 // Coordinate reference pixel
100 Double crpix(Int i) { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i)); }
101
102 // Coordinate delta
103 Double cdelt(Int i) { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i)); }
104
105 // Keyword of given type
106 const FitsKeyword* kw(const FITS::ReservedName& n) { return hdu_p->kw(n); }
107
108 // All keywords
109 ConstFitsKeywordList& kwlist() { return hdu_p->kwlist(); }
110
111 // Advance to next keyword
112 const FitsKeyword* nextkw() { return hdu_p->nextkw(); }
113
114 // Read the next group
116 if (pf)
117 return pf->read();
118 else if (pl)
119 return pl->read();
120 else if (ps)
121 return ps->read();
122 else if (pb)
123 return pb->read();
124 else
125 cout << "can not read the table" << endl;
126 return 0;
127 }
128
129 private:
135};
136
137// <summary>
138// A helper class for MSFitsInput
139// </summary>
140// <use visibility=local>
141// <etymology>
142// This class can hold a primary group of several datatypes
143// </etymology>
144// <synopsis>
145// This is a helper class to avoid cumbersome switch statements on the
146// template type of the primary group
147// It forwards all the PrimaryGroup member functions we need in the filler.
148// </synopsis>
150 // This is a helper class to avoid cumbersome switch statements on the
151 // template type of the primary group
152 // It forwards all the PrimaryGroup member function we need in the filler.
153 public:
154 // Construct an empty holder, used to attach to later
156
157 // Construct from an input file containing a FITS primary group hdu.
158 // Throws an exception if the datatype is not Short, FitsLong or Float
160
162
163 // Attach to the input file, create the appropriate PrimaryGroup.
164 // Throws an exception if the datatype is not Short, FitsLong or Float
165 void attach(FitsInput& infile);
166
167 // Detach from the input file
168 void detach();
169
170 // # forwarding functions
171
172 // Number of dimensions
173 Int dims() { return hdu_p->dims(); }
174
175 // Length of i'th axis
176 Int dim(Int i) { return hdu_p->dim(i); }
177
178 // Coordinate type
179 Char* ctype(Int i) { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i)); }
180
181 // Coordinate reference value
182 Double crval(Int i) { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i)); }
183
184 // Coordinate reference pixel
185 Double crpix(Int i) { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i)); }
186
187 // Coordinate delta
188 Double cdelt(Int i) { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i)); }
189
190 // Keyword of given type
191 const FitsKeyword* kw(const FITS::ReservedName& n) { return hdu_p->kw(n); }
192
193 // All keywords
194 ConstFitsKeywordList& kwlist() { return hdu_p->kwlist(); }
195
196 // Advance to next keyword
197 const FitsKeyword* nextkw() { return hdu_p->nextkw(); }
198
199 // Number of groups
200 Int gcount() const { return pf ? pf->gcount() : (pl ? pl->gcount() : ps->gcount()); }
201
202 // Number of parameters
203 Int pcount() const { return pf ? pf->pcount() : (pl ? pl->pcount() : ps->pcount()); }
204
205 // Parameter type
206 Char* ptype(Int i) const { return pf ? pf->ptype(i) : (pl ? pl->ptype(i) : ps->ptype(i)); }
207
208 // Read the next group
209 Int read() { return pf ? pf->read() : (pl ? pl->read() : ps->read()); }
210
211 // Get i'th parameter
212 Double parm(Int i) { return pf ? pf->parm(i) : (pl ? pl->parm(i) : ps->parm(i)); }
213
214 // Get group data with index i, scaled and converted to Double
215 Double operator()(Int i) const { return pf ? (*pf)(i) : (pl ? (*pl)(i) : (*ps)(i)); }
216
217 private:
222};
223
224// <summary>
225// UV FITS to MeasurementSet filler
226// </summary>
227
228// <use visibility=export>
229
230// <prerequisite>
231// <li> MeasurementSet
232// <li> FITS classes
233// </prerequisite>
234//
235// <etymology>
236// MSFitsInput handles the conversion of FITS files to MeasurementSets
237// </etymology>
238//
239// <synopsis>
240// UV FITS to MeasurementSet filler. This can handle single source fits and
241// multi source fits as written by classic AIPS. Also copes with multiple
242// arrays (i.e. multiple AN tables) but doesn't correct for 5 day offsets
243// introduced by DBCON.
244// </synopsis>
245
247 // This is an implementation helper class used to store 'local' data
248 // during the filling process.
249 public:
250 MSFitsInput() = delete;
251
252 // Create from output and input file names. This function opens the input
253 // file, and checks the output file is writable.
254 MSFitsInput(const String& msFile, const String& fitsFile, const Bool NewNameStyle = False);
255
256 MSFitsInput(const MSFitsInput& other) = delete;
257
258 // The destructor is fairly trivial.
260
261 MSFitsInput& operator=(const MSFitsInput& other) = delete;
262
263 // Read all the data from the FITS file and create the MeasurementSet. Throws
264 // an exception when it has severe trouble interpreting the FITS file.
265 //
267
268 private:
283 MDirection::Types _epochRef; // This is a direction measure reference code
284 // determined by epoch_p, hence the name and type.
285 // unique antennas found in the visibility data
286 // NOTE These are 1-based
287 std::set<Int> _uniqueAnts;
288 // number of rows in the created MS ANTENNA table
293 Double _restfreq; // used for images
302
303 Matrix<Double> _restFreq; // used for UVFITS
306
307 // Check that the input is a UV fits file with required contents.
308 // Returns False if not ok.
310
311 // Read the axis info of the primary group, throws an exception if required
312 // axes are missing.
314
315 // Set up the MeasurementSet, including StorageManagers and fixed columns.
316 // If useTSM is True, the Tiled Storage Manager will be used to store
317 // DATA, FLAG and WEIGHT_SPECTRUM. Use obsType to choose the tiling
318 // scheme.
319 void setupMeasurementSet(const String& MSFileName, Bool useTSM = True,
320 Int obsType = MSTileLayout::Standard);
321
323 // Read a binary table extension of type AIPS AN and create an antenna table
325
326 // Read a binary table extension and update history table
328
329 // Read a binary table extension and update history table
331
332 // extract axis information
334
335 // extract axis information
337
339
340 // verify that the fits contains visibility data
342
344
345 // fill Field table
347 void fillFieldTable(double, double, String);
348
350
352
354
355 // fill the Feed table with minimal info needed for synthesis processing
357
359 // Fill the Observation and ObsLog tables
361
362 // Fill the main table from the Primary group data
363 // if we have enough memory try to do it in mem
364 void fillMSMainTableColWise(Int& nField, Int& nSpW);
365 // else do it row by row
366 void fillMSMainTable(Int& nField, Int& nSpW);
367
368 // fill spectralwindow table from FITS FQ table + header info
370
371 // fill spectralwindow table from header
373
374 // fill Field table from FITS SU table
375 void fillFieldTable(BinaryTable& bt, Int nField);
376
377 // fill Field table from header (single source fits)
378 void fillFieldTable(Int nField);
379
380 // fill the Pointing table (from Field table, all antennas are assumed
381 // to point in the field direction) and possibly the Source table.
383
384 // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
385 // in the (last) AN table
387
388 // Returns the Direction Measure reference for UVW and other appropriate columns
389 // in msc_p (which must exist but have empty columns before you can set it!).
391
392 // Check the frame if there is an SU table
394
395 // update a the Spectral window post filling if necessary
397
400
401 std::pair<Int, Int> _extractAntennas(Int antenna1, Int antenna2);
402 std::pair<Int, Int> _extractAntennas(Float baseline);
403
405
407 const String& casaTableName, const ScalarColumn<Double>& timeCol,
408 const ScalarColumn<Float>& intervalCol, const ScalarColumn<Int>& antNoCol,
409 const ScalarColumn<Int>& freqIDCol, const ScalarColumn<Float>& powerDif1Col,
410 const ScalarColumn<Float>& powerSum1Col, const ScalarColumn<Float>& postGain1Col,
411 const ScalarColumn<Float>& powerDif2Col, const ScalarColumn<Float>& powerSum2Col,
412 const ScalarColumn<Float>& postGain2Col);
413};
414
415} // namespace casacore
416
417#endif
list of read-only FITS keywords
Definition fits.h:1229
ReservedName
FITS Reserved Names.
Definition fits.h:289
fixed-length sequential blocked FITS input
Definition fitsio.h:170
FITS keyword.
Definition fits.h:737
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition MDirection.h:187
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition MFrequency.h:175
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:91
Char * ctype(Int i)
Coordinate type.
Definition MSFitsInput.h:94
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.
Definition MSFitsInput.h:97
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).
Random Group datastructure.
Definition hdu.h:632
Primary Table structure.
Definition hdu.h:742
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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