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