Line data Source code
1 : //# VisIterator.h: Step through the MeasurementEquation by visibility
2 : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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: 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: VisIterator.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $
27 :
28 : #ifndef MSVIS_VISITERATOR_H
29 : #define MSVIS_VISITERATOR_H
30 :
31 : #include <casacore/casa/aips.h>
32 : #include <casacore/casa/Arrays/Matrix.h>
33 : #include <casacore/casa/Arrays/Cube.h>
34 : #include <casacore/casa/Arrays/Slicer.h>
35 : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
36 : #include <casacore/measures/Measures/Stokes.h>
37 : #include <casacore/measures/Measures/MeasConvert.h>
38 : #include <casacore/casa/Quanta/MVDoppler.h>
39 : #include <casacore/measures/Measures/MCDoppler.h>
40 : #include <casacore/measures/Measures/MDoppler.h>
41 : #include <casacore/tables/Tables/ArrayColumn.h>
42 : #include <casacore/tables/Tables/ScalarColumn.h>
43 : #include <casacore/casa/BasicSL/String.h>
44 : #include <casacore/scimath/Mathematics/SquareMatrix.h>
45 : #include <casacore/scimath/Mathematics/RigidVector.h>
46 :
47 : #include <casacore/ms/MSOper/MSDerivedValues.h>
48 : #include <msvis/MSVis/StokesVector.h>
49 : #include <msvis/MSVis/VisImagingWeight.h>
50 : #include <msvis/MSVis/VisibilityIterator.h>
51 : #include <casacore/ms/MeasurementSets/MSIter.h>
52 :
53 : namespace casa { //# NAMESPACE CASA - BEGIN
54 :
55 : //# forward decl
56 : class VisBuffer;
57 :
58 : // <summary>
59 : // ROVisIterator iterates through one or more readonly MeasurementSets
60 : // </summary>
61 :
62 : // <use visibility=export>
63 :
64 : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
65 : // </reviewed>
66 :
67 : // <prerequisite>
68 : // <li> <linkto class="MSIter">MSIter</linkto>
69 : // <li> <linkto class="casacore::MeasurementSet">casacore::MeasurementSet</linkto>
70 : // <li> <linkto class="VisSet">VisSet</linkto>
71 : // </prerequisite>
72 : //
73 : // <etymology>
74 : // The ROVisIterator is a readonly iterator returning visibilities
75 : // </etymology>
76 : //
77 : // <synopsis>
78 : // ROVisIterator provides iteration with various sort orders
79 : // for one or more MSs. It has member functions to retrieve the fields
80 : // commonly needed in synthesis calibration and imaging.
81 : //
82 : // One should use <linkto class="VisBuffer">VisBuffer</linkto>
83 : // to access chunks of data.
84 : // </synopsis>
85 : //
86 : // <example>
87 : // <code>
88 : // //
89 : // </code>
90 : // </example>
91 : //
92 : // <motivation>
93 : // For imaging and calibration you need to access an casacore::MS in some consistent
94 : // order (by field, spectralwindow, time interval etc.). This class provides
95 : // that access.
96 : //
97 : // Unlike ROVisibilityIterator, this supports non-strided in-row selection
98 : // (e.g., of channels and correlations).
99 : // </motivation>
100 : //
101 : // <thrown>
102 : // <li>
103 : // <li>
104 : // </thrown>
105 : //
106 : // <todo asof="1997/05/30">
107 : // <li> cleanup the currently dual interface for visibilities and flags
108 : // <li> sort out what to do with weights when interpolating
109 : // <li> Handle the multi-casacore::MS case like ROVisibilityIterator does.
110 : // </todo>
111 :
112 : class ROVisIteratorImpl;
113 :
114 : class ROVisIterator : public ROVisibilityIterator
115 : {
116 : public:
117 :
118 : // Default constructor - useful only to assign another iterator later
119 : ROVisIterator();
120 :
121 : // Construct from casacore::MS and a casacore::Block of casacore::MS column enums specifying the iteration
122 : // order, if none are specified, time iteration is implicit. An optional
123 : // timeInterval can be given to iterate through chunks of time. The default
124 : // interval of 0 groups all times together. Every 'chunk' of data contains
125 : // all data within a certain time interval (in seconds) and with identical
126 : // values of the other iteration columns (e.g. DATA_DESC_ID and FIELD_ID).
127 : // Using selectChannel(), a number of groups of channels can be requested.
128 : // At present the channel group iteration will always occur before the
129 : // interval iteration.
130 : ROVisIterator(const casacore::MeasurementSet& ms,
131 : const casacore::Block<casacore::Int>& sortColumns,
132 : casacore::Double timeInterval=0);
133 :
134 : ROVisIterator(const casacore::MeasurementSet & ms, const casacore::Block<casacore::Int>& sortColumns,
135 : casacore::Double timeInterval, const ROVisibilityIterator::Factory & factory);
136 :
137 :
138 : // Copy construct. This calls the assignment operator.
139 : ROVisIterator(const ROVisIterator & other);
140 :
141 : // Destructor
142 : ~ROVisIterator();
143 :
144 : // Assignment. Any attached VisBuffers are lost in the assign.
145 : ROVisIterator & operator=(const ROVisIterator &other);
146 :
147 : // Members
148 :
149 : // Advance iterator through data
150 : ROVisIterator & operator++(int);
151 : ROVisIterator & operator++();
152 :
153 : // Return channel numbers in selected VisSet spectrum
154 : // (i.e. disregarding possible selection on the iterator, but
155 : // including the selection set when creating the VisSet)
156 :
157 : casacore::Vector<casacore::Int>& chanIds(casacore::Vector<casacore::Int>& chanids) const;
158 : casacore::Vector<casacore::Int>& chanIds(casacore::Vector<casacore::Int>& chanids,casacore::Int spw) const;
159 :
160 : // Return selected correlation indices
161 : casacore::Vector<casacore::Int>& corrIds(casacore::Vector<casacore::Int>& corrids) const;
162 :
163 : // Return the correlation type (returns casacore::Stokes enums)
164 : casacore::Vector<casacore::Int>& corrType(casacore::Vector<casacore::Int>& corrTypes) const;
165 :
166 : // Set up new chan/corr selection via casacore::Vector<casacore::Slice>
167 : void selectChannel(const casacore::Vector<casacore::Vector<casacore::Slice> >& chansel);
168 : void selectCorrelation(const casacore::Vector<casacore::Vector<casacore::Slice> >& corrsel);
169 :
170 : // Set up/return channel averaging bounds
171 : casacore::Vector<casacore::Matrix<casacore::Int> >& setChanAveBounds(casacore::Float factor, casacore::Vector<casacore::Matrix<casacore::Int> >& bounds);
172 :
173 : // Get selected spws and channel counts
174 : void allSelectedSpectralWindows (casacore::Vector<casacore::Int> & spws, casacore::Vector<casacore::Int> & nvischan);
175 : void lsrFrequency(const casacore::Int& spw, casacore::Vector<casacore::Double>& freq, casacore::Bool& convert, const casacore::Bool ignoreconv=false);
176 :
177 : // The following throws an exception, because this isn't the
178 : // language of channel selection in VisIterator
179 : void getChannelSelection(casacore::Block< casacore::Vector<casacore::Int> >&,
180 : casacore::Block< casacore::Vector<casacore::Int> >&,
181 : casacore::Block< casacore::Vector<casacore::Int> >&,
182 : casacore::Block< casacore::Vector<casacore::Int> >&,
183 : casacore::Block< casacore::Vector<casacore::Int> >&)
184 : { throw(casacore::AipsError("VisIterator::getChannelSelection: you can't do that!")); };
185 :
186 :
187 : // Return number of chans/corrs per spw/pol
188 : casacore::Int numberChan(casacore::Int spw) const;
189 : casacore::Int numberCorr(casacore::Int pol) const;
190 :
191 : protected:
192 :
193 : class Factory : public ROVisibilityIterator::Factory {
194 : public:
195 :
196 0 : Factory (ROVisIterator * vi) : vi_p (vi) {}
197 : VisibilityIteratorReadImpl *
198 : operator() (const asyncio::PrefetchColumns * prefetchColumns,
199 : const casacore::Block<casacore::MeasurementSet>& mss,
200 : const casacore::Block<casacore::Int>& sortColumns,
201 : const casacore::Bool addDefaultSortCols,
202 : casacore::Double timeInterval) const;
203 : private:
204 :
205 : ROVisIterator * vi_p;
206 :
207 : };
208 :
209 : void getDataColumn(DataColumn whichOne, const casacore::Vector<casacore::Vector<casacore::Slice> >& slices, casacore::Cube<casacore::Complex>& data) const;
210 : virtual ROVisIteratorImpl * getReadImpl () const;
211 : };
212 :
213 : // <summary>
214 : // VisIterator iterates through one or more writable MeasurementSets
215 : // </summary>
216 :
217 : // <use visibility=export>
218 :
219 : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
220 : // </reviewed>
221 :
222 : // <prerequisite>
223 : // <li> <linkto class="ROVisIterator">ROVisIterator</linkto>
224 : // </prerequisite>
225 : //
226 : // <etymology>
227 : // The VisIterator is a read/write iterator returning visibilities
228 : // </etymology>
229 : //
230 : // <synopsis>
231 : // VisIterator provides iteration with various sort orders
232 : // for one or more MSs. It has member functions to retrieve the fields
233 : // commonly needed in synthesis calibration and imaging. It is
234 : // derived from the read-only iterator
235 : // <linkto class="ROVisIterator">ROVisIterator</linkto>.
236 : //
237 : // One should use <linkto class="VisBuffer">VisBuffer</linkto>
238 : // to access chunks of data.
239 : // </synopsis>
240 : //
241 : // <example>
242 : // <code>
243 : // //
244 : // </code>
245 : // </example>
246 : //
247 : // <motivation>
248 : // For imaging and calibration you need to access an casacore::MS in some consistent
249 : // order (by field, spectralwindow, time interval etc.). This class provides
250 : // that access.
251 : //
252 : // Unlike ROVisibilityIterator, this supports non-strided in-row selection
253 : // (e.g., of channels).
254 : // </motivation>
255 : //
256 : // #<thrown>
257 : //
258 : // #</thrown>
259 : //
260 : // <todo asof="1997/05/30">
261 : // <li> cleanup the currently dual interface for visibilities and flags
262 : // <li> sort out what to do with weights when interpolating
263 : // <li> Handle the multi-casacore::MS case like VisibilityIterator does.
264 : // </todo>
265 :
266 : class VisIteratorImpl;
267 :
268 : class VisIterator : public ROVisIterator
269 : {
270 : public:
271 :
272 : // Constructors.
273 : // Note: The VisIterator is not initialized correctly by default, you
274 : // need to call origin() before using it to iterate.
275 : VisIterator();
276 : VisIterator(casacore::MeasurementSet & ms, const casacore::Block<casacore::Int>& sortColumns,
277 : casacore::Double timeInterval=0);
278 :
279 : VisIterator(const VisIterator & MSI);
280 :
281 : // Destructor
282 : virtual ~VisIterator();
283 :
284 : VisIterator & operator=(const VisIterator &MSI);
285 :
286 : // Members
287 :
288 : // Advance iterator through data
289 : VisIterator & operator++(int);
290 : VisIterator & operator++();
291 :
292 : // Set/modify the flag row column; dimension casacore::Vector(nrow)
293 : void setFlagRow(const casacore::Vector<casacore::Bool>& rowflags);
294 :
295 : // Set/modify the flags in the data.
296 : // This sets the flags as found in the casacore::MS, casacore::Cube(npol,nchan,nrow),
297 : // where nrow is the number of rows in the current iteration (given by
298 : // nRow()).
299 : void setFlag(const casacore::Cube<casacore::Bool>& flag);
300 :
301 : // Set/modify the visibilities
302 : // This sets the data as found in the casacore::MS, casacore::Cube(npol,nchan,nrow).
303 : void setVis(const casacore::Cube<casacore::Complex>& vis, DataColumn whichOne);
304 :
305 : // Set the visibility and flags, and interpolate from velocities if needed
306 : void setVisAndFlag(const casacore::Cube<casacore::Complex>& vis, const casacore::Cube<casacore::Bool>& flag,
307 : DataColumn whichOne);
308 :
309 : // Set/modify the weightMat
310 : void setWeightMat(const casacore::Matrix<casacore::Float>& wtmat);
311 :
312 : // Set/modify the weightSpectrum
313 : void setWeightSpectrum(const casacore::Cube<casacore::Float>& wtsp);
314 :
315 : protected:
316 :
317 : class Factory : public ROVisibilityIterator::Factory {
318 : public:
319 :
320 0 : Factory (VisIterator * vi) : vi_p (vi) {}
321 : VisibilityIteratorReadImpl *
322 : operator() (const asyncio::PrefetchColumns * prefetchColumns,
323 : const casacore::Block<casacore::MeasurementSet>& mss,
324 : const casacore::Block<casacore::Int>& sortColumns,
325 : const casacore::Bool addDefaultSortCols,
326 : casacore::Double timeInterval) const;
327 : private:
328 :
329 : VisIterator * vi_p;
330 :
331 : };
332 :
333 : virtual void attachColumns(const casacore::Table &t);
334 :
335 : // deals with casacore::Float or casacore::Complex observed data (DATA and FLOAT_DATA).
336 : void putDataColumn(DataColumn whichOne, const casacore::Vector<casacore::Vector<casacore::Slice> >& slices,
337 : const casacore::Cube<casacore::Complex>& data);
338 : void putDataColumn(DataColumn whichOne, const casacore::Cube<casacore::Complex>& data);
339 :
340 : // column access functions
341 : virtual void putCol(casacore::ScalarColumn<casacore::Bool> &column, const casacore::Vector<casacore::Bool> &array);
342 :
343 : virtual void putCol(casacore::ArrayColumn<casacore::Bool> &column, const casacore::Array<casacore::Bool> &array);
344 : virtual void putCol(casacore::ArrayColumn<casacore::Float> &column, const casacore::Array<casacore::Float> &array);
345 : virtual void putCol(casacore::ArrayColumn<casacore::Complex> &column, const casacore::Array<casacore::Complex> &array);
346 :
347 : virtual void putCol(casacore::ArrayColumn<casacore::Bool> &column, const casacore::Slicer &slicer, const casacore::Array<casacore::Bool> &array);
348 : virtual void putCol(casacore::ArrayColumn<casacore::Float> &column, const casacore::Slicer &slicer, const casacore::Array<casacore::Float> &array);
349 : virtual void putCol(casacore::ArrayColumn<casacore::Complex> &column, const casacore::Slicer &slicer, const casacore::Array<casacore::Complex> &array);
350 :
351 : VisIteratorImpl * getImpl () const;
352 : };
353 :
354 :
355 :
356 :
357 : } //# NAMESPACE CASA - END
358 :
359 : #endif
|