casacore
Loading...
Searching...
No Matches
MSSelector.h
Go to the documentation of this file.
1// # MSSelector.h: this defines MSSelector, which specifies MS selections
2// # Copyright (C) 1997,1998,1999,2000,2001
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts 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_MSSELECTOR_H
27#define MS_MSSELECTOR_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/Vector.h>
31#include <casacore/casa/Arrays/Slice.h>
32#include <casacore/casa/Arrays/Slicer.h>
33#include <casacore/ms/MeasurementSets/MeasurementSet.h>
34#include <casacore/ms/MeasurementSets/StokesConverter.h>
35#include <casacore/ms/MSOper/MSDerivedValues.h>
36#include <casacore/ms/MSSel/MSSelectionKeywords.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40template <class T>
41class ArrayColumn;
42class Record;
43class MSIter;
44
45// <summary>
46// MSSelector specifies selections on a MeasurementSet
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
52// </reviewed>
53
54// <prerequisite>
55// <li> MeasurementSet
56// <li> Record
57// </prerequisite>
58//
59// <etymology>
60// MSSelector's main function is selection of data from a MeasurementSet
61// </etymology>
62//
63// <synopsis>
64// This class is used to select and retrieve data from a MeasurementSet.
65// It allows selections on e.g., time, field, spectral window (all row based),
66// but also on channel and polarization (within a row). It can optionally
67// do polarization conversion, spectral averaging and time averaging on the
68// data retrieved and allows modified data to be written back to the Table.
69// This class also provides the DO interface to the MS Iterator.
70// The ms DO uses this class to allow these operations to be done from glish.
71//
72// <example> <srcblock>
73// MSSelector msSelector(myMS);
74// // select data desc Id 1
75// msSelector.initSelection(1);
76// Vector<String> items(3);
77// // fill in some fields
78// items(0)="field_id";
79// items(1)="time";
80// items(2)="num_chan";
81// // get the range of values for the items specified
82// MSRange msRange(msSelector.selectedTable(),msSelector.spectralWindow());
83// Record range=msRange.range(items);
84// //.. change the ranges as needed
85// // now select with the new range
86// msSelector.select(range);
87// Int nchan=10, start=3, width=1, incr=2;
88// msSelector.selectChannel(nchan,start,width,incr)
89// // get out some data
90// Vector<String> dataItems(3);
91// dataItems(0)="data";
92// dataItems(1)="antenna1";
93// dataItems(2)="antenna2";
94// Record dataRec=msSelector.getData(items);
95// </srcblock></example>
96// </synopsis>
97//
98// <motivation>
99// Selection from an MS is needed in various places. It makes sense to
100// provide a uniform interface for MS selection.
101// </motivation>
102//
103// <thrown>
104// <li>
105// </thrown>
106//
107// <todo asof="1998/12/11">
108// <li> provide access to all other columns in the MS?
109// </todo>
110
112 friend class MSRange;
113
114 public:
116
117 // construct from an MS, the MS will supply the range of the various
118 // parameters that can be selected on.
120
121 // Copy constructor, this will initialize the MS with other's MS
122 MSSelector(const MSSelector& other);
123
124 // Assignment, this will initialize the MS with other's MS
126
128
129 // Change or Set the MS this MSSelector refers to.
131
132 // initialize the selection by specifying, optionally,
133 // the DATA_DESC_IDs.
134 // If you don't specify the dataDescIds and the data shape is constant
135 // all data is selected, if the shape does change, only the first
136 // dataDescId is selected. If you specify a number of dataDescIds
137 // and they all have the same shape, they are all selected, otherwise
138 // only the first is selected. The function returns false if
139 // the selection was limited due to changing data shape.
140 // Use the reset argument to return to the completely unselected ms.
142
143 // As above without the data desc id argument
145
146 // Return the data desc IDs selected
147 Vector<Int> dataDescId() const;
148
149 // Set the mapping from input channels in the DATA column to
150 // output channels. nChan is the number of output channels,
151 // start is the first channel to use, width specifies how wide a
152 // block of channels to average, increment specifies the start of
153 // the next block relative to the start of the current block.
154 // Note: averaging uncalibrated data should be avoided (no bandpass applied)
155 Bool selectChannel(Int nChan, Int start, Int width, Int incr);
156
157 // Specify the output polarization.
158 // Missing input polarizations are assumed to be zero.
159 // This selection/conversion assumes that parallactic angle rotation
160 // is taken care of elsewhere (i.e., results may only be correct for
161 // CORRECTED_DATA and MODEL_DATA conversions, not for the observed DATA)
163
164 // Select the MS based on the selections present in the input record.
165 // The format of this record is the same as that returned by range.
166 // Not all possible items can be selected on, some are quietly ignored.
167 // Correct for one-based indexing if oneBased is True.
168 Bool select(const Record& items, Bool oneBased = False);
169
170 // Select the MS based on the TaQL selection string
171 Bool select(const String& msSelect);
172
173 // Return the data for the items requested, all returned values
174 // will be arrays, the last dimension of these is the table row number.
175 // The data arrays are normally 3D with axes: polarization, frequency, row.
176 // If ifrAxis is set to True, the data arrays returned will be 4D, with
177 // the data being split out along an extra interferometer axis, the
178 // axes will be: polarization, frequency, interferometer and time.
179 // Missing interferometers will be marked flagged.
180 // The order of the interferometers is that specified by the last
181 // select call.
182 // Add a (flagged) gap in the data at every antenna1 change if ifrAxisGap>0.
183 // Use inc > 1 to return data from every inc'th row.
184 // Use average=True to vector average the data along the row or time axis
185 // taking the weights column into account (use selectChannel to average
186 // channels together as well). Note that different interferometers will be
187 // averaged together if ifrAxis is False.
188 // Correct for one-based indexing if oneBased is True.
189 Record getData(const Vector<String>& items, Bool ifrAxis, Int ifrAxisGap = 0, Int inc = 1,
190 Bool average = False, Bool oneBased = False);
191
192 // Put the data for the items provided. Note that only fields corresponding
193 // to actual table columns can be put (i.e., no AMPLITUDEs, IFR_NUMBERs etc)
194 // The data will need to have the correct shape for the column and a last
195 // dimension matching the number of selected rows (or last two dimensions
196 // matching times and interferometers, for data retrieved with ifraxis=T)
197 // Channel selection is supported, but the width parameter has to be 1.
198 Bool putData(const Record& items);
199
200 // Set up an iterator, iterating over the specified columns, with
201 // optional time interval and maximum number of rows to return at once
202 // (the default of zero returns all rows). To keep MSIter from adding
203 // the default sort columns, specify addDefaultSortColumns=False
204 Bool iterInit(const Vector<String>& columns, Double interval, rownr_t maxRows = 0,
205 Bool addDefaultSortColumns = True);
206
207 // Step the iterator, sets the selection to the current table iteration.
208 // Returns false if there is no more data
209 // and sets the selection back to the state before iteration started.
211
212 // (Re)Set the iterator to the first iteration, call this after iterInit.
214
215 // End the iteration (before reaching the last iteration)
216 // and set the selection back to the state before iteration started.
218
219 // Number of rows in selected table
220 rownr_t nrow() const;
221
222 // Return the selected table
223 Table selectedTable() const;
224
225 // Return the selection status of the table
226 Bool selected() const;
227
228 protected:
229 // average and convert data
230 void getAveragedData(Array<Complex>& avData, const Array<Bool>& flag,
231 const ArrayColumn<Complex>& col) const;
232
233 // average and convert float data
234 void getAveragedData(Array<Float>& avData, const Array<Bool>& flag,
235 const ArrayColumn<Float>& col) const;
236
237 // average and convert data, with row Slicer
238 void getAveragedData(Array<Complex>& avData, const Array<Bool>& flag,
239 const ArrayColumn<Complex>& col, const Slicer& rowSlicer) const;
240
241 // average and convert float data, with row Slicer
242 void getAveragedData(Array<Float>& avData, const Array<Bool>& flag, const ArrayColumn<Float>& col,
243 const Slicer& rowSlicer) const;
244
245 // "average" flag, at present all output which has a flagged input is flagged
247
248 // "average" flag, at present all output which has a flagged input is flagged,
249 // with row Slicer
251 const Slicer& rowSlicer) const;
252
253 // "unaverage" flag, distribute the flags back to the channels that went
254 // into the average
256
257 // get the weight, set sigma=True when retrieving sigma's
258 Array<Float> getWeight(const ArrayColumn<Float>& wtCol, Bool sigma = False) const;
259
260 // make the data slicer, pass in the first and the number of correlations
261 // to select
262 void makeSlicer(Int start, Int nCorr) const;
263
264 // reorder from 2d to 1d (removing ifr axis)
266
267 // reorder from 2d to 1d (removing ifr axis)
269
270 // time average the input data, return new flags
271 void timeAverage(Array<Bool>& dataFlags, Array<Complex>& data, const Array<Bool>& flags,
272 const Array<Float>& weights);
273
274 // check if the data description selection has been done & do default
275 // selection if not. Return False if the selection fails.
277
278 private:
279 // The function types
281
282 // The data types
284
285 MeasurementSet ms_p; // the original ms
286 MeasurementSet selms_p; // the selected ms
287 MeasurementSet savems_p; // the saved preselection
305 Matrix<Int64> rowIndex_p; // mapping of rows to time and ifr slots
306 RowNumbers selRows_p; // range of rows from selms_p returned by getData
307 rownr_t startRow_p, maxRow_p; // start and length of range of rows
309};
310inline rownr_t MSSelector::nrow() const { return selms_p.nrow(); }
312inline Table MSSelector::selectedTable() const { return selms_p; }
313inline Bool MSSelector::selected() const { return initSel_p; }
314
315} // namespace casacore
316
317#endif
An iterator class for MeasurementSets.
Definition MSIter.h:159
void reorderFlagRow(Array< Bool > &flagRow)
reorder from 2d to 1d (removing ifr axis)
void getAveragedData(Array< Complex > &avData, const Array< Bool > &flag, const ArrayColumn< Complex > &col) const
average and convert data
rownr_t nrow() const
Number of rows in selected table.
Definition MSSelector.h:310
Matrix< Double > bandwidth_p
Definition MSSelector.h:303
Bool checkSelection()
check if the data description selection has been done & do default selection if not.
void getAveragedData(Array< Complex > &avData, const Array< Bool > &flag, const ArrayColumn< Complex > &col, const Slicer &rowSlicer) const
average and convert data, with row Slicer
void timeAverage(Array< Bool > &dataFlags, Array< Complex > &data, const Array< Bool > &flags, const Array< Float > &weights)
time average the input data, return new flags
Bool putData(const Record &items)
Put the data for the items provided.
Vector< Int > ifrSelection_p
Definition MSSelector.h:302
MSDerivedValues msd_p
Definition MSSelector.h:304
Vector< String > polSelection_p
Definition MSSelector.h:301
Bool selectChannel(Int nChan, Int start, Int width, Int incr)
Set the mapping from input channels in the DATA column to output channels.
Vector< Int > dataDescId() const
Return the data desc IDs selected.
Definition MSSelector.h:311
Array< Float > getWeight(const ArrayColumn< Float > &wtCol, Bool sigma=False) const
get the weight, set sigma=True when retrieving sigma's
void makeSlicer(Int start, Int nCorr) const
make the data slicer, pass in the first and the number of correlations to select
Vector< Int > ifrAxis_p
Definition MSSelector.h:302
void reorderWeight(Array< Float > &weight)
reorder from 2d to 1d (removing ifr axis)
Bool iterNext()
Step the iterator, sets the selection to the current table iteration.
Vector< uInt > polId_p
Definition MSSelector.h:291
Vector< Int > polIndex_p
Definition MSSelector.h:297
Bool selected() const
Return the selection status of the table.
Definition MSSelector.h:313
Record getData(const Vector< String > &items, Bool ifrAxis, Int ifrAxisGap=0, Int inc=1, Bool average=False, Bool oneBased=False)
Return the data for the items requested, all returned values will be arrays, the last dimension of th...
Bool iterOrigin()
(Re)Set the iterator to the first iteration, call this after iterInit.
void getAveragedData(Array< Float > &avData, const Array< Bool > &flag, const ArrayColumn< Float > &col, const Slicer &rowSlicer) const
average and convert float data, with row Slicer
Bool select(const String &msSelect)
Select the MS based on the TaQL selection string.
Array< Bool > getAveragedFlag(Array< Bool > &avFlag, const ArrayColumn< Bool > &col, const Slicer &rowSlicer) const
"average" flag, at present all output which has a flagged input is flagged, with row Slicer
Array< Bool > getAveragedFlag(Array< Bool > &avFlag, const ArrayColumn< Bool > &col) const
"average" flag, at present all output which has a flagged input is flagged
Bool selectPolarization(const Vector< String > &wantedPol)
Specify the output polarization.
Bool iterInit(const Vector< String > &columns, Double interval, rownr_t maxRows=0, Bool addDefaultSortColumns=True)
Set up an iterator, iterating over the specified columns, with optional time interval and maximum num...
void putAveragedFlag(const Array< Bool > &avFlag, ArrayColumn< Bool > &col)
"unaverage" flag, distribute the flags back to the channels that went into the average
MSSelector & operator=(const MSSelector &other)
Assignment, this will initialize the MS with other's MS.
MeasurementSet ms_p
Definition MSSelector.h:285
Vector< Int > dataDescId_p
Definition MSSelector.h:290
Vector< Int > lastDataDescId_p
Definition MSSelector.h:290
void setMS(MeasurementSet &ms)
Change or Set the MS this MSSelector refers to.
MeasurementSet selms_p
Definition MSSelector.h:286
Vector< uInt > spwId_p
Definition MSSelector.h:291
StokesConverter stokesConverter_p
Definition MSSelector.h:300
MSSelector(MeasurementSet &ms)
construct from an MS, the MS will supply the range of the various parameters that can be selected on.
Matrix< Int64 > rowIndex_p
Definition MSSelector.h:305
MSSelector(const MSSelector &other)
Copy constructor, this will initialize the MS with other's MS.
void getAveragedData(Array< Float > &avData, const Array< Bool > &flag, const ArrayColumn< Float > &col) const
average and convert float data
Matrix< Double > chanFreq_p
Definition MSSelector.h:303
Vector< Int > chanSel_p
Definition MSSelector.h:292
Bool initSelection(const Vector< Int > &dataDescIds, Bool reset=False)
initialize the selection by specifying, optionally, the DATA_DESC_IDs.
Bool select(const Record &items, Bool oneBased=False)
Select the MS based on the selections present in the input record.
Table selectedTable() const
Return the selected table.
Definition MSSelector.h:312
friend class MSRange
Definition MSSelector.h:112
MeasurementSet savems_p
Definition MSSelector.h:287
Bool iterEnd()
End the iteration (before reaching the last iteration) and set the selection back to the state before...
Bool initSelection(Bool reset=False)
As above without the data desc id argument.
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
void reset()
Reset the contents of the bins to zero, but retain the current bin definition.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
uInt64 rownr_t
Define the type of a row number in a table.
Definition aipsxtype.h:44