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>
42class ScalarColumn;
43class Table;
44template <class T>
45class Block;
46// <summary>
47// Write a MeasurementSet to a random group uvfits file.
48// </summary>
49
51 public:
52 // @param fitsfile Output filename
53 // @param ms input
54 // @param column specifies which "data" column to write
55 // ("observed", "calibrated", "model")
56 MSFitsOutput(const String& fitsfile, const MeasurementSet& ms, const String& column);
57
58 // @param startChan 1st channel
59 // @param nchan # of channels
60 // @param stepChan # of channels to stride by
61 // @param avgChan average every N channels
62 void setChannelInfo(Int startChan, Int nchan, Int stepChan, Int avgChan);
63
64 // @param writeSysCal whether to write the system calibration table
65 void setWriteSysCal(Bool writeSysCal);
66
67 // @param asMultiSource If true a multi-source UVFits file is written.
68 void setAsMultiSource(Bool asMultiSource);
69
70 // @param combineSpw If true it attempts to write the spectral windows as
71 // IFs. This is necessary for many aips tasks, and
72 // for difmap.
73 void setCombineSpw(Bool combineSpw);
74
75 // @param writeStation If true uses pad instead of antenna names.
76 void setWriteStation(Bool writeStation);
77
78 void setSensitivity(Double sensitivity);
79
80 // @param padWithFlags If true and combineSpw==true, fill spws with flags
81 // as needed to fit the IF structure. Does not yet
82 // support spws with different shapes.
83 void setPadWitFlags(Bool padWithFlags);
84
86
87 // @param overwrite overwrite existing file?
88 void setOverwrite(Bool overwrite);
89
90 // write the uvfits file.
91 void write() const;
92
93 // Convert a MeasurementSet to random group UVFITS.
94 // @param fitsfile Output filename
95 // @param ms input
96 // @param column specifies which "data" column to write
97 // ("observed", "calibrated", "model")
98 // @param startchan 1st channel
99 // @param nchan # of channels
100 // @param stepchan # of channels to stride by
101 // @param writeSysCal whether to write the system calibration table
102 // @param asMultiSource If true a multi-source UVFits file is written.
103 // @param combineSpw If true it attempts to write the spectral windows as
104 // IFs. This is necessary for many aips tasks, and
105 // for difmap.
106 // @param writeStation If true uses pad instead of antenna names.
107 // @param sensitivity
108 // @param padWithFlags If true and combineSpw==true, fill spws with flags
109 // as needed to fit the IF structure. Does not yet
110 // support spws with different shapes.
111 // @param avgchan average every N channels
112 // @param fieldNumber field number
113 // @param overwrite overwrite existing file?
114 static Bool writeFitsFile(const String& fitsfile, const MeasurementSet& ms, const String& column,
115 Int startchan = 0, Int nchan = 1, Int stepchan = 1,
116 Bool writeSysCal = False, Bool asMultiSource = False,
117 Bool combineSpw = False, Bool writeStation = False,
118 Double sensitivity = 1.0, const Bool padWithFlags = false,
119 Int avgchan = 1, uInt fieldNumber = 0, Bool overwrite = False);
120
121 private:
128
129 // Write the main table.
130 // @param refPixelFreq
131 // @param refFreq
132 // @param chanbw
133 // @param outFITSFile
134 // @param spwidMap spwidMap[inp_spw] = output_spw, if inp_spw is selected
135 // -1 otherwise.
136 // @param nrspw # of selected spws.
137 // @param fieldidMap fieldidMap[inp_fld] = output_fld, if inp_fld is selected
138 // -1 otherwise.
139 // @param asMultiSource If true, write a multisource UVFITS file.
140 std::shared_ptr<FitsOutput> _writeMain(Int& refPixelFreq, Double& refFreq, Double& chanbw,
141 const String& outFITSFile, const Block<Int>& spwidMap,
142 Int nrspw, const Block<Int>& fieldidMap,
143 Bool asMultiSource) const;
144
145 // Write the FQ table.
146 // If combineSpw is True, all spectral-windows are written in one
147 // row of the FITS table.
148 static Bool _writeFQ(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
149 const Block<Int>& spwidMap, Int nrspw, Double refFreq, Int refPixelFreq,
150 Double chanbw, Bool combineSpw, Int chanstart = 0, Int nchan = -1,
151 Int chanstep = 1, Int avgchan = 1);
152
153 // Write the AN table.
154 static Bool _writeAN(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms, Double refFreq,
155 Bool writeStation);
156
157 // Write the SU table.
158 static Bool _writeSU(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
159 const Block<Int>& fieldidMap, Int nrfield, const Block<Int>& spwidMap,
160 Int nrspw);
161
162 // Write the TY table.
163 static Bool _writeTY(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
164 const Table& syscal, const Block<Int>& spwidMap, uInt nrif, Bool combineSpw);
165
166 // Write the GC table.
167 static Bool _writeGC(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
168 const Table& syscal, const Block<Int>& spwidMap, uInt nrif, Bool combineSpw,
169 Double sensitivity, Int refPixelFreq, Double refFreq, Double chanbw);
170
171 // Write the WX table.
172 static Bool _writeWX(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms);
173
174 // Write the SY table.
175 static Bool _writeSY(std::shared_ptr<FitsOutput> output, const MeasurementSet& ms,
176 Table& syspower, Int nspw, const Block<Int>& spwIDMap, Bool combineSpw);
177
178 // Convert time to day and fraction.
179 static void timeToDay(Int& day, Double& dayFraction, Double time);
180
181 // Get the time and hourangle from the MS at the given row.
182 // It uses the field-id and observation-id to calculate the hourangle.
183 static void getStartHA(Double& startTime, Double& startHA, const MeasurementSet& ms, uInt rownr);
184
185 // Discern the antenna numbers that go into UVFITS
186 static void _handleAntNumbers(const MeasurementSet& ms, Vector<Int>& antnumbers);
187
188 // Handle the SYSCAL table.
189 // It skips the entries not needed and sorts it in the correct order.
190 static Table handleSysCal(const MeasurementSet& ms, const Vector<Int>& spwids, Bool isSubset);
191
192 // Determine which ids are selected in the main table
193 // (used for fields and spectral-window).
194 // @param map (Really an output here, not an input.)
195 // spwidMap[inp_id] = output_id, if inp_id is selected
196 // -1 otherwise.
197 // @param selids (Really an output here, not an input.)
198 // A list of the selected input IDs.
199 // @param allids (Really is an input, not an output!)
200 // IDs to consider.
201 // @return number of selected IDs in allids
202
203 static Int _makeIdMap(Block<Int>& map, Vector<Int>& selids, const Vector<Int>& allids);
204
205 // Find the end of a group of rows with the same
206 // time(_centroid) (within 0.25 * ininterval(rownr)),
207 // baseline #,
208 // and, if asMultiSource, field ID.
209 // @param rownr Row # to start from.
210 // @param nrow # of rows in the columns.
211 // @param nif # of IFs
212 // @param timec time(_centroid) col
213 // @param ininterval used to set tolerance on changes in timec.
214 // @param ant1 ID of baseline's antenna 1.
215 // @param ant2 ID of baseline's antenna 2.
216 // @param asMultiSource If false, treat fieldid as unattached + prone to segfault
217 // @param fieldid
218 // @return Last row # with the same time, baseline, and apparent field as rownr.
219 // @warning Assumes that the columns are sorted by time(_centroid), ant1,
220 // ant2 (, field, DDID).
221 static uInt get_tbf_end(const uInt rownr, const uInt nrow, const uInt nif,
222 const ScalarColumn<Double>& timec, const ScalarColumn<Double>& ininterval,
223 const ScalarColumn<Int>& ant1, const ScalarColumn<Int>& ant2,
224 const Bool asMultiSource, const ScalarColumn<Int>& fieldid);
225
226 static void _checkReceptorAngles(const Vector<Quantity>& ra0, Vector<Quantity>& ra1, Int antnum);
227};
228
229} // namespace casacore
230
231#endif
fixed-length sequential blocked FITS output
Definition fitsio.h:242
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
TableExprNode time(const TableExprNode &node)
Definition ExprNode.h:1368
unsigned int uInt
Definition aipstype.h:49
TableExprNode day(const TableExprNode &node)
Definition ExprNode.h:1329
Int fieldNumber(const String &fieldName) const override
Get the field number from the field name.
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