casa  5.7.0-16
 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 
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 {
66  // This is a helper class to avoid cumbersome switch statements on the
67  // template type of the primary array
68  // It forwards all the PrimaryTable member function we need in the filler.
69 public:
70  // Construct an empty holder, used to attach to later
72 
73  // Construct from an input file containing a FITS primary group hdu.
74  // Throws an exception if the datatype is not Short, FitsLong or Float
76 
78 
79  // Attach to the input file, create the appropriate PrimaryArray.
80  // Throws an exception if the datatype is not Short, FitsLong or Float
81  void attach(FitsInput& infile);
82 
83  // Detach from the input file
84  void detach();
85 
86  //# forwarding functions
87 
88  // Number of dimensions
90  {return hdu_p->dims();}
91 
92  // Length of i'th axis
93  Int dim(Int i)
94  {return hdu_p->dim(i);}
95 
96  // Coordinate type
98  { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i));}
99 
100  // Coordinate reference value
102  { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i));}
103 
104  // Coordinate reference pixel
106  { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i));}
107 
108  // Coordinate delta
110  { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i));}
111 
112  // Keyword of given type
114  { return hdu_p->kw(n);}
115 
116  // All keywords
118  { return hdu_p->kwlist();}
119 
120  // Advance to next keyword
122  { return hdu_p->nextkw();}
123 
124  // Read the next group
125  Int read() {
126  if (pf) return pf->read();
127  else if (pl) return pl->read();
128  else if (ps) return ps->read();
129  else if (pb) return pb->read();
130  else cout << "can not read the table" << endl;
131  return 0;
132  }
133 
134 private:
140 };
141 
142 // <summary>
143 // A helper class for MSFitsInput
144 // </summary>
145 // <use visibility=local>
146 // <etymology>
147 // This class can hold a primary group of several datatypes
148 // </etymology>
149 // <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 functions we need in the filler.
153 // </synopsis>
155 {
156  // This is a helper class to avoid cumbersome switch statements on the
157  // template type of the primary group
158  // It forwards all the PrimaryGroup member function we need in the filler.
159 public:
160  // Construct an empty holder, used to attach to later
162 
163  // Construct from an input file containing a FITS primary group hdu.
164  // Throws an exception if the datatype is not Short, FitsLong or Float
166 
168 
169  // Attach to the input file, create the appropriate PrimaryGroup.
170  // Throws an exception if the datatype is not Short, FitsLong or Float
171  void attach(FitsInput& infile);
172 
173  // Detach from the input file
174  void detach();
175 
176  //# forwarding functions
177 
178  // Number of dimensions
180  {return hdu_p->dims();}
181 
182  // Length of i'th axis
184  {return hdu_p->dim(i);}
185 
186  // Coordinate type
188  { return pf ? pf->ctype(i) : (pl ? pl->ctype(i) : ps->ctype(i));}
189 
190  // Coordinate reference value
192  { return pf ? pf->crval(i) : (pl ? pl->crval(i) : ps->crval(i));}
193 
194  // Coordinate reference pixel
196  { return pf ? pf->crpix(i) : (pl ? pl->crpix(i) : ps->crpix(i));}
197 
198  // Coordinate delta
200  { return pf ? pf->cdelt(i) : (pl ? pl->cdelt(i) : ps->cdelt(i));}
201 
202  // Keyword of given type
204  { return hdu_p->kw(n);}
205 
206  // All keywords
208  { return hdu_p->kwlist();}
209 
210  // Advance to next keyword
212  { return hdu_p->nextkw();}
213 
214  // Number of groups
215  Int gcount() const
216  { return pf ? pf->gcount() : ( pl ? pl->gcount() : ps->gcount());}
217 
218  // Number of parameters
219  Int pcount() const
220  { return pf ? pf->pcount() : ( pl ? pl->pcount() : ps->pcount());}
221 
222  // Parameter type
223  Char* ptype(Int i) const
224  { return pf ? pf->ptype(i) : ( pl ? pl->ptype(i) : ps->ptype(i));}
225 
226  // Read the next group
228  { return pf ? pf->read() : ( pl ? pl->read() : ps->read());}
229 
230  // Get i'th parameter
232  { return pf ? pf->parm(i) : ( pl ? pl->parm(i) : ps->parm(i));}
233 
234  // Get group data with index i, scaled and converted to Double
236  { return pf ? (*pf)(i) : ( pl ? (*pl)(i) : (*ps)(i));}
237 
238 private:
243 };
244 
245 // <summary>
246 // UV FITS to MeasurementSet filler
247 // </summary>
248 
249 // <use visibility=export>
250 
251 // <prerequisite>
252 // <li> MeasurementSet
253 // <li> FITS classes
254 // </prerequisite>
255 //
256 // <etymology>
257 // MSFitsInput handles the conversion of FITS files to MeasurementSets
258 // </etymology>
259 //
260 // <synopsis>
261 // UV FITS to MeasurementSet filler. This can handle single source fits and
262 // multi source fits as written by classic AIPS. Also copes with multiple
263 // arrays (i.e. multiple AN tables) but doesn't correct for 5 day offsets
264 // introduced by DBCON.
265 // </synopsis>
266 
268 {
269  // This is an implementation helper class used to store 'local' data
270  // during the filling process.
271 public:
272  // Create from output and input file names. This function opens the input
273  // file, and checks the output file is writable.
274  MSFitsInput(const String& msFile, const String& fitsFile, const Bool NewNameStyle=False);
275 
276  // The destructor is fairly trivial.
277  ~MSFitsInput();
278 
279  // Read all the data from the FITS file and create the MeasurementSet. Throws
280  // an exception when it has severe trouble interpreting the FITS file.
281  //
282  void readFitsFile(Int obsType = MSTileLayout::Standard);
283 
284  // A simultaneous change to MSFitsOutput means that no longer are
285  // antenna positions being rotated when written to UVFITS. Calling
286  // this method with b=True will perform the reverse of a rotation
287  // when converting from uvfits to MS for relevant UVFITS files which
288  // were written prior to this change. Else no rotation of antenna
289  // positions is done.
291  _rotateAnts = b;
292  }
293 
294 protected:
295 
296  // Check that the input is a UV fits file with required contents.
297  // Returns False if not ok.
298  Bool checkInput(FitsInput& infile);
299 
300  // Read the axis info of the primary group, throws an exception if required
301  // axes are missing.
303 
304  // Set up the MeasurementSet, including StorageManagers and fixed columns.
305  // If useTSM is True, the Tiled Storage Manager will be used to store
306  // DATA, FLAG and WEIGHT_SPECTRUM. Use obsType to choose the tiling
307  // scheme.
308  void setupMeasurementSet(const String& MSFileName, Bool useTSM=True,
309  Int obsType = MSTileLayout::Standard);
310 
312  // Read a binary table extension of type AIPS AN and create an antenna table
313  void fillAntennaTable(BinaryTable& bt);
314 
315  // Read a binary table extension and update history table
317 
318  // Read a binary table extension and update history table
320 
321  //extract axis information
323 
324  //extract axis information
325  void sortPolarizations();
326 
327  void fillPolarizationTable();
328 
329  //verify that the fits contains visibility data
330  void checkRequiredAxis();
331 
333 
334  // fill Field table
335  void fillFieldTable(BinaryTable& bt);
336  void fillFieldTable(double, double, String);
337 
338  void fillMSMainTable(BinaryTable& bt);
339 
340  void fillPointingTable();
341 
342  void fillSourceTable();
343 
344  // fill the Feed table with minimal info needed for synthesis processing
345  void fillFeedTable();
346 
348  // Fill the Observation and ObsLog tables
349  void fillObsTables();
350 
351  // Fill the main table from the Primary group data
352  // if we have enough memory try to do it in mem
353  void fillMSMainTableColWise(Int& nField, Int& nSpW);
354  //else do it row by row
355  void fillMSMainTable(Int& nField, Int& nSpW);
356 
357  // fill spectralwindow table from FITS FQ table + header info
358  void fillSpectralWindowTable(BinaryTable& bt, Int nSpW);
359 
360  // fill spectralwindow table from header
362 
363  // fill Field table from FITS SU table
364  void fillFieldTable(BinaryTable& bt, Int nField);
365 
366  // fill Field table from header (single source fits)
367  void fillFieldTable(Int nField);
368 
369  // fill the Pointing table (from Field table, all antennas are assumed
370  // to point in the field direction) and possibly the Source table.
371  void fillExtraTables();
372 
373  // fix up the EPOCH MEASURE_REFERENCE keywords using the value found
374  // in the (last) AN table
375  void fixEpochReferences();
376 
377  // Returns the Direction Measure reference for UVW and other appropriate columns
378  // in msc_p (which must exist but have empty columns before you can set it!).
380 
381  // Check the frame if there is an SU table
382  void setFreqFrameVar(BinaryTable& binTab);
383  // update a the Spectral window post filling if necessary
385 
386  void readRandomGroupUVFits(Int obsType);
387  void readPrimaryTableUVFits(Int obsType);
388 
389 private:
390  //# The default constructor is private and undefined
391  MSFitsInput();
392  //# The copy constructor is private and undefined
393  MSFitsInput(const MSFitsInput& other);
394  //# The assignment operator is private and undefined
395  MSFitsInput& operator=(const MSFitsInput& other);
396 
411  MDirection::Types _epochRef; // This is a direction measure reference code
412  // determined by epoch_p, hence the name and type.
413  // unique antennas found in the visibility data
414  // NOTE These are 1-based
415  std::set<Int> _uniqueAnts;
416  // number of rows in the created MS ANTENNA table
421  Double _restfreq; // used for images
430 
431  Matrix<Double> _restFreq; // used for UVFITS
434 
435  std::pair<Int, Int> _extractAntennas(Float baseline);
436 
437 };
438 
439 
440 } //# NAMESPACE CASACORE - END
441 
442 #endif
const FitsKeyword * nextkw()
Advance to next keyword.
Definition: MSFitsInput.h:121
Matrix< Double > _restFreq
Definition: MSFitsInput.h:431
Double crpix(Int i)
Coordinate reference pixel.
Definition: MSFitsInput.h:105
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:195
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:404
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:399
void getAxisInfo(ConstFitsKeywordList &)
extract axis information
Int dims()
Number of dimensions.
Definition: MSFitsInput.h:89
Double parm(Int i)
Get i&#39;th parameter.
Definition: MSFitsInput.h:231
PrimaryTable< uChar > * pb
Definition: MSFitsInput.h:139
std::set< Int > _uniqueAnts
determined by epoch_p, hence the name and type.
Definition: MSFitsInput.h:415
A helper class for MSFitsInput.
Definition: MSFitsInput.h:64
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:109
Char * ctype(Int i)
Coordinate type.
Definition: MSFitsInput.h:187
Vector< Double > _obsTime
Definition: MSFitsInput.h:429
PrimaryTable< Short > * ps
Definition: MSFitsInput.h:136
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:113
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
MSFitsInput & operator=(const MSFitsInput &other)
Int dim(int n) const
Definition: hdu.h:77
double crval(int n) const
Definition: hdu.h:365
void setFreqFrameVar(BinaryTable &binTab)
Check the frame if there is an SU table.
Vector< Double > _chanFreq
Definition: MSFitsInput.h:427
int read()
read, or write the next group
Int dim(Int i)
Length of i&#39;th axis.
Definition: MSFitsInput.h:93
Int pcount() const
Number of parameters.
Definition: MSFitsInput.h:219
Vector< Double > _delta
Definition: MSFitsInput.h:408
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
Block< Int > _corrIndex
Definition: MSFitsInput.h:405
const FitsKeyword * nextkw()
Definition: hdu.h:126
Vector< String > _coordType
Definition: MSFitsInput.h:407
char * ctype(int n) const
Definition: hdu.h:362
void sortPolarizations()
extract axis information
Bool checkInput(FitsInput &infile)
Check that the input is a UV fits file with required contents.
Double crval(Int i)
Coordinate reference value.
Definition: MSFitsInput.h:191
Fill the Observation and ObsLog tables *void fillObsTables()
Int dim(Int i)
Length of i&#39;th axis.
Definition: MSFitsInput.h:183
Char * ctype(Int i)
Coordinate type.
Definition: MSFitsInput.h:97
const FitsKeyword * kw(const FITS::ReservedName &n)
Keyword of given type.
Definition: MSFitsInput.h:203
void detach()
Detach from the input file.
Vector< Double > _receptorAngle
Definition: MSFitsInput.h:419
Char * ptype(Int i) const
Parameter type.
Definition: MSFitsInput.h:223
Int read()
Read the next group.
Definition: MSFitsInput.h:125
MDirection::Types getDirectionFrame(Double epoch)
Returns the Direction Measure reference for UVW and other appropriate columns in msc_p (which must ex...
std::pair< Int, Int > _extractAntennas(Float baseline)
Int read()
Read the next group.
Definition: MSFitsInput.h:227
Int dims()
Number of dimensions.
Definition: MSFitsInput.h:179
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:404
Double cdelt(Int i)
Coordinate delta.
Definition: MSFitsInput.h:199
~MSFitsInput()
The destructor is fairly trivial.
MSPrimaryTableHolder _priTable
Definition: MSFitsInput.h:400
const FitsKeyword * nextkw()
Advance to next keyword.
Definition: MSFitsInput.h:211
ConstFitsKeywordList & kwlist()
All keywords.
Definition: MSFitsInput.h:207
PrimaryGroup< Short > * ps
Definition: MSFitsInput.h:240
Vector< Double > _refVal
Definition: MSFitsInput.h:408
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:408
void fillHistoryTable(ConstFitsKeywordList &kwl)
Read a binary table extension and update history table.
list of read-only FITS keywords
Definition: fits.h:955
PrimaryGroup< FitsLong > * pl
Definition: MSFitsInput.h:241
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:411
void rotateAntennaPositions(Bool b)
A simultaneous change to MSFitsOutput means that no longer are antenna positions being rotated when w...
Definition: MSFitsInput.h:290
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.
ConstFitsKeywordList & kwlist()
All keywords.
Definition: MSFitsInput.h:117
void fillMSMainTable(BinaryTable &bt)
MeasurementSet _ms
Definition: MSFitsInput.h:401
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:235
Matrix< Int > _corrProduct
Definition: MSFitsInput.h:406
PrimaryGroup< Float > * pf
Definition: MSFitsInput.h:242
FITS keyword.
Definition: fits.h:519
A class to provide easy read-write access to MeasurementSet columns.
Definition: MSColumns.h:221
double crpix(int n) const
Definition: hdu.h:363
PrimaryTable< Float > * pf
Definition: MSFitsInput.h:138
void updateSpectralWindowTable()
update a the Spectral window post filling if necessary
String: the storage and methods of handling collections of characters.
Definition: String.h:223
UV FITS to MeasurementSet filler.
Definition: MSFitsInput.h:267
Matrix< Double > _sysVel
Definition: MSFitsInput.h:432
Int _nAntRow
number of rows in the created MS ANTENNA table
Definition: MSFitsInput.h:417
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:420
Int gcount() const
Number of groups.
Definition: MSFitsInput.h:215
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:154
Double crval(Int i)
Coordinate reference value.
Definition: MSFitsInput.h:101
PrimaryTable< FitsLong > * pl
Definition: MSFitsInput.h:137
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:242
void readPrimaryTableUVFits(Int obsType)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42