Line data Source code
1 : //# CalTableDesc.cc: Implementation of CalTableDesc.h
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: 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 : //----------------------------------------------------------------------------
28 :
29 : #include <synthesis/CalTables/CalTableDesc.h>
30 : #include <msvis/MSVis/MSCalEnums.h>
31 : #include <casacore/tables/Tables/ScaColDesc.h>
32 : #include <casacore/tables/Tables/ArrColDesc.h>
33 : #include <casacore/tables/Tables/SetupNewTab.h>
34 : #include <casacore/tables/Tables/TableRecord.h>
35 : #include <casacore/measures/TableMeasures/TableMeasRefDesc.h>
36 : #include <casacore/measures/TableMeasures/TableMeasValueDesc.h>
37 : #include <casacore/measures/TableMeasures/TableMeasDesc.h>
38 : #include <casacore/measures/TableMeasures/TableQuantumDesc.h>
39 : #include <casacore/measures/Measures/MEpoch.h>
40 : #include <casacore/measures/Measures/MFrequency.h>
41 : #include <casacore/measures/Measures/MDirection.h>
42 : #include <casacore/casa/Containers/Record.h>
43 : #include <casacore/casa/Arrays/IPosition.h>
44 :
45 : using namespace casacore;
46 : namespace casa { //# NAMESPACE CASA - BEGIN
47 :
48 : //----------------------------------------------------------------------------
49 :
50 0 : CalTableDesc::CalTableDesc() : itsCalMainDesc(defaultCalMain("")),
51 0 : itsCalHistoryDesc(defaultCalHistory()),
52 0 : itsCalDescDesc(defaultCalDesc())
53 : {
54 : // Default null constructor for calibration table description (v2.0)
55 : // Output to private data:
56 : // itsCalMainDesc TableDesc Table descriptor (cal_main)
57 : // itsCalHistoryDesc TableDesc Table descriptor (cal_history)
58 : // itsCalDescDesc TableDesc Table descriptor (cal_desc)
59 : //
60 0 : };
61 :
62 : //----------------------------------------------------------------------------
63 :
64 0 : CalTableDesc::CalTableDesc (const String& type) :
65 0 : itsCalMainDesc(defaultCalMain(type)),
66 0 : itsCalHistoryDesc(defaultCalHistory()), itsCalDescDesc(defaultCalDesc())
67 : {
68 : // Constructor for calibration table description (v2.0)
69 : // Inputs:
70 : // type const String& Cal table type (eg. "P Jones")
71 : // Output to private data:
72 : // itsCalMainDesc TableDesc Table descriptor (cal_main)
73 : // itsCalHistoryDesc TableDesc Table descriptor (cal_history)
74 : // itsCalDescDesc TableDesc Table descriptor (cal_desc)
75 : //
76 0 : };
77 :
78 : //----------------------------------------------------------------------------
79 :
80 0 : TableDesc CalTableDesc::defaultCalHistory()
81 : {
82 : // Generate the default table descriptor for the Cal History sub-table
83 : // Output:
84 : // defaultCalHistory TableDesc Default Cal History descriptor
85 : //
86 0 : TableDesc td ("Cal History", "2.0", TableDesc::Scratch);
87 0 : td.comment() = "Calibration history sub-table";
88 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::CAL_PARMS),
89 : ColumnDesc::Direct));
90 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::CAL_TABLES),
91 : ColumnDesc::Direct));
92 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::CAL_SELECT),
93 : ColumnDesc::Direct));
94 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::CAL_NOTES),
95 : ColumnDesc::Direct));
96 0 : return td;
97 0 : };
98 :
99 : //----------------------------------------------------------------------------
100 :
101 0 : TableDesc CalTableDesc::defaultCalDesc()
102 : {
103 : // Generate the default table descriptor for the Cal Desc sub-table
104 : // Output:
105 : // defaultCalDesc TableDesc Default Cal Desc descriptor
106 : //
107 0 : TableDesc td ("Cal Desc", "1.0", TableDesc::Scratch);
108 0 : td.comment() = "Calibration description sub-table";
109 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::NUM_SPW),
110 : ColumnDesc::Direct));
111 0 : td.addColumn (ArrayColumnDesc <Int> (MSC::fieldName (MSC::NUM_CHAN)));
112 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::NUM_RECEPTORS),
113 : ColumnDesc::Direct));
114 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::N_JONES),
115 : ColumnDesc::Direct));
116 : td.addColumn
117 0 : (ArrayColumnDesc <Int> (MSC::fieldName (MSC::SPECTRAL_WINDOW_ID)));
118 0 : td.addColumn (ArrayColumnDesc <Double> (MSC::fieldName (MSC::CHAN_FREQ)));
119 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::MEAS_FREQ_REF),
120 : ColumnDesc::Direct));
121 0 : td.addColumn (ArrayColumnDesc <Double> (MSC::fieldName (MSC::CHAN_WIDTH)));
122 0 : td.addColumn (ArrayColumnDesc <Int> (MSC::fieldName (MSC::CHAN_RANGE)));
123 0 : td.addColumn (ArrayColumnDesc <String>
124 0 : (MSC::fieldName (MSC::POLARIZATION_TYPE)));
125 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::JONES_TYPE),
126 : ColumnDesc::Direct));
127 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::MS_NAME),
128 : ColumnDesc::Direct));
129 :
130 : // Add TableMeasures information for Measures/Quanta columns
131 : //
132 : // CHAN_FREQ
133 0 : TableMeasValueDesc chanFreqMeasVal (td, MSC::fieldName(MSC::CHAN_FREQ));
134 0 : TableMeasRefDesc chanFreqMeasRef (td, MSC::fieldName (MSC::MEAS_FREQ_REF));
135 0 : TableMeasDesc<MFrequency> chanFreqMeasCol (chanFreqMeasVal, chanFreqMeasRef);
136 0 : chanFreqMeasCol.write (td);
137 :
138 : // CHAN_WIDTH
139 0 : TableQuantumDesc chanWidthQuantDesc (td, MSC::fieldName (MSC::CHAN_WIDTH),
140 0 : Unit ("Hz"));
141 0 : chanWidthQuantDesc.write (td);
142 :
143 0 : return td;
144 0 : };
145 :
146 : //----------------------------------------------------------------------------
147 :
148 0 : TableDesc CalTableDesc::defaultCalMain (const String& type)
149 : {
150 : // Generate the default table descriptor for the Cal Main sub-table
151 : // Input:
152 : // type const String& Cal table type (eg. "P Jones")
153 : // Output:
154 : // defaultCalMain TableDesc Default Cal Main descriptor
155 : //
156 : // Set up table descriptor and add comment field
157 0 : TableDesc td (type, "1.0", TableDesc::Scratch);
158 0 : td.comment() = type + " calibration table";
159 :
160 : // Define keywords
161 0 : Record keyWordRec;
162 : // Cal_desc and cal_history indices
163 0 : keyWordRec.define (MSC::fieldName (MSC::CAL_DESC_ID), 0);
164 0 : keyWordRec.define (MSC::fieldName (MSC::CAL_HISTORY_ID), 0);
165 : // Add to table descriptor
166 0 : td.rwKeywordSet().assign (keyWordRec);
167 :
168 : // Cal Main columns (MS Main indices)
169 0 : td.addColumn (ScalarColumnDesc <Double> (MSC::fieldName (MSC::TIME),
170 : ColumnDesc::Direct));
171 : td.addColumn
172 0 : (ScalarColumnDesc <Double> (MSC::fieldName (MSC::TIME_EXTRA_PREC),
173 : ColumnDesc::Direct));
174 0 : td.addColumn (ScalarColumnDesc <Double> (MSC::fieldName (MSC::INTERVAL),
175 : ColumnDesc::Direct));
176 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::ANTENNA1),
177 : ColumnDesc::Direct));
178 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::FEED1),
179 : ColumnDesc::Direct));
180 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::FIELD_ID),
181 : ColumnDesc::Direct));
182 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::ARRAY_ID),
183 : ColumnDesc::Direct));
184 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::OBSERVATION_ID),
185 : ColumnDesc::Direct));
186 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::SCAN_NUMBER),
187 : ColumnDesc::Direct));
188 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::PROCESSOR_ID),
189 : ColumnDesc::Direct));
190 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::STATE_ID),
191 : ColumnDesc::Direct));
192 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::PHASE_ID),
193 : ColumnDesc::Direct));
194 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::PULSAR_BIN),
195 : ColumnDesc::Direct));
196 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::PULSAR_GATE_ID),
197 : ColumnDesc::Direct));
198 :
199 : // Secondary MS indices (from MS sub-tables)
200 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::FREQ_GROUP),
201 : ColumnDesc::Direct));
202 0 : td.addColumn (ScalarColumnDesc<String> (MSC::fieldName(MSC::FREQ_GROUP_NAME),
203 : ColumnDesc::Direct));
204 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::FIELD_NAME),
205 : ColumnDesc::Direct));
206 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::FIELD_CODE),
207 : ColumnDesc::Direct));
208 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::SOURCE_NAME),
209 : ColumnDesc::Direct));
210 0 : td.addColumn (ScalarColumnDesc <String> (MSC::fieldName (MSC::SOURCE_CODE),
211 : ColumnDesc::Direct));
212 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName(MSC::CALIBRATION_GROUP),
213 : ColumnDesc::Direct));
214 :
215 : // Gain values
216 0 : td.addColumn (ArrayColumnDesc <Complex> (MSC::fieldName (MSC::GAIN)));
217 :
218 : // Reference frame for antenna-based corrections
219 0 : td.addColumn (ArrayColumnDesc <Int> (MSC::fieldName (MSC::REF_ANT)));
220 0 : td.addColumn (ArrayColumnDesc <Int> (MSC::fieldName (MSC::REF_FEED)));
221 0 : td.addColumn (ArrayColumnDesc <Int> (MSC::fieldName (MSC::REF_RECEPTOR)));
222 0 : td.addColumn (ArrayColumnDesc <Double> (MSC::fieldName(MSC::REF_FREQUENCY)));
223 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::MEAS_FREQ_REF),
224 : ColumnDesc::Direct));
225 0 : td.addColumn (ArrayColumnDesc <Double> (MSC::fieldName(MSC::REF_DIRECTION)));
226 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::MEAS_DIR_REF),
227 : ColumnDesc::Direct));
228 :
229 : // Pointers to Cal_Desc and Cal_History sub-tables
230 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::CAL_DESC_ID),
231 : ColumnDesc::Direct));
232 0 : td.addColumn (ScalarColumnDesc <Int> (MSC::fieldName (MSC::CAL_HISTORY_ID),
233 : ColumnDesc::Direct));
234 :
235 : // Add TableMeasures information for designated Measures/Quanta columns
236 : //
237 : // TIME
238 0 : TableMeasValueDesc timeMeasVal (td, MSC::fieldName (MSC::TIME));
239 0 : TableMeasRefDesc timeMeasRef (MEpoch::DEFAULT);
240 0 : TableMeasDesc<MEpoch> timeMeasCol (timeMeasVal, timeMeasRef);
241 0 : timeMeasCol.write (td);
242 :
243 : // TIME fix Unit
244 0 : TableQuantumDesc timeQuantDesc (td, MSC::fieldName (MSC::TIME),
245 0 : Unit ("s"));
246 0 : timeQuantDesc.write (td);
247 :
248 : // TIME_EXTRA_PREC
249 0 : TableQuantumDesc timeEPQuantDesc (td, MSC::fieldName (MSC::TIME_EXTRA_PREC),
250 0 : Unit ("s"));
251 0 : timeEPQuantDesc.write (td);
252 :
253 : // INTERVAL
254 0 : TableQuantumDesc intervalQuantDesc (td, MSC::fieldName(MSC::INTERVAL),
255 0 : Unit ("s"));
256 0 : intervalQuantDesc.write (td);
257 :
258 : // REF_FREQUENCY
259 0 : TableMeasValueDesc refFreqMeasVal (td, MSC::fieldName (MSC::REF_FREQUENCY));
260 0 : TableMeasRefDesc refFreqMeasRef (td, MSC::fieldName (MSC::MEAS_FREQ_REF));
261 0 : TableMeasDesc<MFrequency> refFreqMeasCol (refFreqMeasVal, refFreqMeasRef);
262 0 : refFreqMeasCol.write (td);
263 :
264 : // REF_DIRECTION
265 0 : TableMeasValueDesc refDirMeasVal (td, MSC::fieldName (MSC::REF_DIRECTION));
266 0 : TableMeasRefDesc refDirMeasRef (td, MSC::fieldName (MSC::MEAS_DIR_REF));
267 0 : TableMeasDesc<MDirection> refDirMeasCol (refDirMeasVal, refDirMeasRef);
268 0 : refDirMeasCol.write (td);
269 :
270 0 : return td;
271 0 : };
272 :
273 : //----------------------------------------------------------------------------
274 :
275 0 : TableDesc CalTableDesc::calMainDesc()
276 : {
277 : // Return the main calibration table descriptor
278 : // Output:
279 : // calMainDesc TableDesc Table descriptor (cal_main)
280 : //
281 0 : return itsCalMainDesc;
282 : };
283 :
284 : //----------------------------------------------------------------------------
285 :
286 0 : TableDesc CalTableDesc::calHistoryDesc()
287 : {
288 : // Return the calibration history sub-table descriptor
289 : // Output:
290 : // calHistoryDesc TableDesc Table descriptor (cal_history)
291 : //
292 0 : return itsCalHistoryDesc;
293 : };
294 :
295 : //----------------------------------------------------------------------------
296 :
297 0 : TableDesc CalTableDesc::calDescDesc()
298 : {
299 : // Return the calibration description sub-table descriptor
300 : // Output:
301 : // calDescDesc TableDesc Table descriptor (cal_desc)
302 : //
303 0 : return itsCalDescDesc;
304 : };
305 :
306 : //----------------------------------------------------------------------------
307 :
308 0 : TableDesc CalTableDesc::defaultFitDesc()
309 : {
310 : // Generate the default table descriptor for fit parameters
311 : // Output:
312 : // defaultFitDesc TableDesc Table descriptor (fit parameters)
313 : //
314 0 : TableDesc td;
315 0 : td.addColumn (ScalarColumnDesc <Bool>
316 0 : (MSC::fieldName (MSC::TOTAL_SOLUTION_OK), ColumnDesc::Direct));
317 0 : td.addColumn (ScalarColumnDesc <Float> (MSC::fieldName (MSC::TOTAL_FIT),
318 : ColumnDesc::Direct));
319 0 : td.addColumn (ScalarColumnDesc <Float>
320 0 : (MSC::fieldName (MSC::TOTAL_FIT_WEIGHT), ColumnDesc::Direct));
321 0 : td.addColumn (ArrayColumnDesc <Bool> (MSC::fieldName (MSC::SOLUTION_OK)));
322 0 : td.addColumn (ArrayColumnDesc <Float> (MSC::fieldName (MSC::FIT)));
323 0 : td.addColumn (ArrayColumnDesc <Float> (MSC::fieldName (MSC::FIT_WEIGHT)));
324 0 : td.addColumn (ArrayColumnDesc <Bool> (MSC::fieldName (MSC::FLAG)));
325 0 : td.addColumn (ArrayColumnDesc <Float> (MSC::fieldName (MSC::SNR)));
326 :
327 0 : return td;
328 0 : };
329 :
330 : //----------------------------------------------------------------------------
331 :
332 0 : TableDesc CalTableDesc::defaultPolyDesc()
333 : {
334 : // Generate the default table descriptor for general polynomial parameters
335 : // Output:
336 : // defaultPolyDesc TableDesc Table descriptor (poly parameters)
337 : //
338 0 : TableDesc td;
339 :
340 : // Additional parameters required for general polynomials
341 : // POLY_TYPE - polynomial type (e.g. Chebyshev or spline)
342 : // POLY_MODE - polynomial y-value (e.g. A&P)
343 : // SCALE_FACTOR - overall polynomial scale factor
344 : // VALID_DOMAIN - valid polynomial domain [x_0, x_1]
345 : // N_POLY_AMP - polynomial degree for amplitude
346 : // N_POLY_PHASE - polynomial degree for phase
347 : // POLY_COEFF_AMP - polynomial coefficients for amplitude
348 : // POLY_COEFF_PHASE - polynomial coefficients for phase
349 : // PHASE_UNITS - units for the phase polynomial
350 : //
351 0 : td.addColumn(ScalarColumnDesc<String>(MSC::fieldName(MSC::POLY_TYPE)));
352 0 : td.addColumn(ScalarColumnDesc<String>(MSC::fieldName(MSC::POLY_MODE)));
353 0 : td.addColumn(ScalarColumnDesc<Complex>(MSC::fieldName(MSC::SCALE_FACTOR)));
354 0 : td.addColumn(ArrayColumnDesc<Double>(MSC::fieldName(MSC::VALID_DOMAIN)));
355 0 : td.addColumn(ScalarColumnDesc<Int>(MSC::fieldName(MSC::N_POLY_AMP)));
356 0 : td.addColumn(ScalarColumnDesc<Int>(MSC::fieldName(MSC::N_POLY_PHASE)));
357 0 : td.addColumn(ArrayColumnDesc<Double>(MSC::fieldName(MSC::POLY_COEFF_AMP)));
358 0 : td.addColumn(ArrayColumnDesc<Double>(MSC::fieldName(MSC::POLY_COEFF_PHASE)));
359 0 : td.addColumn(ScalarColumnDesc<String>(MSC::fieldName(MSC::PHASE_UNITS)));
360 :
361 0 : return td;
362 0 : };
363 :
364 : //----------------------------------------------------------------------------
365 :
366 0 : TableDesc CalTableDesc::defaultSplineDesc()
367 : {
368 : // Generate the default table descriptor for spline polynomial parameters
369 : // Output:
370 : // defaultSplineDesc TableDesc Table descriptor (spline parameters)
371 : //
372 0 : TableDesc td;
373 :
374 : // Additional parameters required for spline polynomials.
375 : // N_KNOTS_AMP - number of spline knots in amplitude
376 : // N_KNOTS_PHASE - number of spline knots in phase
377 : // SPLINE_KNOTS_AMP - spline knot positions for amplitude
378 : // SPLINE_KNOTS_PHASE - spline knot positions for phase
379 : //
380 0 : td.addColumn(ScalarColumnDesc<Int>(MSC::fieldName(MSC::N_KNOTS_AMP)));
381 0 : td.addColumn(ScalarColumnDesc<Int>(MSC::fieldName(MSC::N_KNOTS_PHASE)));
382 0 : td.addColumn(ArrayColumnDesc<Double>(MSC::fieldName(MSC::SPLINE_KNOTS_AMP)));
383 0 : td.addColumn(ArrayColumnDesc<Double>
384 0 : (MSC::fieldName(MSC::SPLINE_KNOTS_PHASE)));
385 :
386 0 : return td;
387 0 : };
388 :
389 : //----------------------------------------------------------------------------
390 :
391 0 : TableDesc CalTableDesc::insertDesc (const TableDesc& tableDesc,
392 : const TableDesc& insert,
393 : const String& insertAfter)
394 : {
395 : // Insert one table descriptor into another after a specified
396 : // column name.
397 : // Input:
398 : // tableDesc const TableDesc& Input table descriptor
399 : // insert const TableDesc& Table descriptor to be inserted
400 : // insertAfter const String& Column name to insert after
401 : // Output:
402 : // insertDesc TableDesc Output table descriptor
403 : //
404 0 : TableDesc tdout;
405 : ColumnDesc* colDesc;
406 0 : Int ncol = tableDesc.ncolumn();
407 : Int jcol;
408 :
409 : // Loop over the number of columns in the input table descriptor
410 0 : for (jcol = 0; jcol < ncol; jcol++) {
411 0 : colDesc = new ColumnDesc (tableDesc.columnDesc (jcol));
412 :
413 : // Add column to output descriptor
414 0 : tdout.addColumn (*colDesc);
415 :
416 : // Insert second descriptor if appropriate
417 0 : if (colDesc->name() == insertAfter) {
418 0 : tdout.add (insert);
419 : };
420 0 : delete colDesc;
421 : };
422 :
423 0 : return tdout;
424 0 : };
425 :
426 : //----------------------------------------------------------------------------
427 :
428 :
429 :
430 :
431 : } //# NAMESPACE CASA - END
432 :
|