Line data Source code
1 : //# NewCalTable.h: Calibration table access and creation
2 : //# Copyright (C) 2011
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 adressed 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 : //#
27 : //# $Id$
28 :
29 : #ifndef CALIBRATION_NEWCALTABLE_H
30 : #define CALIBRATION_NEWCALTABLE_H
31 :
32 : #include <casacore/casa/aips.h>
33 : #include <casacore/tables/Tables/Table.h>
34 : #include <casacore/tables/TaQL/ExprNode.h>
35 : #include <casacore/casa/Containers/Record.h>
36 : #include <casacore/casa/OS/Path.h>
37 : #include <casacore/casa/Utilities/Sort.h>
38 : #include <casacore/ms/MeasurementSets/MSObservation.h>
39 : #include <casacore/ms/MeasurementSets/MSAntenna.h>
40 : #include <casacore/ms/MeasurementSets/MSField.h>
41 : #include <casacore/ms/MeasurementSets/MSSpectralWindow.h>
42 : #include <casacore/ms/MeasurementSets/MSHistory.h>
43 : #include <casacore/ms/MeasurementSets/MSObsColumns.h>
44 : #include <casacore/ms/MeasurementSets/MSAntennaColumns.h>
45 : #include <casacore/ms/MeasurementSets/MSFieldColumns.h>
46 : #include <casacore/ms/MeasurementSets/MSSpWindowColumns.h>
47 : #include <casacore/ms/MeasurementSets/MSHistoryColumns.h>
48 : #include <synthesis/CalTables/CTDesc.h>
49 : #include <synthesis/CalTables/CTMainRecord.h>
50 : #include <synthesis/CalTables/CTMainColumns.h>
51 : #include <synthesis/CalTables/VisCalEnum.h>
52 : #include <msvis/MSVis/SimpleSimVi2.h>
53 :
54 : namespace casa { //# NAMESPACE CASA - BEGIN
55 :
56 :
57 : // <summary>
58 : // NewCalTable: New Calibration table access and creation
59 : // </summary>
60 :
61 : // <use visibility=export>
62 :
63 : // <reviewed reviewer="" date="" tests="" demos="">
64 :
65 : // <prerequisite>
66 : // <li> <linkto class="CalTableDesc">CalTableDesc</linkto> module
67 : // </prerequisite>
68 : //
69 : // <etymology>
70 : // From "calibration" and "table".
71 : // </etymology>
72 : //
73 : // <synopsis>
74 : // The NewCalTable classes provide basic access to calibration tables. This
75 : // includes the creation of calibration tables, sorting and selection
76 : // capabilities, and basic data access. Specializations for baseline-based,
77 : // time-variable and solvable VisJones types, and sub-types, are provided
78 : // through inheritance.
79 : // </etymology>
80 : //
81 : // <example>
82 : // <srcblock>
83 : // </srcblock>
84 : // </example>
85 : //
86 : // <motivation>
87 : // This class is used by other calibration table accessors and iterators.
88 : // </motivation>
89 : //
90 : // <todo asof="11/06/10">
91 : // </todo>
92 :
93 :
94 : // Typedefs for subtable objects
95 : typedef casacore::MSField CTField;
96 : typedef casacore::MSObservation CTObservation;
97 : typedef casacore::MSAntenna CTAntenna;
98 : typedef casacore::MSSpectralWindow CTSpectralWindow;
99 : typedef casacore::MSHistory CTHistory;
100 : typedef casacore::MSFieldColumns CTFieldColumns;
101 : typedef casacore::MSObservationColumns CTObservationColumns;
102 : typedef casacore::MSAntennaColumns CTAntennaColumns;
103 : typedef casacore::MSSpWindowColumns CTSpWindowColumns;
104 : typedef casacore::MSHistoryColumns CTHistoryColumns;
105 : typedef casacore::MSFieldColumns ROCTFieldColumns;
106 : typedef casacore::MSObservationColumns ROCTObservationColumns;
107 : typedef casacore::MSAntennaColumns ROCTAntennaColumns;
108 : typedef casacore::MSSpWindowColumns ROCTSpWindowColumns;
109 : typedef casacore::MSHistoryColumns ROCTHistoryColumns;
110 :
111 : class NewCalTable : public casacore::Table
112 : {
113 :
114 : friend class SolvableVisCal;
115 :
116 : public:
117 : // Default null constructor, and destructor
118 : NewCalTable();
119 : virtual ~NewCalTable();
120 :
121 : // Construct from a specified table name, calibration table descriptor
122 : // and table access option. Used for creating new tables.
123 : NewCalTable (const casacore::String& tableName, CTDesc& ctableDesc,
124 : casacore::Table::TableOption access = casacore::Table::New,
125 : casacore::Table::TableType ttype = casacore::Table::Plain);
126 :
127 : // Construct from setupNewTable
128 : NewCalTable (casacore::SetupNewTable& newTab, casacore::uInt nrow = 0, casacore::Bool initialize = false);
129 :
130 : // Create an empty NewCalTable conveniently
131 : NewCalTable(casacore::String tableName,VisCalEnum::VCParType parType,
132 : casacore::String typeName,casacore::String msName,casacore::Bool doSingleChan);
133 :
134 : // Construct from a specified table name, and access option. Used
135 : // for accessing existing tables.
136 : NewCalTable (const casacore::String& tableName,
137 : casacore::Table::TableOption access = casacore::Table::Old,
138 : casacore::Table::TableType ttype = casacore::Table::Memory);
139 : // control locking option
140 : NewCalTable (const casacore::String& tableName,
141 : const casacore::TableLock& lockOptions,
142 : casacore::Table::TableOption access = casacore::Table::Old,
143 : casacore::Table::TableType ttype = casacore::Table::Memory);
144 :
145 : static NewCalTable createCT(const casacore::String& tableName,
146 : casacore::Table::TableOption access,
147 : casacore::Table::TableType ttype,
148 : casacore::Bool doBackCompat=true);
149 :
150 : static NewCalTable* createCTptr(const casacore::String& tableName,
151 : casacore::Table::TableOption access,
152 : casacore::Table::TableType ttype,
153 : casacore::Bool doBackCompat=true);
154 :
155 :
156 :
157 : // Construct from an existing table object
158 : NewCalTable (const casacore::Table& table);
159 :
160 : // Copy constructor
161 : NewCalTable (const NewCalTable& other);
162 :
163 : // Create a vanilla NewCalTable from shapes (for testing purposes)
164 : // Default rTime is 2012/01/06/12:00:00
165 : NewCalTable(casacore::String tableName,casacore::String CorF,
166 : casacore::Int nObs=1, casacore::Int nScanPerObs=1,casacore::Int nTimePerScan=1,
167 : casacore::Int nAnt=1, casacore::Int nSpw=1, casacore::Vector<casacore::Int> nChan=casacore::Vector<casacore::Int>(1,1),
168 : casacore::Int nFld=1,
169 : casacore::Double rTime=0.0, casacore::Double tint=0.0,
170 : casacore::Bool disk=false, casacore::Bool verbose=false);
171 :
172 : // Create an empty NewCalTable from a SimpleSimVi2Parameters object
173 : // NB: only for testing, for now
174 : NewCalTable(casacore::String tableName, casacore::String CorF, casacore::String caltype,
175 : const vi::SimpleSimVi2Parameters& ssp,
176 : casacore::Bool disk=false,casacore::Bool verbose=false);
177 :
178 : // Assignment operator
179 : NewCalTable& operator= (const NewCalTable& other);
180 :
181 : // Handle backward compatibility
182 : static casacore::Bool CTBackCompat(const casacore::String& caltable);
183 :
184 : // Set the casacore::TableInfo record
185 : void setTableInfo();
186 :
187 : // initialize reference to subtables
188 : void createSubTables();
189 : void attachSubTables();
190 : void clearSubtables();
191 :
192 : void copyMemCalSubtables(const NewCalTable& other);
193 : void copyMemCalSubtable(const casacore::Table& otherSubtable, casacore::Table& subTable);
194 :
195 : // casacore::Complex parameters? (else casacore::Float)
196 : casacore::Bool isComplex();
197 :
198 : // Report the polarization basis (from header record)
199 : casacore::String polBasis();
200 :
201 : // Report the CASA version at which the NCT was created (from header)
202 : casacore::String CASAvers();
203 :
204 : // Get a row from cal_main
205 : casacore::Record getRowMain (const casacore::Int& jrow);
206 :
207 : // Put a row to cal_main
208 : void putRowMain (const casacore::Int& jrow, CTMainRecord& tableRec);
209 :
210 : // Get rows of the data from the main table
211 : // void fillRowsMain ();
212 :
213 : // Set Meta data info from a parent casacore::MS
214 : void setMetaInfo (const casacore::String& msName);
215 :
216 : //validate input table desc. over required caltable desc
217 : static casacore::Bool conformant(const casacore::TableDesc& tabDesc);
218 :
219 : // save to disk
220 : void writeToDisk(const casacore::String& tableName);
221 :
222 4 : CTObservation& observation() {return observation_p;}
223 4 : CTAntenna& antenna() {return antenna_p;}
224 4 : CTField& field() {return field_p;}
225 4 : CTSpectralWindow& spectralWindow() {return spectralWindow_p;}
226 0 : CTHistory& history() {return history_p;}
227 2 : const CTObservation& observation() const {return observation_p;}
228 2 : const CTAntenna& antenna() const {return antenna_p;}
229 2 : const CTField& field() const {return field_p;}
230 2 : const CTSpectralWindow& spectralWindow() const {return spectralWindow_p;}
231 2 : const CTHistory& history() const {return history_p;}
232 :
233 : // Provide RO access to
234 : // inline ROCTMainColumns mcols() const {return ROCTMainColumns(*this);};
235 :
236 : static casacore::Complex NCTtestvalueC(casacore::Int iant,casacore::Int ispw,casacore::Double ich,casacore::Double time,casacore::Double refTime,casacore::Double tint);
237 : static casacore::Float NCTtestvalueF(casacore::Int iant,casacore::Int ispw,casacore::Double ich,casacore::Double time,casacore::Double refTime,casacore::Double tint);
238 :
239 : // Fill in antenna-based solutions
240 : // (obsId-less version calls obsId-capable version w/ obsId=0)
241 : void fillAntBasedMainRows(casacore::uInt nrows,
242 : casacore::Double time,casacore::Double interval,
243 : casacore::Int fieldId,casacore::uInt spwId,casacore::Int scanNo,
244 : const casacore::Vector<casacore::Int>& ant1list, casacore::Int refant,
245 : const casacore::Cube<casacore::Complex>& cparam,
246 : const casacore::Cube<casacore::Bool>& flag,
247 : const casacore::Cube<casacore::Float>& paramErr,
248 : const casacore::Cube<casacore::Float>& snr);
249 : void fillAntBasedMainRows(casacore::uInt nrows,
250 : casacore::Double time,casacore::Double interval,
251 : casacore::Int fieldId,casacore::uInt spwId,casacore::Int obsId,casacore::Int scanNo,
252 : const casacore::Vector<casacore::Int>& ant1list, casacore::Int refant,
253 : const casacore::Cube<casacore::Complex>& cparam,
254 : const casacore::Cube<casacore::Bool>& flag,
255 : const casacore::Cube<casacore::Float>& paramErr,
256 : const casacore::Cube<casacore::Float>& snr);
257 :
258 : // Reset spw freq info
259 : void setSpwFreqs(casacore::Int spw, const casacore::Vector<casacore::Double>& freq,
260 : const casacore::Vector<casacore::Double>& chanwidth=casacore::Vector<casacore::Double>());
261 :
262 : // Set FLAG_ROW in SPECTRAL_WINDOW subtable for spws absent in MAIN
263 : void flagAbsentSpws();
264 :
265 : // Merge SPW subtable rows from another NewCalTable
266 : void mergeSpwMetaInfo(const NewCalTable& other);
267 :
268 : // Add a line to the HISTORY table
269 : void addHistoryMessage(casacore::String app="",casacore::String message="none");
270 :
271 : private:
272 :
273 : // Services for generic test table ctor
274 : // Default rTime is 2012/01/06/12:00:00
275 : void fillGenericContents(casacore::Int nObs=1, casacore::Int nScanPerObs=1, casacore::Int nTimePerScan=1,
276 : casacore::Int nAnt=1, casacore::Int nSpw=1, casacore::Vector<casacore::Int> nChan=casacore::Vector<casacore::Int>(1,1),
277 : casacore::Int nFld=1,
278 : casacore::Double rTime=0.0, casacore::Double tint=0.0,
279 : casacore::Bool verbose=false);
280 : void fillGenericObs(casacore::Int nObs);
281 : void fillGenericField(casacore::Int nFld);
282 : void fillGenericAntenna(casacore::Int nAnt);
283 : void fillGenericSpw(casacore::Int nSpw,casacore::Vector<casacore::Int>& nChan);
284 :
285 : // Init subtables from SimpleSimVi2Parameters
286 : void fillGenericObs(const vi::SimpleSimVi2Parameters& ssp);
287 : void fillGenericField(const vi::SimpleSimVi2Parameters& ssp);
288 : void fillGenericAntenna(const vi::SimpleSimVi2Parameters& ssp);
289 : void fillGenericSpw(const vi::SimpleSimVi2Parameters& ssp);
290 :
291 : // Force Spw subtable to be all nchan=1
292 : // (very basic; uses chan n/2 freq)
293 : void makeSpwSingleChan();
294 :
295 : // Handle pre-4.1 caltables that don't have OBS_ID
296 : // (by adding a phoney one with a single OBS_ID
297 : void addPhoneyObs();
298 :
299 : // Handle Eph objects...
300 : void handleEphObj(const casacore::MSField& msfldtab,const casacore::String& msName);
301 :
302 :
303 : // The subtables
304 : CTObservation observation_p;
305 : CTAntenna antenna_p;
306 : CTField field_p;
307 : CTSpectralWindow spectralWindow_p;
308 : CTHistory history_p;
309 :
310 : };
311 :
312 : } //# NAMESPACE CASA - END
313 :
314 : #endif
|