casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
37 #include <casacore/fits/FITS/hdu.h>
45 
46 namespace casacore { //# NAMESPACE CASACORE - BEGIN
47 
48 class FitsInput;
49 class BinaryTable;
50 class MSColumns;
51 template <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.
70 public:
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
94  Int dim(Int i)
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
126  Int read() {
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 
135 private:
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.
160 public:
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 
239 private:
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.
272 public:
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.
282  ~MSFitsInput();
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  //
289  void readFitsFile(Int obsType = MSTileLayout::Standard);
290 
291 private:
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.
332  Bool _checkInput(FitsInput& infile);
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
347  void fillAntennaTable(BinaryTable& bt);
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
359  void sortPolarizations();
360 
361  void fillPolarizationTable();
362 
363  //verify that the fits contains visibility data
364  void checkRequiredAxis();
365 
367 
368  // fill Field table
369  void fillFieldTable(BinaryTable& bt);
370  void fillFieldTable(double, double, String);
371 
372  void fillMSMainTable(BinaryTable& bt);
373 
374  void fillPointingTable();
375 
376  void fillSourceTable();
377 
378  // fill the Feed table with minimal info needed for synthesis processing
379  void fillFeedTable();
380 
382  // Fill the Observation and ObsLog tables
383  void fillObsTables();
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
392  void fillSpectralWindowTable(BinaryTable& bt, Int nSpW);
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.
405  void fillExtraTables();
406 
407  // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
408  // in the (last) AN table
409  void fixEpochReferences();
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
416  void setFreqFrameVar(BinaryTable& binTab);
417 
418  // update a the Spectral window post filling if necessary
420 
421  void readRandomGroupUVFits(Int obsType);
422  void readPrimaryTableUVFits(Int obsType);
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
const FitsKeyword * nextkw()
Advance to next keyword.
Definition: MSFitsInput.h:122
Matrix< Double > _restFreq
Definition: MSFitsInput.h:326
Double crpix(Int i)
Coordinate reference pixel.
Definition: MSFitsInput.h:106
Int pcount() const
Definition: hdu.h:608
int Int
Definition: aipstype.h:50
void attach(FitsInput &infile)
Attach to the input file, create the appropriate PrimaryGroup.
Double crpix(Int i)
Coordinate reference pixel.
Definition: MSFitsInput.h:196
int read()
The `read()&#39; and `write()&#39; functions control reading and writing data from the external FITS I/O medi...
char * ptype(int n) const
Definition: hdu.h:609
Vector< Int > _corrType
Definition: MSFitsInput.h:299
void checkRequiredAxis()
verify that the fits contains visibility data
void fillObservationTable(ConstFitsKeywordList &kwl)
Read a binary table extension and update history table.
const FitsKeyword * kw(int n)
Definition: hdu.h:129
MSPrimaryGroupHolder _priGroup
Definition: MSFitsInput.h:294
void getAxisInfo(ConstFitsKeywordList &)
extract axis information
Int dims()
Number of dimensions.
Definition: MSFitsInput.h:90
Double parm(Int i)
Get i&#39;th parameter.
Definition: MSFitsInput.h:232
PrimaryTable< uChar > * pb
Definition: MSFitsInput.h:140
std::set< Int > _uniqueAnts
determined by epoch_p, hence the name and type.
Definition: MSFitsInput.h:310
A helper class for MSFitsInput.
Definition: MSFitsInput.h:65
Standard, optimizes i/o by using large tiles (128 kB)
Definition: MSTileLayout.h:87
double cdelt(int n) const
Definition: hdu.h:366
Double cdelt(Int i)
Coordinate delta.
Definition: MSFitsInput.h:110
Char * ctype(Int i)
Coordinate type.
Definition: MSFitsInput.h:188
Vector< Double > _obsTime
Definition: MSFitsInput.h:324
PrimaryTable< Short > * ps
Definition: MSFitsInput.h:137
base class that defines a HDU
Definition: hdu.h:71
char Char
Definition: aipstype.h:46
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
Definition: MSFitsInput.h:114
MSPrimaryTableHolder()
This is a helper class to avoid cumbersome switch statements on the template type of the primary arra...
ostream-like interface to creating log messages.
Definition: LogIO.h:167
Int dim(int n) const
Definition: hdu.h:77
double crval(int n) const
Definition: hdu.h:365
MSFitsInput & operator=(const MSFitsInput &other)=delete
void setFreqFrameVar(BinaryTable &binTab)
Check the frame if there is an SU table.
Vector< Double > _chanFreq
Definition: MSFitsInput.h:322
Bool _checkInput(FitsInput &infile)
Check that the input is a UV fits file with required contents.
int read()
read, or write the next group
Int dim(Int i)
Length of i&#39;th axis.
Definition: MSFitsInput.h:94
Int pcount() const
Number of parameters.
Definition: MSFitsInput.h:220
Vector< Double > _delta
Definition: MSFitsInput.h:303
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition: MDirection.h:188
void fillFeedTable()
fill the Feed table with minimal info needed for synthesis processing
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)
Block< Int > _corrIndex
Definition: MSFitsInput.h:300
const FitsKeyword * nextkw()
Definition: hdu.h:126
Vector< String > _coordType
Definition: MSFitsInput.h:302
char * ctype(int n) const
Definition: hdu.h:362
MSFitsInput()=delete
This is an implementation helper class used to store &#39;local&#39; data during the filling process...
void sortPolarizations()
extract axis information
Double crval(Int i)
Coordinate reference value.
Definition: MSFitsInput.h:192
Fill the Observation and ObsLog tables *void fillObsTables()
Int dim(Int i)
Length of i&#39;th axis.
Definition: MSFitsInput.h:184
Char * ctype(Int i)
Coordinate type.
Definition: MSFitsInput.h:98
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
Definition: MSFitsInput.h:204
void detach()
Detach from the input file.
Vector< Double > _receptorAngle
Definition: MSFitsInput.h:314
Char * ptype(Int i) const
Parameter type.
Definition: MSFitsInput.h:224
Int read()
Read the next group.
Definition: MSFitsInput.h:126
MDirection::Types getDirectionFrame(Double epoch)
Returns the Direction Measure reference for UVW and other appropriate columns in msc_p (which must ex...
Int read()
Read the next group.
Definition: MSFitsInput.h:228
Int dims()
Number of dimensions.
Definition: MSFitsInput.h:180
Int dims() const
Definition: hdu.h:76
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...
double Double
Definition: aipstype.h:55
Vector< Int > _nPixel
Definition: MSFitsInput.h:299
Double cdelt(Int i)
Coordinate delta.
Definition: MSFitsInput.h:200
~MSFitsInput()
The destructor is fairly trivial.
MSPrimaryTableHolder _priTable
Definition: MSFitsInput.h:295
const FitsKeyword * nextkw()
Advance to next keyword.
Definition: MSFitsInput.h:212
ConstFitsKeywordList & kwlist()
All keywords.
Definition: MSFitsInput.h:208
PrimaryGroup< Short > * ps
Definition: MSFitsInput.h:241
Vector< Double > _refVal
Definition: MSFitsInput.h:303
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Vector< Double > _refPix
Definition: MSFitsInput.h:303
void fillHistoryTable(ConstFitsKeywordList &kwl)
Read a binary table extension and update history table.
list of read-only FITS keywords
Definition: fits.h:951
PrimaryGroup< FitsLong > * pl
Definition: MSFitsInput.h:242
BinaryTable is used to translate a FITS binary table to a Casacore Table.
Definition: BinTable.h:110
float Float
Definition: aipstype.h:54
ConstFitsKeywordList & kwlist()
Operations on the HDU&#39;s keyword list.
Definition: hdu.h:120
const Bool False
Definition: aipstype.h:44
MDirection::Types _epochRef
Definition: MSFitsInput.h:306
void fixEpochReferences()
fix up the EPOCH MEASURE_REFERENCE keywords using the value found in the (last) AN table ...
MSPrimaryGroupHolder()
This is a helper class to avoid cumbersome switch statements on the template type of the primary grou...
A Table intended to hold astronomical data (a set of Measurements).
void setupMeasurementSet(const String &MSFileName, Bool useTSM=True, Int obsType=MSTileLayout::Standard)
Set up the MeasurementSet, including StorageManagers and fixed columns.
void _fillSysPowerTable(BinaryTable &bt)
ConstFitsKeywordList & kwlist()
All keywords.
Definition: MSFitsInput.h:118
void fillMSMainTable(BinaryTable &bt)
MeasurementSet _ms
Definition: MSFitsInput.h:296
void getPrimaryGroupAxisInfo()
Read the axis info of the primary group, throws an exception if required axes are missing...
fixed-length sequential blocked FITS input
Definition: fitsio.h:156
Double operator()(Int i) const
Get group data with index i, scaled and converted to Double.
Definition: MSFitsInput.h:236
Matrix< Int > _corrProduct
Definition: MSFitsInput.h:301
PrimaryGroup< Float > * pf
Definition: MSFitsInput.h:243
FITS keyword.
Definition: fits.h:515
A class to provide easy access to MeasurementSet columns.
Definition: MSColumns.h:116
double crpix(int n) const
Definition: hdu.h:363
PrimaryTable< Float > * pf
Definition: MSFitsInput.h:139
void updateSpectralWindowTable()
update a the Spectral window post filling if necessary
String: the storage and methods of handling collections of characters.
Definition: String.h:225
UV FITS to MeasurementSet filler.
Definition: MSFitsInput.h:268
Matrix< Double > _sysVel
Definition: MSFitsInput.h:327
Int _nAntRow
number of rows in the created MS ANTENNA table
Definition: MSFitsInput.h:312
void readRandomGroupUVFits(Int obsType)
void fillExtraTables()
fill the Pointing table (from Field table, all antennas are assumed to point in the field direction) ...
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition: MFrequency.h:176
void fillSpectralWindowTable()
fill spectralwindow table from header
Int gcount() const
Return basic parameters of a random group.
Definition: hdu.h:607
MFrequency::Types _freqsys
Definition: MSFitsInput.h:315
Int gcount() const
Number of groups.
Definition: MSFitsInput.h:216
std::pair< Int, Int > _extractAntennas(Int antenna1, Int antenna2)
void attach(FitsInput &infile)
Attach to the input file, create the appropriate PrimaryArray.
void detach()
Detach from the input file.
void readFitsFile(Int obsType=MSTileLayout::Standard)
Read all the data from the FITS file and create the MeasurementSet.
const Bool True
Definition: aipstype.h:43
A helper class for MSFitsInput.
Definition: MSFitsInput.h:155
Double crval(Int i)
Coordinate reference value.
Definition: MSFitsInput.h:102
PrimaryTable< FitsLong > * pl
Definition: MSFitsInput.h:138
void fillFieldTable(BinaryTable &bt)
fill Field table
Read a binary table extension of type AIPS AN and create an antenna table *void fillAntennaTable(BinaryTable &bt)
ReservedName
FITS Reserved Names.
Definition: fits.h:238
void readPrimaryTableUVFits(Int obsType)