casa  5.7.0-16
 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 
34 
35 #include <casacore/casa/aips.h>
36 
37 namespace casacore {
38 
39 //# Forward Declarations
40 class FitsOutput;
41 template<class T> class ScalarColumn;
42 class Table;
43 template<class T> class Block;
44 template<class T> class Vector;
45 
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.
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(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  FitsOutput *output, const MeasurementSet& ms,
173  Double refFreq, Bool writeStation
174  );
175 
176  // Write the SU table.
177  static Bool writeSU(
178  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  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  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(FitsOutput *output, const MeasurementSet& ms);
200 
201  // Convert time to day and fraction.
202  static void timeToDay(Int& day, Double& dayFraction, Double time);
203 
204  // Get the time and hourangle from the MS at the given row.
205  // It uses the field-id and observation-id to calculate the hourangle.
206  static void getStartHA (
207  Double& startTime, Double& startHA,
208  const MeasurementSet& ms, uInt rownr
209  );
210 
211  // Discern the antenna numbers that go into UVFITS
212  static void handleAntNumbers(const MeasurementSet& ms,Vector<Int>& antnumbers);
213 
214  // Handle the SYSCAL table.
215  // It skips the entries not needed and sorts it in the correct order.
216  static Table handleSysCal (
217  const MeasurementSet& ms,
218  const Vector<Int>& spwids, Bool isSubset
219  );
220 
221  // Determine which ids are selected in the main table
222  // (used for fields and spectral-window).
223  // @param map (Really an output here, not an input.)
224  // spwidMap[inp_id] = output_id, if inp_id is selected
225  // -1 otherwise.
226  // @param selids (Really an output here, not an input.)
227  // A list of the selected input IDs.
228  // @param allids (Really is an input, not an output!)
229  // IDs to consider.
230  // @return number of selected IDs in allids
231 
232  static Int _makeIdMap(
233  Block<Int>& map, Vector<Int>& selids,
234  const Vector<Int>& allids
235  );
236 
237  // Find the end of a group of rows with the same
238  // time(_centroid) (within 0.25 * ininterval(rownr)),
239  // baseline #,
240  // and, if asMultiSource, field ID.
241  // @param rownr Row # to start from.
242  // @param nrow # of rows in the columns.
243  // @param nif # of IFs
244  // @param timec time(_centroid) col
245  // @param ininterval used to set tolerance on changes in timec.
246  // @param ant1 ID of baseline's antenna 1.
247  // @param ant2 ID of baseline's antenna 2.
248  // @param asMultiSource If false, treat fieldid as unattached + prone to segfault
249  // @param fieldid
250  // @return Last row # with the same time, baseline, and apparent field as rownr.
251  // @warning Assumes that the columns are sorted by time(_centroid), ant1,
252  // ant2 (, field, DDID).
253  static uInt get_tbf_end(
254  const uInt rownr, const uInt nrow, const uInt nif,
255  const ScalarColumn<Double>& timec,
256  const ScalarColumn<Double>& ininterval,
257  const ScalarColumn<Int>& ant1,
258  const ScalarColumn<Int>& ant2,
259  const Bool asMultiSource,
260  const ScalarColumn<Int>& fieldid
261  );
262 
263  static void _checkReceptorAngles(
264  const Vector<Quantity>& ra0, Vector<Quantity>& ra1, Int antnum
265  );
266 };
267 
268 } //# NAMESPACE CASACORE - END
269 
270 #endif
A 1-D Specialization of the Array class.
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.
int Int
Definition: aipstype.h:50
TableExprNode time(const TableExprNode &node)
Definition: ExprNode.h:1537
void setOverwrite(Bool overwrite)
Main interface class to a read/write table.
Definition: Table.h:153
static Bool writeGC(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.
void setSensitivity(Double sensitivity)
static Bool writeFQ(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.
static Bool writeAN(FitsOutput *output, const MeasurementSet &ms, Double refFreq, Bool writeStation)
Write the AN table.
static Table handleSysCal(const MeasurementSet &ms, const Vector< Int > &spwids, Bool isSubset)
Handle the SYSCAL table.
void setPadWitFlags(Bool padWithFlags)
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)
static void handleAntNumbers(const MeasurementSet &ms, Vector< Int > &antnumbers)
Discern the antenna numbers that go into UVFITS.
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.
static Bool writeSU(FitsOutput *output, const MeasurementSet &ms, const Block< Int > &fieldidMap, Int nrfield, const Block< Int > &spwidMap, Int nrspw)
Write the SU table.
void setFieldNumber(uInt fieldNumber)
const MeasurementSet _ms
Definition: MSFitsOutput.h:132
void setChannelInfo(Int startChan, Int nchan, Int stepChan, Int avgChan)
static Bool writeWX(FitsOutput *output, const MeasurementSet &ms)
Write the WX table.
void write() const
write the uvfits file.
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
const String _fitsfile
Definition: MSFitsOutput.h:131
const Bool False
Definition: aipstype.h:44
void setWriteSysCal(Bool writeSysCal)
A Table intended to hold astronomical data (a set of Measurements).
simple 1-D array
fixed-length sequential blocked FITS output
Definition: fitsio.h:228
TableExprNode day(const TableExprNode &node)
Definition: ExprNode.h:1480
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Access to a scalar table column with arbitrary data type.
Definition: MSFitsOutput.h:41
static Bool writeTY(FitsOutput *output, const MeasurementSet &ms, const Table &syscal, const Block< Int > &spwidMap, uInt nrif, Bool combineSpw)
Write the TY table.
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42