Line data Source code
1 : //# SubMS.h: this defines SubMS which creates a subset of an casacore::MS with some
2 : //# transformation
3 : //# Copyright (C) 1997,1998,1999,2000,2001,2003
4 : //# Associated Universities, Inc. Washington DC, USA.
5 : //#
6 : //# This library is free software; you can redistribute it and/or modify it
7 : //# under the terms of the GNU Library General Public License as published by
8 : //# the Free Software Foundation; either version 2 of the License, or (at your
9 : //# option) any later version.
10 : //#
11 : //# This library is distributed in the hope that it will be useful, but WITHOUT
12 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 : //# License for more details.
15 : //#
16 : //# You should have received a copy of the GNU Library General Public License
17 : //# along with this library; if not, write to the Free Software Foundation,
18 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 : //#
20 : //# Correspondence concerning AIPS++ should be addressed as follows:
21 : //# Internet email: casa-feedback@nrao.edu.
22 : //# Postal address: AIPS++ Project Office
23 : //# National Radio Astronomy Observatory
24 : //# 520 Edgemont Road
25 : //# Charlottesville, VA 22903-2475 USA
26 : //#
27 : //#
28 : //# $Id$
29 : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
30 : #include <casacore/ms/MeasurementSets/MSColumns.h>
31 : #include <casacore/ms/MeasurementSets/MSMainEnums.h>
32 : //#include <msvis/MSVis/VisIterator.h>
33 : #include <msvis/MSVis/VisBufferComponents.h>
34 : #include <casacore/casa/aips.h>
35 : #include <casacore/casa/Arrays/Array.h>
36 : #include <casacore/casa/Arrays/Vector.h>
37 : #include <casacore/tables/Tables/Table.h>
38 : //#include <casa/Utilities/CountedPtr.h>
39 : #include <map>
40 : #include <set>
41 : #include <vector>
42 : #include <casacore/scimath/Mathematics/InterpolateArray1D.h>
43 :
44 :
45 : #ifndef MSVIS_SUBMS_H
46 :
47 : namespace casacore{
48 :
49 : class MSSelection; // #include <ms/MSSel/MSSelection.h>
50 : template<class T> class ArrayColumn;
51 : class Table;
52 : }
53 :
54 : namespace casa { //# NAMESPACE CASA - BEGIN
55 :
56 : #define MSVIS_SUBMS_H
57 :
58 : namespace subms {
59 : // Returns wt**-0.5 or -1, depending on whether wt is positive.
60 : // NOT a member function, so it can be easily passed to other functions
61 : // (i.e. arrayTransformInPlace).
62 : double wtToSigma(casacore::Double wt);
63 : double sigToWeight(casacore::Double sig);
64 : }
65 :
66 : // forward declaration
67 : class MSTransformManager;
68 :
69 : // <summary>
70 : // SubMS provides functionalities to make a subset of an existing MS
71 : // </summary>
72 :
73 : // <visibility=export>
74 :
75 : // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
76 : // </reviewed>
77 :
78 : // <prerequisite>
79 : // <li> MeasurementSet
80 : // </prerequisite>
81 : //
82 : // <etymology>
83 : // SubMS ...from the SUBset of an MS
84 : // </etymology>
85 : //
86 : // <synopsis>
87 : // The order of operations (as in ms::split()) is:
88 : // ctor
89 : // setmsselect
90 : // selectTime
91 : // makeSubMS
92 : // </synopsis>
93 :
94 : // These forward declarations are so the corresponding .h files don't have to
95 : // be included in this .h file, but it's only worth it if a lot of other files
96 : // include this file.
97 : class VBRemapper;
98 :
99 : // // These typedefs are necessary because a<b::c> doesn't work.
100 : // typedef std::vector<casacore::uInt> uivector;
101 : // struct uIntCmp
102 : // {
103 : // bool operator()(const casacore::uInt i1, const casacore::uInt i2) const
104 : // {
105 : // return i1 < i2;
106 : // }
107 : // };
108 : // typedef std::map<const casacore::uInt, uivector, uIntCmp> ui2vmap;
109 :
110 : casacore::Bool isAllColumns(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
111 :
112 : class SubMS
113 : {
114 :
115 : // jagonzal: Allow TransformVisDataHandler to access protected methods and members of this class
116 : friend class MSTransformManager;
117 :
118 : public:
119 :
120 : enum RegriddingAlternatives {
121 : useFFTShift = -100, // needs input and output grid to have the same number of channels and be equidistant in freq.
122 : useLinIntThenFFTShift // for the case the input grid is not equidistant in frequency but the output grid is
123 : };
124 :
125 : enum asdmStManUseAlternatives {
126 : DONT,
127 : USE_FOR_DATA,
128 : USE_FOR_DATA_WEIGHT_SIGMA_FLAG
129 : };
130 :
131 : SubMS(casacore::String& theMS, casacore::Table::TableOption option = casacore::Table::Old);
132 :
133 : // construct from an MS
134 : SubMS(casacore::MeasurementSet& ms);
135 :
136 : virtual ~SubMS();
137 :
138 : // Change or Set the casacore::MS this casacore::MSSelector refers to.
139 : void setMS(casacore::MeasurementSet& ms);
140 :
141 : // Returns the set (possibly empty) of spectral windows that are in spwv but
142 : // not listed in ms's DATA_DESCRIPTION subtable. (This happens with certain
143 : // calibration/hardware setups.)
144 : static std::set<casacore::Int> findBadSpws(casacore::MeasurementSet& ms, casacore::Vector<casacore::Int> spwv);
145 :
146 : // Select spw and channels for each spw.
147 : // This is the version used by split. It returns true on success and false
148 : // on failure.
149 : casacore::Bool selectSpw(const casacore::String& spwstr, const casacore::Vector<casacore::Int>& steps);
150 :
151 : // This older version is used by the older version of setmsselect().
152 : void selectSpw(casacore::Vector<casacore::Int> spw, casacore::Vector<casacore::Int> nchan, casacore::Vector<casacore::Int> start,
153 : casacore::Vector<casacore::Int> step);
154 :
155 : // Setup polarization selection (for now, only from available correlations -
156 : // no casacore::Stokes transformations.)
157 : casacore::Bool selectCorrelations(const casacore::String& corrstr);
158 :
159 : //select casacore::Time and time averaging or regridding
160 : //void selectTime();
161 :
162 : //select stuff using msselection syntax ...time is left out
163 : // call it separately with timebin
164 : // This version returns a success value, and does not need nchan, start, and
165 : // step. It is used by split.
166 : casacore::Bool setmsselect(const casacore::String& spw="", const casacore::String& field="",
167 : const casacore::String& baseline="", const casacore::String& scan="",
168 : const casacore::String& uvrange="", const casacore::String& taql="",
169 : const casacore::Vector<casacore::Int>& step=casacore::Vector<casacore::Int> (1,1),
170 : const casacore::String& subarray="", const casacore::String& correlation="",
171 : const casacore::String& intent="", const casacore::String& obs="");
172 :
173 : // This older version does not return a success value, and does need nchan,
174 : // start, and step. It is used elsewhere (i.e. ImagerMultiMS).
175 : void setmsselect(const casacore::String& spw, const casacore::String& field,
176 : const casacore::String& baseline, const casacore::String& scan,
177 : const casacore::String& obs, const casacore::String& uvrange,
178 : const casacore::String& taql, const casacore::Vector<casacore::Int>& nchan,
179 : const casacore::Vector<casacore::Int>& start, const casacore::Vector<casacore::Int>& step,
180 : const casacore::String& subarray, const casacore::String& intent="");
181 :
182 : // Select source or field
183 : casacore::Bool selectSource(const casacore::Vector<casacore::Int>& fieldid);
184 :
185 : // Select Antennas to split out
186 0 : void selectAntenna(const casacore::Vector<casacore::Int>& antennaids,
187 : const casacore::Vector<casacore::String>& antennaSel)
188 : {
189 0 : antennaSel_p = pickAntennas(antennaId_p, antennaSelStr_p,
190 : antennaids, antennaSel);
191 0 : }
192 : static casacore::Bool pickAntennas(casacore::Vector<casacore::Int>& selected_antennaids,
193 : casacore::Vector<casacore::String>& selected_antenna_strs,
194 : const casacore::Vector<casacore::Int>& antennaids,
195 : const casacore::Vector<casacore::String>& antennaSel);
196 :
197 : // Select array IDs to use.
198 0 : void selectArray(const casacore::String& subarray) {arrayExpr_p = subarray;}
199 :
200 : //select time parameters
201 : void selectTime(casacore::Double timeBin=-1.0, casacore::String timerng="");
202 :
203 : //void selectSource(casacore::Vector<casacore::String> sourceid);
204 :
205 : //Method to set if a phase Center rotation is needed
206 : //void setPhaseCenter(casacore::Int fieldid, casacore::MDirection& newPhaseCenter);
207 :
208 : // Sets the polynomial order for continuum fitting to fitorder.
209 : // If < 0, continuum subtraction is not done.
210 : void setFitOrder(casacore::Int fitorder, casacore::Bool advise=true);
211 : // Set the selection string for line-free channels.
212 : void setFitSpw(const casacore::String& fitspw) {fitspw_p = fitspw;}
213 : // Selection string for output channels if doing continuum subtraction.
214 : void setFitOutSpw(const casacore::String& fitoutspw) {fitoutspw_p = fitoutspw;}
215 :
216 : //Method to make the subMS
217 : //
218 : //TileShape of size 1 can have 2 values [0], and [1] ...these are used in to
219 : //determine the tileshape by using MSTileLayout. Otherwise it has to be a
220 : //vector size 3 e.g [4, 15, 351] => a tile shape of 4 stokes, 15 channels 351
221 : //rows.
222 : //
223 : // combine sets combine_p. (Columns to ignore while time averaging.)
224 : //
225 : casacore::Bool makeSubMS(casacore::String& submsname, casacore::String& whichDataCol,
226 : const casacore::Vector<casacore::Int>& tileShape=casacore::Vector<casacore::Int>(1, 0),
227 : const casacore::String& combine="");
228 :
229 : //Method to make a scratch subMS and even in memory if posssible
230 : //Useful if temporary subselection/averaging is necessary
231 : // It'll be in memory if the basic output ms is less than half of
232 : // memory reported by casacore::HostInfo unless forced to by user...
233 : virtual casacore::MeasurementSet* makeScratchSubMS(const casacore::Vector<casacore::MS::PredefinedColumns>& whichDataCols,
234 : const casacore::Bool forceInMemory=false);
235 : // In this form whichDataCol gets passed to parseColumnNames().
236 : virtual casacore::MeasurementSet* makeScratchSubMS(const casacore::String& whichDataCol,
237 : const casacore::Bool forceInMemory=false);
238 :
239 : // This sets up a default new ms
240 : // Declared static as it can be (and is) called directly outside of SubMS.
241 : // Therefore it is not dependent on any member variable.
242 : static casacore::MeasurementSet* setupMS(const casacore::String& msname, const casacore::Int nchan,
243 : const casacore::Int npol, const casacore::String& telescop,
244 : const casacore::Vector<casacore::MS::PredefinedColumns>& colNamesTok,
245 : const casacore::Int obstype=0,
246 : const casacore::Bool compress=false,
247 : const asdmStManUseAlternatives asdmStManUse=DONT);
248 :
249 : // Same as above except allowing manual tileshapes
250 : static casacore::MeasurementSet* setupMS(const casacore::String& msname, const casacore::Int nchan,
251 : const casacore::Int npol,
252 : const casacore::Vector<casacore::MS::PredefinedColumns>& colNamesTok,
253 : const casacore::Vector<casacore::Int>& tileShape=casacore::Vector<casacore::Int>(1,0),
254 : const casacore::Bool compress=false,
255 : const asdmStManUseAlternatives asdmStManUse=DONT);
256 :
257 :
258 : // Add optional columns to outTab if present in inTab and possColNames.
259 : // beLazy should only be true if outTab is in its default state.
260 : // Returns the number of added columns.
261 : static casacore::uInt addOptionalColumns(const casacore::Table& inTab, casacore::Table& outTab,
262 : const casacore::Bool beLazy=false);
263 :
264 : // Like casacore::TableCopy::copyRows, but by column.
265 : static casacore::Bool copyCols(casacore::Table& out, const casacore::Table& in, const casacore::Bool flush=true);
266 :
267 : // A customized version of casacore::MS::createDefaultSubtables().
268 : static void createSubtables(casacore::MeasurementSet& ms, casacore::Table::TableOption option);
269 :
270 : // Declared static because it's used in setupMS(). Therefore it can't use
271 : // any member variables. It is also used in MSFixvis.cc.
272 : // colNameList is internally upcased, so it is not const or passed by reference.
273 : static const casacore::Vector<casacore::MS::PredefinedColumns>& parseColumnNames(casacore::String colNameList);
274 : // This version uses the casacore::MeasurementSet to check what columns are present,
275 : // i.e. it makes col=="all" smarter, and it is not necessary to call
276 : // verifyColumns() after calling this. Unlike the other version, it knows
277 : // about FLOAT_DATA and LAG_DATA. It throws an exception if a
278 : // _specifically_ requested column is absent.
279 : static const casacore::Vector<casacore::MS::PredefinedColumns>& parseColumnNames(casacore::String colNameList,
280 : const casacore::MeasurementSet& ms);
281 :
282 : void verifyColumns(const casacore::MeasurementSet& ms, const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
283 :
284 : // The output casacore::MS must have (at least?) 1 of DATA, FLOAT_DATA, or LAG_DATA.
285 : // MODEL_DATA or CORRECTED_DATA will be converted to DATA if necessary.
286 166 : static casacore::Bool mustConvertToData(const casacore::uInt nTok,
287 : const casacore::Vector<casacore::MS::PredefinedColumns>& datacols)
288 : {
289 294 : return (nTok == 1) && (datacols[0] != casacore::MS::FLOAT_DATA) &&
290 294 : (datacols[0] != casacore::MS::LAG_DATA);
291 : }
292 :
293 : static casacore::Bool sepFloat(const casacore::Vector<casacore::MS::PredefinedColumns>& anyDataCols,
294 : casacore::Vector<casacore::MS::PredefinedColumns>& complexDataCols);
295 :
296 : // Fills outToIn[pol] with a map from output correlation index to input
297 : // correlation index, for each input polID pol.
298 : // It does not yet check the appropriateness of the correlation selection
299 : // string, so ignore the return value for now. outToIn[pol] defaults to
300 : // an empty casacore::Vector if no correlations are selected for pol.
301 : // That is not the same as the default "select everything in ms".
302 : static casacore::Bool getCorrMaps(casacore::MSSelection& mssel, const casacore::MeasurementSet& ms,
303 : casacore::Vector<casacore::Vector<casacore::Int> >& outToIn,
304 : const casacore::Bool areSelecting=false);
305 :
306 : // Replaces col[i] with mapper[col[i]] for each element of col.
307 : // Does NOT check whether mapper[col[i]] is defined, but it does return
308 : // right away (i.e. a no-op) if mapper is empty.
309 : static void remap(casacore::Vector<casacore::Int>& col, const casacore::Vector<casacore::Int>& mapper);
310 : static void remap(casacore::Vector<casacore::Int>& col, const std::map<casacore::Int, casacore::Int>& mapper);
311 :
312 : // Transform spectral data to different reference frame,
313 : // optionally regrid the frequency channels
314 : // return values: -1 = casacore::MS not modified, 1 = casacore::MS modified and OK,
315 : // 0 = casacore::MS modified but not OK (i.e. casacore::MS is probably damaged)
316 : casacore::Int regridSpw(casacore::String& message, // returns the casacore::MS history entry
317 : const casacore::String& outframe="", // default = "keep the same"
318 : const casacore::String& regridQuant="chan",
319 : const casacore::Double regridVeloRestfrq=-3E30, // default = "not set"
320 : const casacore::String& regridInterpMeth="LINEAR",
321 : const casacore::Double regridCenter=-3E30, // default = "not set"
322 : const casacore::Double regridBandwidth=-1., // default = "not set"
323 : const casacore::Double regridChanWidth=-1., // default = "not set"
324 : const casacore::Bool doHanningSmooth=false,
325 : const casacore::Int phaseCenterFieldId=-2, // -2 = use pahse center from field table
326 : casacore::MDirection phaseCenter=casacore::MDirection(), // this direction is used if phaseCenterFieldId==-1
327 : const casacore::Bool centerIsStart=false, // if true, the parameter regridCenter specifies the start
328 : const casacore::Bool startIsEnd=false, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
329 : const casacore::Int nchan=0, // if >0: used instead of regridBandwidth, ==
330 : const casacore::Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
331 : const casacore::Int start=-1 // if >=0 and regridQuant=="freq": used instead of regridCenter
332 : );
333 :
334 : // the following inline convenience methods for regridSpw bypass the whole CASA measure system
335 : // because when they are used, they can assume that the frame stays the same and the units are OK
336 11199 : static casacore::lDouble vrad(const casacore::lDouble freq, const casacore::lDouble rest){ return (casacore::C::c * (1. - freq/rest)); };
337 429 : static casacore::lDouble vopt(const casacore::lDouble freq, const casacore::lDouble rest){ return (casacore::C::c *(rest/freq - 1.)); };
338 0 : static casacore::lDouble lambda(const casacore::lDouble freq){ return (casacore::C::c/freq); };
339 10725 : static casacore::lDouble freq_from_vrad(const casacore::lDouble vrad, const casacore::lDouble rest){ return (rest * (1. - vrad/casacore::C::c)); };
340 372 : static casacore::lDouble freq_from_vopt(const casacore::lDouble vopt, const casacore::lDouble rest){ return (rest / (1. + vopt/casacore::C::c)); };
341 0 : static casacore::lDouble freq_from_lambda(const casacore::lDouble lambda){ return (casacore::C::c/lambda); };
342 :
343 : // Support method for regridSpw():
344 : // results in the column oldName being renamed to newName, and a new column
345 : // which is an empty copy of oldName being created together with a
346 : // TileShapeStMan data manager and hypercolumn (name copied from the old
347 : // hypercolumn) with given dimension, the old hypercolumn of name
348 : // hypercolumnName is renamed to name+"B"
349 : casacore::Bool createPartnerColumn(casacore::TableDesc& modMSTD, const casacore::String& oldName,
350 : const casacore::String& newName, const casacore::Int& hypercolumnDim,
351 : const casacore::IPosition& tileShape);
352 :
353 : // Support method for regridSpw():
354 : // calculate the final new channel boundaries from the regridding parameters
355 : // and the old channel boundaries (already transformed to the desired
356 : // reference frame); returns false if input paramters were invalid and no
357 : // useful boundaries could be created
358 : static casacore::Bool regridChanBounds(casacore::Vector<casacore::Double>& newChanLoBound,
359 : casacore::Vector<casacore::Double>& newChanHiBound,
360 : const casacore::Double regridCenter,
361 : const casacore::Double regridBandwidth,
362 : const casacore::Double regridChanWidth,
363 : const casacore::Double regridVeloRestfrq,
364 : const casacore::String regridQuant,
365 : const casacore::Vector<casacore::Double>& transNewXin,
366 : const casacore::Vector<casacore::Double>& transCHAN_WIDTH,
367 : casacore::String& message, // message to the user, epsecially in case of error
368 : const casacore::Bool centerIsStart=false, // if true, the parameter regridCenter specifies the start
369 : const casacore::Bool startIsEnd=false, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
370 : const casacore::Int nchan=0, // if != 0 : used instead of regridBandwidth, -1 means use all channels
371 : const casacore::Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
372 : const casacore::Int start=-1 // if >=0 and regridQuant=="freq": used instead of regridCenter
373 : );
374 :
375 : // a helper function for handling the gridding parameter user input
376 : static casacore::Bool convertGridPars(casacore::LogIO& os,
377 : const casacore::String& mode,
378 : const int nchan,
379 : const casacore::String& start,
380 : const casacore::String& width,
381 : const casacore::String& interp,
382 : const casacore::String& restfreq,
383 : const casacore::String& outframe,
384 : const casacore::String& veltype,
385 : casacore::String& t_mode,
386 : casacore::String& t_outframe,
387 : casacore::String& t_regridQuantity,
388 : casacore::Double& t_restfreq,
389 : casacore::String& t_regridInterpMeth,
390 : casacore::Double& t_cstart,
391 : casacore::Double& t_bandwidth,
392 : casacore::Double& t_cwidth,
393 : casacore::Bool& t_centerIsStart,
394 : casacore::Bool& t_startIsEnd,
395 : casacore::Int& t_nchan,
396 : casacore::Int& t_width,
397 : casacore::Int& t_start);
398 :
399 : // A wrapper for SubMS::regridChanBounds() which takes the user interface type gridding parameters
400 : // The ready-made grid is returned in newCHAN_FREQ and newCHAN_WIDTH
401 : static casacore::Bool calcChanFreqs(casacore::LogIO& os,
402 : // output
403 : casacore::Vector<casacore::Double>& newCHAN_FREQ,
404 : casacore::Vector<casacore::Double>& newCHAN_WIDTH,
405 : // input
406 : const casacore::Vector<casacore::Double>& oldCHAN_FREQ, // the original grid
407 : const casacore::Vector<casacore::Double>& oldCHAN_WIDTH,
408 : // the gridding parameters
409 : const casacore::MDirection phaseCenter,
410 : const casacore::MFrequency::Types theOldRefFrame,
411 : const casacore::MEpoch theObsTime,
412 : const casacore::MPosition mObsPos,
413 : const casacore::String& mode,
414 : const int nchan,
415 : const casacore::String& start,
416 : const casacore::String& width,
417 : const casacore::String& restfreq,
418 : const casacore::String& outframe,
419 : const casacore::String& veltype,
420 : const casacore::Bool verbose=false,
421 : const casacore::MRadialVelocity mRV=casacore::MRadialVelocity() // additional radial velo shift to apply,
422 : // used e.g. when outframe=="SOURCE"
423 : );
424 :
425 : // Overloaded version of the above method returning the additional value weightScale
426 : // which is the factor by which WEIGHT needs to be scaled when transforming from
427 : // the old grid to the new grid.
428 : static casacore::Bool calcChanFreqs(casacore::LogIO& os,
429 : // output
430 : casacore::Vector<casacore::Double>& newCHAN_FREQ,
431 : casacore::Vector<casacore::Double>& newCHAN_WIDTH,
432 : casacore::Double& weightScale,
433 : // input
434 : const casacore::Vector<casacore::Double>& oldCHAN_FREQ, // the original grid
435 : const casacore::Vector<casacore::Double>& oldCHAN_WIDTH,
436 : // the gridding parameters
437 : const casacore::MDirection phaseCenter,
438 : const casacore::MFrequency::Types theOldRefFrame,
439 : const casacore::MEpoch theObsTime,
440 : const casacore::MPosition mObsPos,
441 : const casacore::String& mode,
442 : const int nchan,
443 : const casacore::String& start,
444 : const casacore::String& width,
445 : const casacore::String& restfreq,
446 : const casacore::String& outframe,
447 : const casacore::String& veltype,
448 : const casacore::Bool verbose=false,
449 : const casacore::MRadialVelocity mRV=casacore::MRadialVelocity() // additional radial velo shift to apply,
450 : // used e.g. when outframe=="SOURCE"
451 : );
452 :
453 : // Support method for regridSpw():
454 : // if writeTables is false, the (const) input parameters are only verified, nothing is written;
455 : // return value is true if the parameters are OK.
456 : // if writeTables is true, the vectors are filled and the SPW, DD, and SOURCE tables are modified;
457 : // the return value in this case is true only if a successful modification (or none) took place
458 : casacore::Bool setRegridParameters(std::vector<casacore::Int>& oldSpwId,
459 : std::vector<casacore::Int>& oldFieldId,
460 : std::vector<casacore::Int>& newDataDescId,
461 : std::vector<casacore::Bool>& regrid,
462 : std::vector<casacore::Bool>& transform,
463 : std::vector<casacore::MDirection>& theFieldDirV,
464 : std::vector<casacore::MPosition>& mObsPosV,
465 : std::vector<casacore::MFrequency::Types>& fromFrameTypeV,
466 : std::vector<casacore::MFrequency::Ref>& outFrameV,
467 : std::vector<casacore::MRadialVelocity>& outRadVelV,
468 : std::vector<casacore::Double>& weightScaleV,
469 : std::vector< casacore::Vector<casacore::Double> >& xold,
470 : std::vector< casacore::Vector<casacore::Double> >& xout,
471 : std::vector< casacore::Vector<casacore::Double> >& xin,
472 : std::vector< casacore::Int >& method, // interpolation method cast to Int
473 : casacore::Bool& msMod,
474 : const casacore::String& outframe,
475 : const casacore::String& regridQuant,
476 : const casacore::Double regridVeloRestfrq,
477 : const casacore::String& regridInterpMeth,
478 : const casacore::Double regridCenter,
479 : const casacore::Double regridBandwidth,
480 : const casacore::Double regridChanWidth,
481 : const casacore::Int regridPhaseCenterFieldId, // -2 = take from field table, -1 = use
482 : const casacore::MDirection regridPhaseCenter, // <- this value, >-1 = take from this field
483 : const casacore::Bool writeTables,
484 : casacore::LogIO& os,
485 : casacore::String& regridMessage,
486 : const casacore::Bool centerIsStart=false, // if true, the parameter regridCenter specifies the start
487 : const casacore::Bool startIsEnd=false, // if true, and centerIsStart is true, regridCenter specifies the upper end in frequency
488 : const casacore::Int nchan=0, // if >0: used instead of regridBandwidth
489 : const casacore::Int width=0, // if >0 and regridQuant=="freq": used instead of regridChanWidth
490 : const casacore::Int start=-1 // if >=0 and regridQuant=="freq": used instead of regridCenter
491 : );
492 :
493 : // combineSpws():
494 : // make one spectral window from all spws given by the spwids vector
495 : casacore::Bool combineSpws(const casacore::Vector<casacore::Int>& spwids, // casacore::Vector<casacore::Int>(1,-1) means: use all SPWs
496 : const casacore::Bool noModify, // if true, the casacore::MS will not be modified
497 : casacore::Vector<casacore::Double>& newCHAN_FREQ, // will return the grid of the resulting SPW
498 : casacore::Vector<casacore::Double>& newCHAN_WIDTH,
499 : casacore::Bool verbose=false
500 : );
501 :
502 : casacore::Bool combineSpws(const casacore::Vector<casacore::Int>& spwids = casacore::Vector<casacore::Int>(1,-1)){ // casacore::Vector<casacore::Int>(1,-1) means: use all SPWs
503 : casacore::Vector<casacore::Double> temp1;
504 : casacore::Vector<casacore::Double> temp2;
505 : return combineSpws(spwids, false, temp1, temp2, true);
506 : }
507 :
508 : // Fills mapper[ntok] with a map from dataColumn indices to ArrayColumns in
509 : // the output. mapper must have ntok slots!
510 : static void getDataColMap(casacore::MSColumns* msc, casacore::ArrayColumn<casacore::Complex>* mapper,
511 : casacore::uInt ntok,
512 : const casacore::Vector<casacore::MS::PredefinedColumns>& colEnums);
513 :
514 : void setTVIDebug(bool debug) {tvi_debug = debug;}
515 : void setWantCont(bool want_cont) {want_cont_p = want_cont;}
516 :
517 :
518 : protected:
519 :
520 : //method that returns the selected ms (?! - but it's Boolean - RR)
521 : casacore::Bool makeSelection();
522 :
523 : // (Sub)table fillers.
524 : casacore::Bool fillAllTables(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
525 : casacore::Bool fillDDTables(); // Includes spw and pol.
526 : casacore::Bool fillFieldTable();
527 :
528 : // Used to be fillMainTable(colnames), but what distinguishes it from
529 : // writeSomeMainRows(colnames) is that it is for cases where there is
530 : // a 1-1 match between rows in mssel_p and msOut_p (including order).
531 : casacore::Bool writeAllMainRows(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
532 :
533 : // Used to be fillAverMainTable(colnames), but what distinguishes it from
534 : // writeAllMainRows(colnames) is that it is for cases where there is not
535 : // necessarily a 1-1 match between rows in mssel_p and msOut_p.
536 : casacore::Bool writeSomeMainRows(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
537 :
538 : casacore::Bool copyAntenna();
539 : casacore::Bool copyFeed();
540 : casacore::Bool copyFlag_Cmd();
541 : casacore::Bool copyHistory();
542 : casacore::Bool copyObservation();
543 : casacore::Bool copyPointing();
544 : casacore::Bool copyProcessor();
545 : casacore::Bool copySource();
546 : casacore::Bool copyState();
547 : casacore::Bool copySyscal();
548 : casacore::Bool copyWeather();
549 : casacore::Bool copyGenericSubtables();
550 : void copyMainTableKeywords(casacore::TableRecord& outKeys,const casacore::TableRecord& inKeys);
551 :
552 : // This falls between copyGenericSubtables() and the copiers for standard
553 : // subtables like copyFeed(). It is for optional subtables like CALDEVICE
554 : // and SYSPOWER which can be watched for by name and may need their
555 : // ANTENNA_ID and SPECTRAL_WINDOW_ID columns remapped. (Technically FEED_ID,
556 : // too, if split ever starts remapping feeds.)
557 : //
558 : // It must be called BEFORE copyGenericSubtables()!
559 : //
560 : casacore::Bool filterOptSubtable(const casacore::String& subtabname);
561 :
562 : // casacore::Bool writeDiffSpwShape(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
563 : casacore::Bool fillAccessoryMainCols();
564 :
565 : // *** Private member functions ***
566 :
567 : // Adds and copies inTab to msOut_p without any filtering.
568 : // tabName is the table "type", i.e. POINTING or SYSPOWER without the
569 : // preceding path.
570 : //
571 : // If noRows is true, the structure will be setup but no rows will be
572 : // copied. (Useful for filtering)
573 : void copySubtable(const casacore::String& tabName, const casacore::Table& inTab,
574 : const casacore::Bool noRows=false);
575 :
576 : casacore::Bool getDataColumn(casacore::ArrayColumn<casacore::Complex>& data,
577 : const casacore::MS::PredefinedColumns colName);
578 : casacore::Bool getDataColumn(casacore::ArrayColumn<casacore::Float>& data,
579 : const casacore::MS::PredefinedColumns colName);
580 : casacore::Bool putDataColumn(casacore::MSColumns& msc, casacore::ArrayColumn<casacore::Complex>& data,
581 : const casacore::MS::PredefinedColumns datacol,
582 : const casacore::Bool writeToDataCol=false);
583 : casacore::Bool putDataColumn(casacore::MSColumns& msc, casacore::ArrayColumn<casacore::Float>& data,
584 : const casacore::MS::PredefinedColumns datacol,
585 : const casacore::Bool writeToDataCol=false);
586 :
587 : // This method uses VisIter for efficient copy mode data transfer
588 : casacore::Bool copyDataFlagsWtSp(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames,
589 : const casacore::Bool writeToDataCol);
590 :
591 : // Like doTimeAver(), but it subtracts the continuum instead of time
592 : // averaging. Unlike doTimeAver(), it infers writeToDataCol from
593 : // colNames.nelements() (subtractContinuum is intentionally not as general as
594 : // copyDataFlagsWtSp), and writes according to fitoutspw_p instead of spw_p.
595 : casacore::Bool subtractContinuum(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames,
596 : const VBRemapper& remapper);
597 :
598 : // Helper function for parseColumnNames(). Converts col to a list of
599 : // casacore::MS::PredefinedColumnss, and returns the # of recognized data columns.
600 : // static because parseColumnNames() is static.
601 : static casacore::uInt dataColStrToEnums(const casacore::String& col,
602 : casacore::Vector<casacore::MS::PredefinedColumns>& colvec);
603 :
604 : casacore::Bool doChannelMods(const casacore::Vector<casacore::MS::PredefinedColumns>& colNames);
605 :
606 : void fill_vbmaps(std::map<VisBufferComponents::EnumType,
607 : std::map<casacore::Int, casacore::Int> >& vbmaps);
608 :
609 : // return the number of unique antennas selected
610 : //casacore::Int numOfBaselines(casacore::Vector<casacore::Int>& ant1, casacore::Vector<casacore::Int>& ant2,
611 : // casacore::Bool includeAutoCorr=false);
612 :
613 : // Used in a couple of places to estimate how much memory to grab.
614 0 : casacore::Double n_bytes() {return mssel_p.nrow() * nchan_p[0] * ncorr_p[0] *
615 0 : sizeof(casacore::Complex);}
616 :
617 : // Picks a reference to DATA, MODEL_DATA, CORRECTED_DATA, or LAG_DATA out
618 : // of ms_p. FLOAT_DATA is not included because it is not natively complex.
619 : const casacore::ArrayColumn<casacore::Complex>& right_column(const casacore::MSColumns *ms_p,
620 : const casacore::MS::PredefinedColumns datacol);
621 :
622 : // The writable version of the above.
623 : casacore::ArrayColumn<casacore::Complex>& right_column(casacore::MSColumns *msclala,
624 : const casacore::MS::PredefinedColumns col,
625 : const casacore::Bool writeToDataCol);
626 :
627 : // Figures out the number, maximum, and index of the selected antennas.
628 : casacore::uInt fillAntIndexer(std::map<casacore::Int, casacore::Int>& antIndexer, const casacore::MSColumns *msc);
629 :
630 : // Read the input, time average it to timeBin_p, and write the output.
631 : // The first version uses VisibilityIterator (much faster), but the second
632 : // supports correlation selection using VisIterator. VisIterator should be
633 : // sped up soon!
634 : casacore::Bool doTimeAver(const casacore::Vector<casacore::MS::PredefinedColumns>& dataColNames,
635 : const VBRemapper& remapper);
636 : casacore::Bool doTimeAverVisIterator(const casacore::Vector<casacore::MS::PredefinedColumns>& dataColNames,
637 : const VBRemapper& remapper);
638 :
639 0 : void getDataColMap(casacore::ArrayColumn<casacore::Complex>* mapper, casacore::uInt ntok,
640 : const casacore::Vector<casacore::MS::PredefinedColumns>& colEnums)
641 : {
642 0 : getDataColMap(msc_p, mapper, ntok, colEnums);
643 0 : }
644 :
645 : // Returns whether or not the numbers of correlations and channels
646 : // are independent of DATA_DESCRIPTION_ID, for both the input and output
647 : // MSes.
648 : casacore::Bool areDataShapesConstant();
649 :
650 : // Returns whether or not the input casacore::MS has a valid FLAG_CATEGORY, and its
651 : // first row has the right number of correlations and channels.
652 : casacore::Bool existsFlagCategory() const;
653 :
654 : // Sets up sourceRelabel_p for mapping input SourceIDs (if any) to output
655 : // ones. Must be called after fieldid_p is set and before calling
656 : // fillFieldTable() or copySource().
657 : void relabelSources();
658 :
659 : void relabelIDs();
660 :
661 : // Sets outcol to the indices of selvals that correspond to incol, i.e.
662 : // outcol(i) = j s.t. selvals[j] == incol(i).
663 : //
664 : // Ideally selvals is set up so that outcol's values will be row numbers in
665 : // the corresponding subtable of its ms.
666 : //
667 : // Throws an exception if incol and outcol do not have the same # of rows, or
668 : // incol has a value that is not in selvals.
669 : void remapColumn(casacore::ScalarColumn<casacore::Int>& outcol, const casacore::ScalarColumn<casacore::Int>& incol,
670 : const casacore::Vector<casacore::Int>& selvals);
671 :
672 : // Equivalent to but slightly more efficient than
673 : // remapColumn(outcol, incol, incol.getColumn()).
674 : void remapColumn(casacore::ScalarColumn<casacore::Int>& outcol, const casacore::ScalarColumn<casacore::Int>& incol);
675 :
676 : //static void make_map(const casacore::Vector<casacore::Int>& mscol, casacore::Vector<casacore::Int>& mapper);
677 :
678 : // Sets mapper to to a map from the distinct values of inv, in increasing
679 : // order, to 0, 1, 2, ..., mapper.size() - 1.
680 : static void make_map(std::map<casacore::Int, casacore::Int>& mapper, const casacore::Vector<casacore::Int>& inv);
681 : // Sets mapper to form a map from inv whose elements are mapped values. It skips
682 : // to store in mapper if the value is -1
683 : static void make_map2(std::map<casacore::Int, casacore::Int>& mapper, const casacore::Vector<casacore::Int>& inv);
684 :
685 : casacore::uInt remapped(const casacore::Int ov, const casacore::Vector<casacore::Int>& mapper, casacore::uInt i);
686 :
687 : // Sets up the stub of a POINTING, enough to create an MSColumns.
688 : void setupNewPointing();
689 :
690 : // Sets sort to a casacore::Block of columns that a VisibilityIterator should sort by,
691 : // according to combine_p. Columns that should never be combined in the
692 : // calling function, i.e. spw for time averaging, should be listed in
693 : // uncombinable.
694 : //
695 : // verbose: log a message on error.
696 : //
697 : // Returns whether or not there were any conflicts between combine_p and
698 : // uncombinable.
699 : casacore::Bool setSortOrder(casacore::Block<casacore::Int>& sort, const casacore::String& uncombinable="",
700 : const casacore::Bool verbose=true) const;
701 :
702 : // Returns whether col is (not in combine_p) || in uncombinable.
703 : // Columns that should never be combined in the
704 : // calling function, i.e. spw for time averaging, should be listed in
705 : // uncombinable.
706 : //
707 : // verbose: log a message on error.
708 : //
709 : // conflict is set to true if there is a conflict between combine_p and
710 : // uncombinable.
711 : casacore::Bool shouldWatch(casacore::Bool& conflict, const casacore::String& col,
712 : const casacore::String& uncombinable="",
713 : const casacore::Bool verbose=true) const;
714 :
715 : // *** Member variables ***
716 :
717 : // Initialized* by ctors. (Maintain order both here and in ctors.)
718 : // * not necessarily to anything useful.
719 : casacore::MeasurementSet ms_p, mssel_p;
720 : casacore::MSColumns * msc_p; // columns of msOut_p
721 : casacore::MSColumns * mscIn_p;
722 : casacore::Bool keepShape_p, // Iff true, each output array has the
723 : // same shape as the corresponding input one.
724 : // sameShape_p, // Iff true, the shapes of the arrays do not
725 : // // vary with row number.
726 : antennaSel_p; // Selecting by antenna?
727 : casacore::Double timeBin_p;
728 : casacore::String scanString_p, // Selects scans by #number#. Historically named.
729 : intentString_p, // Selects scans by string. scanString_p was taken.
730 : obsString_p, // casacore::String for observationID selection.
731 : uvrangeString_p,
732 : taqlString_p;
733 : casacore::String timeRange_p, arrayExpr_p, corrString_p;
734 : casacore::String combine_p; // Should time averaging not split bins by
735 : // scan #, observation, and/or state ID?
736 : // Must be lowercase at all times.
737 : casacore::Int fitorder_p; // The polynomial order for continuum fitting.
738 : // If < 0 (default), continuum subtraction is
739 : // not done.
740 : casacore::String fitspw_p; // Selection string for line-free channels.
741 : casacore::String fitoutspw_p; // Selection string for output channels if doing
742 : // continuum subtraction.
743 :
744 : // jagonzal: Allow main table to be left empty, so that it can be filled by another layer.
745 : casacore::Bool fillMainTable_p;
746 :
747 : // Uninitialized by ctors.
748 : casacore::MeasurementSet msOut_p;
749 : casacore::Vector<casacore::Int> spw_p, // The input spw corresponding to each output spw.
750 : spw_uniq_p, // Uniquified version of spw_p.
751 : spwind_to_min_spwind_p,
752 : nchan_p, // The # of output channels for each range.
753 : totnchan_p, // The # of output channels for each output spw.
754 : chanStart_p, // 1st input channel index in a selection.
755 : chanEnd_p, // last input channel index in a selection.
756 : chanStep_p, // Increment between input chans, i.e. if 3, only every third
757 : // input channel will be used.
758 : widths_p, // # of input chans per output chan for each range.
759 : ncorr_p, // The # of output correlations for each DDID.
760 : inNumChan_p, // The # of input channels for each spw.
761 : inNumCorr_p; // The # of input correlations for each DDID.
762 : casacore::Vector<casacore::Int> fieldid_p;
763 : casacore::Vector<casacore::Int> spwRelabel_p, fieldRelabel_p, sourceRelabel_p;
764 : casacore::Vector<casacore::Int> oldDDSpwMatch_p;
765 : casacore::Vector<casacore::String> antennaSelStr_p;
766 : casacore::Vector<casacore::Int> antennaId_p;
767 : casacore::Vector<casacore::Int> antIndexer_p;
768 : casacore::Vector<casacore::Int> antNewIndex_p;
769 :
770 : casacore::Vector<casacore::Int> selObsId_p; // casacore::List of selected OBSERVATION_IDs.
771 : casacore::Vector<casacore::Int> polID_p; // casacore::Map from input DDID to input polID, filled in fillDDTables().
772 : casacore::Vector<casacore::uInt> spw2ddid_p;
773 :
774 : // inCorrInd = outPolCorrToInCorrMap_p[polID_p[ddID]][outCorrInd]
775 : casacore::Vector<casacore::Vector<casacore::Int> > inPolOutCorrToInCorrMap_p;
776 :
777 : std::map<casacore::Int, casacore::Int> stateRemapper_p;
778 :
779 : casacore::Vector<casacore::Vector<casacore::Slice> > chanSlices_p; // Used by VisIterator::selectChannel()
780 : casacore::Vector<casacore::Slice> corrSlice_p;
781 : casacore::Vector<casacore::Vector<casacore::Slice> > corrSlices_p; // Used by VisIterator::selectCorrelation()
782 : casacore::Matrix<casacore::Double> selTimeRanges_p;
783 :
784 : bool tvi_debug;
785 : bool want_cont_p;
786 : };
787 :
788 : } //# NAMESPACE CASA - END
789 :
790 : #endif
791 :
|