casacore
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 
31 #include <casacore/casa/BasicSL/String.h>
32 #include <casacore/ms/MeasurementSets/MeasurementSet.h>
33 
34 #include <casacore/casa/aips.h>
35 
36 namespace casacore {
37 
38 //# Forward Declarations
39 class FitsOutput;
40 template<class T> class ScalarColumn;
41 class Table;
42 template<class T> class Block;
43 template<class T> class Vector;
44 
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 overwrite overwrite existing file?
118  static Bool writeFitsFile(
119  const String& fitsfile, const MeasurementSet& ms,
120  const String& column, Int startchan=0,
121  Int nchan=1, Int stepchan=1,
122  Bool writeSysCal = False,
123  Bool asMultiSource = False, Bool combineSpw=False,
124  Bool writeStation=False, Double sensitivity=1.0,
125  const Bool padWithFlags=false, Int avgchan=1,
126  uInt fieldNumber=0, Bool overwrite=False
127  );
128 
129 private:
137 
138 
139  // Write the main table.
140  // @param refPixelFreq
141  // @param refFreq
142  // @param chanbw
143  // @param outFITSFile
144  // @param rawms
145  // @param column data column to write
146  // @param spwidMap spwidMap[inp_spw] = output_spw, if inp_spw is selected
147  // -1 otherwise.
148  // @param nrspw # of selected spws.
149  // @param startchan First channel
150  // @param nchan # of channels
151  // @param stepchan channel stride
152  // @param fieldidMap fieldidMap[inp_fld] = output_fld, if inp_fld is selected
153  // -1 otherwise.
154  // @param asMultiSource If true, write a multisource UVFITS file.
155  // @param combineSpw If true, export the spectral window(s) as IF(s).
156  // @param padWithFlags If true && combineSpw==true, pad the spws with
157  // flags as necessary to fit the IF structure.
158  // @param avgchan average every N channels
160  Int& refPixelFreq, Double& refFreq,
161  Double& chanbw, const String& outFITSFile,
162  const Block<Int>& spwidMap, Int nrspw,
163  const Block<Int>& fieldidMap,
164  Bool asMultiSource
165  ) const;
166 
167  // Write the FQ table.
168  // If combineSpw is True, all spectral-windows are written in one
169  // row of the FITS table.
170  static Bool writeFQ(FitsOutput *output, const MeasurementSet& ms,
171  const Block<Int>& spwidMap, Int nrspw,
172  Double refFreq, Int refPixelFreq,
173  Double chanbw, Bool combineSpw,
174  Int chanstart = 0, Int nchan = -1, Int chanstep = 1,
175  Int avgchan = 1
176  );
177 
178  // Write the AN table.
179  static Bool writeAN(
180  FitsOutput *output, const MeasurementSet& ms,
181  Double refFreq, Bool writeStation
182  );
183 
184  // Write the SU table.
185  static Bool writeSU(
186  FitsOutput *output, const MeasurementSet& ms,
187  const Block<Int>& fieldidMap, Int nrfield,
188  const Block<Int>& spwidMap, Int nrspw
189  );
190 
191  // Write the TY table.
192  static Bool writeTY(
193  FitsOutput *output, const MeasurementSet& ms,
194  const Table& syscal, const Block<Int>& spwidMap,
195  uInt nrif, Bool combineSpw
196  );
197 
198  // Write the GC table.
199  static Bool writeGC(
200  FitsOutput *output, const MeasurementSet& ms,
201  const Table& syscal, const Block<Int>& spwidMap,
202  uInt nrif, Bool combineSpw, Double sensitivity,
203  Int refPixelFreq, Double refFreq, Double chanbw
204  );
205 
206  // Write the WX table.
207  static Bool writeWX(FitsOutput *output, const MeasurementSet& ms);
208 
209  // Convert time to day and fraction.
210  static void timeToDay(Int& day, Double& dayFraction, Double time);
211 
212  // Get the time and hourangle from the MS at the given row.
213  // It uses the field-id and observation-id to calculate the hourangle.
214  static void getStartHA (
215  Double& startTime, Double& startHA,
216  const MeasurementSet& ms, uInt rownr
217  );
218 
219  // Discern the antenna numbers that go into UVFITS
220  static void handleAntNumbers(const MeasurementSet& ms,Vector<Int>& antnumbers);
221 
222  // Handle the SYSCAL table.
223  // It skips the entries not needed and sorts it in the correct order.
224  static Table handleSysCal (
225  const MeasurementSet& ms,
226  const Vector<Int>& spwids, Bool isSubset
227  );
228 
229  // Determine which ids are selected in the main table
230  // (used for fields and spectral-window).
231  // @param map (Really an output here, not an input.)
232  // spwidMap[inp_id] = output_id, if inp_id is selected
233  // -1 otherwise.
234  // @param selids (Really an output here, not an input.)
235  // A list of the selected input IDs.
236  // @param allids (Really is an input, not an output!)
237  // IDs to consider.
238  // @return number of selected IDs in allids
239 
240  static Int _makeIdMap(
241  Block<Int>& map, Vector<Int>& selids,
242  const Vector<Int>& allids
243  );
244 
245  // Find the end of a group of rows with the same
246  // time(_centroid) (within 0.25 * ininterval(rownr)),
247  // baseline #,
248  // and, if asMultiSource, field ID.
249  // @param rownr Row # to start from.
250  // @param nrow # of rows in the columns.
251  // @param nif # of IFs
252  // @param timec time(_centroid) col
253  // @param ininterval used to set tolerance on changes in timec.
254  // @param ant1 ID of baseline's antenna 1.
255  // @param ant2 ID of baseline's antenna 2.
256  // @param asMultiSource If false, treat fieldid as unattached + prone to segfault
257  // @param fieldid
258  // @return Last row # with the same time, baseline, and apparent field as rownr.
259  // @warning Assumes that the columns are sorted by time(_centroid), ant1,
260  // ant2 (, field, DDID).
261  static uInt get_tbf_end(
262  const uInt rownr, const uInt nrow, const uInt nif,
263  const ScalarColumn<Double>& timec,
264  const ScalarColumn<Double>& ininterval,
265  const ScalarColumn<Int>& ant1,
266  const ScalarColumn<Int>& ant2,
267  const Bool asMultiSource,
268  const ScalarColumn<Int>& fieldid
269  );
270 };
271 
272 } //# NAMESPACE CASACORE - END
273 
274 #endif
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:47
TableExprNode time(const TableExprNode &node)
Definition: ExprNode.h:1637
void setOverwrite(Bool overwrite)
Main interface class to a read/write table.
Definition: Table.h:149
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:131
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:52
void setWriteStation(Bool writeStation)
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:39
const String _fitsfile
Definition: MSFitsOutput.h:130
const Bool False
Definition: aipstype.h:41
void setWriteSysCal(Bool writeSysCal)
A Table intended to hold astronomical data (a set of Measurements).
fixed-length sequential blocked FITS output
Definition: fitsio.h:228
TableExprNode day(const TableExprNode &node)
Definition: ExprNode.h:1580
String: the storage and methods of handling collections of characters.
Definition: String.h:223
static Bool writeTY(FitsOutput *output, const MeasurementSet &ms, const Table &syscal, const Block< Int > &spwidMap, uInt nrif, Bool combineSpw)
Write the TY table.
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:48