casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSFitsOutput.h
Go to the documentation of this file.
1 //# MSFitsOutput.h: Write a MeasurementSet to a random group uvfits file
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001,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: MSFitsOutput.h 21521 2014-12-10 08:06:42Z gervandiepen $
27 
28 #ifndef MS_MSFITSOUTPUT_H
29 #define MS_MSFITSOUTPUT_H
30 
35 
36 #include <casacore/casa/aips.h>
37 
38 namespace casacore {
39 
40 //# Forward Declarations
41 class File;
42 class FitsOutput;
43 template<class T> class ScalarColumn;
44 class Table;
45 template<class T> class Block;
46 // <summary>
47 // Write a MeasurementSet to a random group uvfits file.
48 // </summary>
49 
50 class MSFitsOutput {
51 public:
52  // @param fitsfile Output filename
53  // @param ms input
54  // @param column specifies which "data" column to write
55  // ("observed", "calibrated", "model")
57  const String& fitsfile, const MeasurementSet& ms,
58  const String& column
59  );
60 
61  // @param startChan 1st channel
62  // @param nchan # of channels
63  // @param stepChan # of channels to stride by
64  // @param avgChan average every N channels
65  void setChannelInfo(
66  Int startChan, Int nchan, Int stepChan, Int avgChan
67  );
68 
69  // @param writeSysCal whether to write the system calibration table
70  void setWriteSysCal(Bool writeSysCal);
71 
72  // @param asMultiSource If true a multi-source UVFits file is written.
73  void setAsMultiSource(Bool asMultiSource);
74 
75  // @param combineSpw If true it attempts to write the spectral windows as
76  // IFs. This is necessary for many aips tasks, and
77  // for difmap.
78  void setCombineSpw(Bool combineSpw);
79 
80  // @param writeStation If true uses pad instead of antenna names.
81  void setWriteStation(Bool writeStation);
82 
83  void setSensitivity(Double sensitivity);
84 
85  // @param padWithFlags If true and combineSpw==true, fill spws with flags
86  // as needed to fit the IF structure. Does not yet
87  // support spws with different shapes.
88  void setPadWitFlags(Bool padWithFlags);
89 
90  void setFieldNumber(uInt fieldNumber);
91 
92  // @param overwrite overwrite existing file?
93  void setOverwrite(Bool overwrite);
94 
95  // write the uvfits file.
96  void write() const;
97 
98  // Convert a MeasurementSet to random group UVFITS.
99  // @param fitsfile Output filename
100  // @param ms input
101  // @param column specifies which "data" column to write
102  // ("observed", "calibrated", "model")
103  // @param startchan 1st channel
104  // @param nchan # of channels
105  // @param stepchan # of channels to stride by
106  // @param writeSysCal whether to write the system calibration table
107  // @param asMultiSource If true a multi-source UVFits file is written.
108  // @param combineSpw If true it attempts to write the spectral windows as
109  // IFs. This is necessary for many aips tasks, and
110  // for difmap.
111  // @param writeStation If true uses pad instead of antenna names.
112  // @param sensitivity
113  // @param padWithFlags If true and combineSpw==true, fill spws with flags
114  // as needed to fit the IF structure. Does not yet
115  // support spws with different shapes.
116  // @param avgchan average every N channels
117  // @param fieldNumber field number
118  // @param overwrite overwrite existing file?
119  static Bool writeFitsFile(
120  const String& fitsfile, const MeasurementSet& ms,
121  const String& column, Int startchan=0,
122  Int nchan=1, Int stepchan=1,
123  Bool writeSysCal = False,
124  Bool asMultiSource = False, Bool combineSpw=False,
125  Bool writeStation=False, Double sensitivity=1.0,
126  const Bool padWithFlags=false, Int avgchan=1,
127  uInt fieldNumber=0, Bool overwrite=False
128  );
129 
130 private:
138 
139 
140  // Write the main table.
141  // @param refPixelFreq
142  // @param refFreq
143  // @param chanbw
144  // @param outFITSFile
145  // @param spwidMap spwidMap[inp_spw] = output_spw, if inp_spw is selected
146  // -1 otherwise.
147  // @param nrspw # of selected spws.
148  // @param fieldidMap fieldidMap[inp_fld] = output_fld, if inp_fld is selected
149  // -1 otherwise.
150  // @param asMultiSource If true, write a multisource UVFITS file.
151  std::shared_ptr<FitsOutput> _writeMain(
152  Int& refPixelFreq, Double& refFreq,
153  Double& chanbw, const String& outFITSFile,
154  const Block<Int>& spwidMap, Int nrspw,
155  const Block<Int>& fieldidMap,
156  Bool asMultiSource
157  ) const;
158 
159  // Write the FQ table.
160  // If combineSpw is True, all spectral-windows are written in one
161  // row of the FITS table.
162  static Bool _writeFQ(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
163  const Block<Int>& spwidMap, Int nrspw,
164  Double refFreq, Int refPixelFreq,
165  Double chanbw, Bool combineSpw,
166  Int chanstart = 0, Int nchan = -1, Int chanstep = 1,
167  Int avgchan = 1
168  );
169 
170  // Write the AN table.
171  static Bool _writeAN(
172  std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
173  Double refFreq, Bool writeStation
174  );
175 
176  // Write the SU table.
177  static Bool _writeSU(
178  std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
179  const Block<Int>& fieldidMap, Int nrfield,
180  const Block<Int>& spwidMap, Int nrspw
181  );
182 
183  // Write the TY table.
184  static Bool _writeTY(
185  std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
186  const Table& syscal, const Block<Int>& spwidMap,
187  uInt nrif, Bool combineSpw
188  );
189 
190  // Write the GC table.
191  static Bool _writeGC(
192  std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
193  const Table& syscal, const Block<Int>& spwidMap,
194  uInt nrif, Bool combineSpw, Double sensitivity,
195  Int refPixelFreq, Double refFreq, Double chanbw
196  );
197 
198  // Write the WX table.
199  static Bool _writeWX(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms);
200 
201  // Write the SY table.
202  static Bool _writeSY(
203  std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
204  Table& syspower, Int nspw, const Block<Int>& spwIDMap,
205  Bool combineSpw
206  );
207 
208  // Convert time to day and fraction.
209  static void timeToDay(Int& day, Double& dayFraction, Double time);
210 
211  // Get the time and hourangle from the MS at the given row.
212  // It uses the field-id and observation-id to calculate the hourangle.
213  static void getStartHA (
214  Double& startTime, Double& startHA,
215  const MeasurementSet& ms, uInt rownr
216  );
217 
218  // Discern the antenna numbers that go into UVFITS
219  static void _handleAntNumbers(const MeasurementSet& ms,Vector<Int>& antnumbers);
220 
221  // Handle the SYSCAL table.
222  // It skips the entries not needed and sorts it in the correct order.
223  static Table handleSysCal (
224  const MeasurementSet& ms,
225  const Vector<Int>& spwids, Bool isSubset
226  );
227 
228  // Determine which ids are selected in the main table
229  // (used for fields and spectral-window).
230  // @param map (Really an output here, not an input.)
231  // spwidMap[inp_id] = output_id, if inp_id is selected
232  // -1 otherwise.
233  // @param selids (Really an output here, not an input.)
234  // A list of the selected input IDs.
235  // @param allids (Really is an input, not an output!)
236  // IDs to consider.
237  // @return number of selected IDs in allids
238 
239  static Int _makeIdMap(
240  Block<Int>& map, Vector<Int>& selids,
241  const Vector<Int>& allids
242  );
243 
244  // Find the end of a group of rows with the same
245  // time(_centroid) (within 0.25 * ininterval(rownr)),
246  // baseline #,
247  // and, if asMultiSource, field ID.
248  // @param rownr Row # to start from.
249  // @param nrow # of rows in the columns.
250  // @param nif # of IFs
251  // @param timec time(_centroid) col
252  // @param ininterval used to set tolerance on changes in timec.
253  // @param ant1 ID of baseline's antenna 1.
254  // @param ant2 ID of baseline's antenna 2.
255  // @param asMultiSource If false, treat fieldid as unattached + prone to segfault
256  // @param fieldid
257  // @return Last row # with the same time, baseline, and apparent field as rownr.
258  // @warning Assumes that the columns are sorted by time(_centroid), ant1,
259  // ant2 (, field, DDID).
260  static uInt get_tbf_end(
261  const uInt rownr, const uInt nrow, const uInt nif,
262  const ScalarColumn<Double>& timec,
263  const ScalarColumn<Double>& ininterval,
264  const ScalarColumn<Int>& ant1,
265  const ScalarColumn<Int>& ant2,
266  const Bool asMultiSource,
267  const ScalarColumn<Int>& fieldid
268  );
269 
270  static void _checkReceptorAngles(
271  const Vector<Quantity>& ra0, Vector<Quantity>& ra1, Int antnum
272  );
273 };
274 
275 } //# NAMESPACE CASACORE - END
276 
277 #endif
int Int
Definition: aipstype.h:50
TableExprNode time(const TableExprNode &node)
Definition: ExprNode.h:1580
void setOverwrite(Bool overwrite)
Main interface class to a read/write table.
Definition: Table.h:157
void setSensitivity(Double sensitivity)
static Table handleSysCal(const MeasurementSet &ms, const Vector< Int > &spwids, Bool isSubset)
Handle the SYSCAL table.
void setPadWitFlags(Bool padWithFlags)
static Bool _writeAN(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms, Double refFreq, Bool writeStation)
Write the AN table.
static Int _makeIdMap(Block< Int > &map, Vector< Int > &selids, const Vector< Int > &allids)
Determine which ids are selected in the main table (used for fields and spectral-window).
void setCombineSpw(Bool combineSpw)
Write a MeasurementSet to a random group uvfits file.
Definition: MSFitsOutput.h:50
static void getStartHA(Double &startTime, Double &startHA, const MeasurementSet &ms, uInt rownr)
Get the time and hourangle from the MS at the given row.
void setFieldNumber(uInt fieldNumber)
const MeasurementSet _ms
Definition: MSFitsOutput.h:132
void setChannelInfo(Int startChan, Int nchan, Int stepChan, Int avgChan)
static Bool _writeFQ(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms, const Block< Int > &spwidMap, Int nrspw, Double refFreq, Int refPixelFreq, Double chanbw, Bool combineSpw, Int chanstart=0, Int nchan=-1, Int chanstep=1, Int avgchan=1)
Write the FQ table.
void write() const
write the uvfits file.
static Bool _writeSY(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms, Table &syspower, Int nspw, const Block< Int > &spwIDMap, Bool combineSpw)
Write the SY table.
static void timeToDay(Int &day, Double &dayFraction, Double time)
Convert time to day and fraction.
static Bool writeFitsFile(const String &fitsfile, const MeasurementSet &ms, const String &column, Int startchan=0, Int nchan=1, Int stepchan=1, Bool writeSysCal=False, Bool asMultiSource=False, Bool combineSpw=False, Bool writeStation=False, Double sensitivity=1.0, const Bool padWithFlags=false, Int avgchan=1, uInt fieldNumber=0, Bool overwrite=False)
Convert a MeasurementSet to random group UVFITS.
static uInt get_tbf_end(const uInt rownr, const uInt nrow, const uInt nif, const ScalarColumn< Double > &timec, const ScalarColumn< Double > &ininterval, const ScalarColumn< Int > &ant1, const ScalarColumn< Int > &ant2, const Bool asMultiSource, const ScalarColumn< Int > &fieldid)
Find the end of a group of rows with the same time(_centroid) (within 0.25 * ininterval(rownr)), baseline #, and, if asMultiSource, field ID.
double Double
Definition: aipstype.h:55
void setWriteStation(Bool writeStation)
static void _checkReceptorAngles(const Vector< Quantity > &ra0, Vector< Quantity > &ra1, Int antnum)
MSFitsOutput(const String &fitsfile, const MeasurementSet &ms, const String &column)
void setAsMultiSource(Bool asMultiSource)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static Bool _writeWX(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms)
Write the WX table.
const String _fitsfile
Definition: MSFitsOutput.h:131
static Bool _writeGC(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms, const Table &syscal, const Block< Int > &spwidMap, uInt nrif, Bool combineSpw, Double sensitivity, Int refPixelFreq, Double refFreq, Double chanbw)
Write the GC table.
const Bool False
Definition: aipstype.h:44
void setWriteSysCal(Bool writeSysCal)
static Bool _writeSU(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms, const Block< Int > &fieldidMap, Int nrfield, const Block< Int > &spwidMap, Int nrspw)
Write the SU table.
A Table intended to hold astronomical data (a set of Measurements).
TableExprNode day(const TableExprNode &node)
Definition: ExprNode.h:1523
static Bool _writeTY(std::shared_ptr< FitsOutput > output, const MeasurementSet &ms, const Table &syscal, const Block< Int > &spwidMap, uInt nrif, Bool combineSpw)
Write the TY table.
String: the storage and methods of handling collections of characters.
Definition: String.h:225
std::shared_ptr< FitsOutput > _writeMain(Int &refPixelFreq, Double &refFreq, Double &chanbw, const String &outFITSFile, const Block< Int > &spwidMap, Int nrspw, const Block< Int > &fieldidMap, Bool asMultiSource) const
Write the main table.
unsigned int uInt
Definition: aipstype.h:51
static void _handleAntNumbers(const MeasurementSet &ms, Vector< Int > &antnumbers)
Discern the antenna numbers that go into UVFITS.