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> class ArrayColumn;
41class Record;
42class MSIter;
43
44// <summary>
45// MSSelector specifies selections on a MeasurementSet
46// </summary>
47
48// <use visibility=export>
49
50// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
51// </reviewed>
52
53// <prerequisite>
54// <li> MeasurementSet
55// <li> Record
56// </prerequisite>
57//
58// <etymology>
59// MSSelector's main function is selection of data from a MeasurementSet
60// </etymology>
61//
62// <synopsis>
63// This class is used to select and retrieve data from a MeasurementSet.
64// It allows selections on e.g., time, field, spectral window (all row based),
65// but also on channel and polarization (within a row). It can optionally
66// do polarization conversion, spectral averaging and time averaging on the
67// data retrieved and allows modified data to be written back to the Table.
68// This class also provides the DO interface to the MS Iterator.
69// The ms DO uses this class to allow these operations to be done from glish.
70//
71// <example> <srcblock>
72// MSSelector msSelector(myMS);
73// // select data desc Id 1
74// msSelector.initSelection(1);
75// Vector<String> items(3);
76// // fill in some fields
77// items(0)="field_id";
78// items(1)="time";
79// items(2)="num_chan";
80// // get the range of values for the items specified
81// MSRange msRange(msSelector.selectedTable(),msSelector.spectralWindow());
82// Record range=msRange.range(items);
83// //.. change the ranges as needed
84// // now select with the new range
85// msSelector.select(range);
86// Int nchan=10, start=3, width=1, incr=2;
87// msSelector.selectChannel(nchan,start,width,incr)
88// // get out some data
89// Vector<String> dataItems(3);
90// dataItems(0)="data";
91// dataItems(1)="antenna1";
92// dataItems(2)="antenna2";
93// Record dataRec=msSelector.getData(items);
94// </srcblock></example>
95// </synopsis>
96//
97// <motivation>
98// Selection from an MS is needed in various places. It makes sense to
99// provide a uniform interface for MS selection.
100// </motivation>
101//
102// <thrown>
103// <li>
104// </thrown>
105//
106// <todo asof="1998/12/11">
107// <li> provide access to all other columns in the MS?
108// </todo>
109
111{
112 friend class MSRange;
113
114public:
115
117
118 // construct from an MS, the MS will supply the range of the various
119 // parameters that can be selected on.
121
122 // Copy constructor, this will initialize the MS with other's MS
123 MSSelector(const MSSelector& other);
124
125 // Assignment, this will initialize the MS with other's MS
127
129
130 // Change or Set the MS this MSSelector refers to.
132
133 // initialize the selection by specifying, optionally,
134 // the DATA_DESC_IDs.
135 // If you don't specify the dataDescIds and the data shape is constant
136 // all data is selected, if the shape does change, only the first
137 // dataDescId is selected. If you specify a number of dataDescIds
138 // and they all have the same shape, they are all selected, otherwise
139 // only the first is selected. The function returns false if
140 // the selection was limited due to changing data shape.
141 // Use the reset argument to return to the completely unselected ms.
142 Bool initSelection(const Vector<Int>& dataDescIds, Bool reset=False);
143
144 // As above without the data desc id argument
146
147 // Return the data desc IDs selected
148 Vector<Int> dataDescId() const;
149
150 // Set the mapping from input channels in the DATA column to
151 // output channels. nChan is the number of output channels,
152 // start is the first channel to use, width specifies how wide a
153 // block of channels to average, increment specifies the start of
154 // the next block relative to the start of the current block.
155 // Note: averaging uncalibrated data should be avoided (no bandpass applied)
156 Bool selectChannel(Int nChan, Int start, Int width, Int incr);
157
158 // Specify the output polarization.
159 // Missing input polarizations are assumed to be zero.
160 // This selection/conversion assumes that parallactic angle rotation
161 // is taken care of elsewhere (i.e., results may only be correct for
162 // CORRECTED_DATA and MODEL_DATA conversions, not for the observed DATA)
164
165 // Select the MS based on the selections present in the input record.
166 // The format of this record is the same as that returned by range.
167 // Not all possible items can be selected on, some are quietly ignored.
168 // Correct for one-based indexing if oneBased is True.
169 Bool select(const Record& items, Bool oneBased=False);
170
171 // Select the MS based on the TaQL selection string
172 Bool select(const String& msSelect);
173
174 // Return the data for the items requested, all returned values
175 // will be arrays, the last dimension of these is the table row number.
176 // The data arrays are normally 3D with axes: polarization, frequency, row.
177 // If ifrAxis is set to True, the data arrays returned will be 4D, with
178 // the data being split out along an extra interferometer axis, the
179 // axes will be: polarization, frequency, interferometer and time.
180 // Missing interferometers will be marked flagged.
181 // The order of the interferometers is that specified by the last
182 // select call.
183 // Add a (flagged) gap in the data at every antenna1 change if ifrAxisGap>0.
184 // Use inc > 1 to return data from every inc'th row.
185 // Use average=True to vector average the data along the row or time axis
186 // taking the weights column into account (use selectChannel to average
187 // channels together as well). Note that different interferometers will be
188 // averaged together if ifrAxis is False.
189 // Correct for one-based indexing if oneBased is True.
190 Record getData(const Vector<String>& items, Bool ifrAxis,
191 Int ifrAxisGap=0, Int inc=1,
192 Bool average=False, Bool oneBased=False);
193
194 // Put the data for the items provided. Note that only fields corresponding
195 // to actual table columns can be put (i.e., no AMPLITUDEs, IFR_NUMBERs etc)
196 // The data will need to have the correct shape for the column and a last
197 // dimension matching the number of selected rows (or last two dimensions
198 // matching times and interferometers, for data retrieved with ifraxis=T)
199 // Channel selection is supported, but the width parameter has to be 1.
200 Bool putData(const Record& items);
201
202 // Set up an iterator, iterating over the specified columns, with
203 // optional time interval and maximum number of rows to return at once
204 // (the default of zero returns all rows). To keep MSIter from adding
205 // the default sort columns, specify addDefaultSortColumns=False
207 Double interval, rownr_t maxRows=0,
208 Bool addDefaultSortColumns=True);
209
210 // Step the iterator, sets the selection to the current table iteration.
211 // Returns false if there is no more data
212 // and sets the selection back to the state before iteration started.
214
215 // (Re)Set the iterator to the first iteration, call this after iterInit.
217
218 // End the iteration (before reaching the last iteration)
219 // and set the selection back to the state before iteration started.
221
222 // Number of rows in selected table
223 rownr_t nrow() const;
224
225 // Return the selected table
226 Table selectedTable() const;
227
228 // Return the selection status of the table
229 Bool selected() const;
230
231protected:
232 // average and convert data
233 void getAveragedData(Array<Complex>& avData, const Array<Bool>& flag,
234 const ArrayColumn<Complex>& col) const;
235
236 // average and convert float data
237 void getAveragedData(Array<Float>& avData, const Array<Bool>& flag,
238 const ArrayColumn<Float>& col) const;
239
240 // average and convert data, with row Slicer
241 void getAveragedData(Array<Complex>& avData, const Array<Bool>& flag,
242 const ArrayColumn<Complex>& col,
243 const Slicer & rowSlicer) const;
244
245 // average and convert float data, with row Slicer
246 void getAveragedData(Array<Float>& avData, const Array<Bool>& flag,
247 const ArrayColumn<Float>& col,
248 const Slicer & rowSlicer) const;
249
250 // "average" flag, at present all output which has a flagged input is flagged
252 const ArrayColumn<Bool>& col) const;
253
254 // "average" flag, at present all output which has a flagged input is flagged,
255 // with row Slicer
257 const ArrayColumn<Bool>& col,
258 const Slicer& rowSlicer) const;
259
260 // "unaverage" flag, distribute the flags back to the channels that went
261 // into the average
262 void putAveragedFlag(const Array<Bool>& avFlag,
263 ArrayColumn<Bool>& col);
264
265 // get the weight, set sigma=True when retrieving sigma's
267 Bool sigma=False) const;
268
269 // make the data slicer, pass in the first and the number of correlations
270 // to select
271 void makeSlicer(Int start, Int nCorr) const;
272
273 // reorder from 2d to 1d (removing ifr axis)
275
276 // reorder from 2d to 1d (removing ifr axis)
278
279 // time average the input data, return new flags
280 void timeAverage(Array<Bool>& dataFlags, Array<Complex>& data,
281 const Array<Bool>& flags, const Array<Float>& weights);
282
283 // check if the data description selection has been done & do default
284 // selection if not. Return False if the selection fails.
286
287private:
288 // The function types
290
291 // The data types
293
294 MeasurementSet ms_p; // the original ms
295 MeasurementSet selms_p; // the selected ms
296 MeasurementSet savems_p; // the saved preselection
314 Matrix<Int64> rowIndex_p; // mapping of rows to time and ifr slots
315 RowNumbers selRows_p; // range of rows from selms_p returned by getData
316 rownr_t startRow_p, maxRow_p; // start and length of range of rows
318
319};
320inline rownr_t MSSelector::nrow() const { return selms_p.nrow();}
323inline Bool MSSelector::selected() const {return initSel_p;}
324
325
326} //# NAMESPACE CASACORE - END
327
328#endif
329
An iterator class for MeasurementSets.
Definition MSIter.h:160
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:320
Matrix< Double > bandwidth_p
Definition MSSelector.h:312
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:311
MSDerivedValues msd_p
Definition MSSelector.h:313
Vector< String > polSelection_p
Definition MSSelector.h:310
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:321
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:311
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:300
Vector< Int > polIndex_p
Definition MSSelector.h:306
Bool selected() const
Return the selection status of the table.
Definition MSSelector.h:323
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:294
Vector< Int > dataDescId_p
Definition MSSelector.h:299
Vector< Int > lastDataDescId_p
Definition MSSelector.h:299
void setMS(MeasurementSet &ms)
Change or Set the MS this MSSelector refers to.
MeasurementSet selms_p
Definition MSSelector.h:295
Vector< uInt > spwId_p
Definition MSSelector.h:300
StokesConverter stokesConverter_p
Definition MSSelector.h:309
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:314
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:312
Vector< Int > chanSel_p
Definition MSSelector.h:301
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:322
MeasurementSet savems_p
Definition MSSelector.h:296
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:223
rownr_t nrow() const
Get the number of rows.
Definition Table.h:1176
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
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