Line data Source code
1 : ///# MSTransform.cc: this defines MSTransform
2 : //# Copyright (C) 2000,2001,2002
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 : //# $Id$
27 : #include <stdarg.h>
28 : #include <sstream>
29 : #include <iostream>
30 : #include <vector>
31 : #include <casacore/casa/Utilities/Regex.h>
32 : #include <casacore/casa/OS/HostInfo.h>
33 : #include <casacore/casa/Exceptions/Error.h>
34 : #include <mstransform/MSTransform/MSTransform.h>
35 : #include <casacore/casa/stdio.h>
36 : #include <casacore/casa/math.h>
37 :
38 : using namespace casacore;
39 : namespace casa {
40 :
41 :
42 : // -----------------------------------------------------------------------
43 : // Default Constructor
44 : // -----------------------------------------------------------------------
45 0 : MSTransform::MSTransform () : mdh_p()
46 : {
47 0 : done();
48 0 : }
49 :
50 :
51 : // -----------------------------------------------------------------------
52 : // Default Destructor
53 : // -----------------------------------------------------------------------
54 0 : MSTransform::~MSTransform ()
55 : {
56 0 : done();
57 0 : }
58 :
59 : void
60 0 : MSTransform::done()
61 : {
62 0 : if(mdh_p){
63 0 : auto *mdh = mdh_p.release();
64 0 : delete mdh;
65 : }
66 :
67 : // Default values of parameters
68 0 : msname_p = "";
69 0 : outputms_p = "";
70 0 : spw_p = "";
71 0 : scan_p = "";
72 0 : field_p = "";
73 0 : antenna_p = "";
74 0 : timerange_p = "";
75 0 : correlation_p = "";
76 0 : intent_p = "";
77 0 : feed_p = "";
78 0 : array_p = "";
79 0 : uvrange_p = "";
80 0 : observation_p = "";
81 :
82 0 : config_p = Record();
83 0 : datacolumn_p = "CORRECTED";
84 0 : isconfigured_p = false;
85 :
86 0 : return;
87 : }
88 :
89 :
90 :
91 : // ---------------------------------------------------------------------
92 : // MSTransform::configure
93 : // Configure the MSTransformManager and the parameters.
94 : // The config Record is mandatory and needs to have at least
95 : // the parameters for the input and output MSs.
96 : // This method may be called again to add or change parameters.
97 : // ---------------------------------------------------------------------
98 : bool
99 0 : MSTransform::configure(Record config)
100 : {
101 0 : log_p.origin(LogOrigin("MSTransform", __func__));
102 :
103 0 : if (config.empty()){
104 0 : log_p << LogIO::SEVERE << "There is no configuration for the tool"
105 0 : << LogIO::POST;
106 0 : return false;
107 : }
108 :
109 : // First time configuration
110 0 : if (!isconfigured_p){
111 :
112 : // The minimum configuration is the input and output MS names.
113 0 : if (config.isDefined("inputms"))
114 0 : config.get("inputms", msname_p);
115 : else{
116 0 : log_p << LogIO::SEVERE << "There is no \"inputms\" in configuration Record"
117 0 : << LogIO::POST;
118 0 : return false;
119 : }
120 :
121 0 : if (config.isDefined("outputms"))
122 0 : config.get("outputms", outputms_p);
123 : else{
124 0 : log_p << LogIO::SEVERE << "There is no \"outputms\" in configuration Record"
125 0 : << LogIO::POST;
126 0 : return false;
127 : }
128 :
129 0 : if(mdh_p) {
130 0 : auto *mdh = mdh_p.release();
131 0 : delete mdh;
132 : }
133 :
134 : // Create an object for the MSTransformManager
135 0 : mdh_p = std::unique_ptr<MSTransformManager>(new MSTransformManager());
136 : }
137 :
138 0 : config_p = config;
139 :
140 : // The datacolumn must exist
141 0 : if (config_p.isDefined("datacolumn")){
142 0 : config_p.get("datacolumn", datacolumn_p);
143 0 : datacolumn_p.upcase();
144 0 : config_p.define("datacolumn", datacolumn_p);
145 : }
146 : else {
147 : // Add the default column to the Record
148 0 : config_p.define("datacolumn", datacolumn_p);
149 : }
150 :
151 : // Configure the MSTransformManager object
152 0 : mdh_p->configure(config_p);
153 0 : isconfigured_p = true;
154 :
155 : // TODO: should I check all the other parameters in the config_p Record?
156 : // Which other parameters should be checked here?
157 :
158 0 : ostringstream os;
159 0 : config_p.print(os);
160 0 : String str(os.str());
161 0 : log_p << LogIO::DEBUG1 << " Configuration Record " << LogIO::POST;
162 0 : log_p << LogIO::DEBUG1 << str << LogIO::POST;
163 :
164 0 : return true;
165 0 : }
166 :
167 :
168 : // ---------------------------------------------------------------------
169 : // MSTransform::open
170 : // Setup the MSTranformDataHandler and generate the iterators
171 : // It assumes that MSTransform::configure is run first
172 : // ---------------------------------------------------------------------
173 : bool
174 0 : MSTransform::open()
175 : {
176 :
177 0 : log_p.origin(LogOrigin("MSTransform", __func__));
178 :
179 0 : if (! isconfigured_p){
180 0 : log_p << LogIO::SEVERE << "There is no configuration for the tool"
181 0 : << LogIO::POST;
182 0 : return false;
183 : }
184 :
185 0 : if(!mdh_p){
186 0 : log_p << LogIO::SEVERE << "The tool was not configured" << LogIO::POST;
187 0 : return false;
188 : }
189 :
190 : // Open the MS and select the data
191 0 : mdh_p->open();
192 :
193 :
194 : // Setup the DataHandler
195 0 : mdh_p->setup();
196 :
197 0 : return true;
198 : }
199 :
200 : // ---------------------------------------------------------------------
201 : // MSTransform::run
202 : // Run the tool
203 : // TODO: For the moment it returns a Record, but verify this later
204 : // ---------------------------------------------------------------------
205 : Record
206 0 : MSTransform::run()
207 : {
208 0 : log_p.origin(LogOrigin("MSTransform", __func__));
209 :
210 0 : if (! mdh_p){
211 0 : log_p << LogIO::SEVERE << "The tool is not configured. Please run mt.config and mt.open first."
212 0 : << LogIO::POST;
213 0 : return Record();
214 : }
215 :
216 0 : vi::VisibilityIterator2 *visIter = mdh_p->getVisIter();
217 0 : vi::VisBuffer2 *vb = visIter->getVisBuffer();
218 0 : visIter->originChunks();
219 0 : while (visIter->moreChunks())
220 : {
221 0 : visIter->origin();
222 0 : while (visIter->more())
223 : {
224 0 : mdh_p->fillOutputMs(vb);
225 0 : visIter->next();
226 : }
227 :
228 0 : visIter->nextChunk();
229 : }
230 0 : Record result;
231 0 : visIter->result(result);
232 0 : mdh_p->close();
233 :
234 0 : return result;
235 0 : }
236 :
237 : /*
238 : // ---------------------------------------------------------------------
239 : // MSTransform::defaultOptions
240 : // Set the defaults for all the parameters
241 : // Returns a Record with the default of each parameter
242 : // ---------------------------------------------------------------------
243 : Record &
244 : MSTransform::defaultOptions()
245 : {
246 : Record defaults;
247 :
248 : defaults.define("inputms", "");
249 : defaults.define("outputms", "");
250 : defaults.define("createmms", true);
251 : defaults.define("separationaxis", "both");
252 : defaults.define("numsubms", "");
253 : defaults.define("tileshape", "");
254 : defaults.define("spw", "");
255 : defaults.define("scan", "");
256 : defaults.define("antenna", "");
257 : defaults.define("array", "");
258 : defaults.define("correlation", "");
259 : defaults.define("field", "");
260 : defaults.define("timerange", "");
261 : defaults.define("uvrange", "");
262 : defaults.define("state", "");
263 : defaults.define("observation", "");
264 : defaults.define("datacolumn", "CORRECTED");
265 : defaults.define("realmodelcol", false);
266 : defaults.define("combinespws", false);
267 : defaults.define("freqaverage", false);
268 : defaults.define("freqbin", "");
269 : defaults.define("useweights", "");
270 : defaults.define("hanning", false);
271 : defaults.define("regridms", false);
272 : defaults.define("mode", "");
273 : defaults.define("nchan", "");
274 : defaults.define("start", "");
275 : defaults.define("width", "");
276 : defaults.define("interpolation", "");
277 : defaults.define("phasecenter", "");
278 : defaults.define("restfreq", "");
279 : defaults.define("outframe", "");
280 : defaults.define("veltype", "");
281 : defaults.define("separatespws", false);
282 : defaults.define("nspws", "");
283 : defaults.define("timeaverage", false);
284 : defaults.define("timebing", "");
285 : defaults.define("timespan", "");
286 : defaults.define("quantize_c", "");
287 : defaults.define("minbaselines", "");
288 :
289 : return defauts;
290 : }
291 : */
292 :
293 :
294 : // ---------------------------------------------------------------------
295 : // MSTransform::validateDataColumn
296 : // Check if datacolumn is valid
297 : // Return validated datacolumn
298 : // ---------------------------------------------------------------------
299 : /*
300 : String
301 : MSTransform::validateDataColumn(String datacol)
302 : {
303 : String ret = "";
304 : Bool checkcol = false;
305 : datacol.upcase();
306 :
307 : LogIO log_p(LogOrigin("MSTransform", __FUNCTION__, WHERE));
308 :
309 : if (mdh_p->checkIfColumnExists(datacol))
310 : ret = datacol;
311 : else {
312 : // Check if default column exist
313 : if (mdh_p->checkIfColumnExists("CORRECTED"))
314 : ret = "CORRECTED";
315 : }
316 :
317 : return ret;
318 : }
319 : */
320 :
321 :
322 :
323 : } //#end casa namespace
324 :
325 :
|