source: branches/Release2.0/src/Scantable.h@ 1978

Last change on this file since 1978 was 1030, checked in by mar637, 19 years ago

Various fixes to make >=gcc-3.4 compliant

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1//
2// C++ Interface: Scantable
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2005
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef ASAPSCANTABLE_H
13#define ASAPSCANTABLE_H
14
15// STL
16#include <string>
17#include <vector>
18// AIPS++
19#include <casa/aips.h>
20#include <casa/Arrays/MaskedArray.h>
21#include <casa/BasicSL/String.h>
22#include <casa/Utilities/CountedPtr.h>
23
24#include <coordinates/Coordinates/SpectralCoordinate.h>
25
26#include <tables/Tables/Table.h>
27#include <tables/Tables/ArrayColumn.h>
28#include <tables/Tables/ScalarColumn.h>
29
30#include <measures/TableMeasures/ScalarMeasColumn.h>
31
32#include "Logger.h"
33#include "STHeader.h"
34#include "STFrequencies.h"
35#include "STWeather.h"
36#include "STFocus.h"
37#include "STTcal.h"
38#include "STMolecules.h"
39#include "STSelector.h"
40#include "STHistory.h"
41#include "STPol.h"
42#include "STFit.h"
43#include "STFitEntry.h"
44
45namespace asap {
46
47/**
48 * This class contains and wraps a casa::Table, which is used to store
49 * all the information. This can be either a MemoryTable or a
50 * disk based Table.
51 * It provides access functions to the underlying table
52 * It contains n subtables:
53 * @li weather
54 * @li frequencies
55 * @li molecules
56 * @li tcal
57 * @li focus
58 * @li fits
59 *
60 * @brief The main ASAP data container
61 * @author Malte Marquarding
62 * @date
63 * @version
64*/
65class Scantable : private Logger
66{
67
68friend class STMath;
69
70public:
71 /**
72 * Default constructor
73 */
74 Scantable(casa::Table::TableType ttype = casa::Table::Memory);
75
76 /**
77 * Create a Scantable object form an existing table on disk
78 * @param[in] name the name of the existing Scantable
79 */
80 Scantable(const std::string& name, casa::Table::TableType ttype = casa::Table::Memory);
81
82 /// @fixme this is only sensible for MemoryTables....
83 Scantable(const Scantable& other, bool clear=true);
84
85 /**
86 * Destructor
87 */
88 virtual ~Scantable();
89
90 /**
91 * get a const reference to the underlying casa::Table
92 * @return consantcasa::Table reference
93 */
94 const casa::Table& table() const;
95
96 /**
97 * get a reference to the underlying casa::Table with the Selection
98 * object applied if set
99 * @return casa::Table reference
100 */
101 casa::Table& table();
102
103
104 /**
105 * Get a handle to the selection object
106 * @return constant STSelector reference
107 */
108 const STSelector& getSelection() const { return selector_; }
109
110 /**
111 * Set the data to be a subset as defined by the STSelector
112 * @param selection a STSelector object
113 */
114 void setSelection(const STSelector& selection);
115
116 /**
117 * unset the selection of the data
118 */
119 void unsetSelection();
120 /**
121 * set the header
122 * @param[in] sdh an STHeader object
123 */
124 void setHeader( const STHeader& sth );
125
126 /**
127 * get the header information
128 * @return an STHeader object
129 */
130 STHeader getHeader( ) const;
131 /**
132 * Checks if the "other" Scantable is conformant with this,
133 * i.e. if header values are the same.
134 * @param[in] other another Scantable
135 * @return true or false
136 */
137 bool conformant( const Scantable& other);
138
139 /**
140 * return the number of scans in the table
141 * @return number of scans in the table
142 */
143 int nscan() const;
144
145 casa::MEpoch::Types getTimeReference() const;
146
147 /**
148 * Get global antenna position
149 * @return casa::MPosition
150 */
151 casa::MPosition getAntennaPosition() const;
152
153 casa::MDirection getDirection( int whichrow ) const;
154
155 void setDirectionRefString(const std::string& refstr="");
156
157 std::string getDirectionRefString() const;
158
159 /**
160 * Return the Flux unit of the data, e.g. "Jy" or "K"
161 * @return string
162 */
163 std::string getFluxUnit() const;
164
165 /**
166 * Set the Flux unit of the data
167 * @param unit a string representing the unit, e.g "Jy" or "K"
168 */
169 void setFluxUnit( const std::string& unit );
170
171 /**
172 *
173 * @param instrument a string representing an insturment. see xxx
174 */
175 void setInstrument( const std::string& instrument );
176
177 /**
178 * (Re)calculate the azimuth and elevationnfor all rows
179 */
180 void calculateAZEL();
181
182 /**
183 * "hard" flag the data, this flags everything selected in setSelection()
184 */
185 void flag( const std::vector<bool>& msk = std::vector<bool>());
186
187 /**
188 * Return a list of row numbers with respect to the original table.
189 * @return a list of unsigned ints
190 */
191 std::vector<unsigned int> rownumbers() const;
192
193
194 /**
195 * Get the number of beams in the data or a specific scan
196 * @param scanno the scan number to get the number of beams for.
197 * If scanno<0 the number is retrieved from the header.
198 * @return an integer number
199 */
200 int nbeam(int scanno=-1) const;
201 /**
202 * Get the number of IFs in the data or a specific scan
203 * @param scanno the scan number to get the number of IFs for.
204 * If scanno<0 the number is retrieved from the header.
205 * @return an integer number
206 */
207 int nif(int scanno=-1) const;
208 /**
209 * Get the number of polarizations in the data or a specific scan
210 * @param scanno the scan number to get the number of polarizations for.
211 * If scanno<0 the number is retrieved from the header.
212 * @return an integer number
213 */
214 int npol(int scanno=-1) const;
215
216 std::string getPolType() const;
217
218 /**
219 * Get the number of channels in the data or a specific IF. This currently
220 * varies only with IF number
221 * @param ifno the IF number to get the number of channels for.
222 * If ifno<0 the number is retrieved from the header.
223 * @return an integer number
224 */
225 int nchan(int ifno=-1) const;
226
227 /**
228 * Get the number of integartion cycles
229 * @param scanno the scan number to get the number of rows for.
230 * If scanno<0 the number is retrieved from the header.
231 * @return
232 */
233 int nrow(int scanno=-1) const;
234
235 int ncycle(int scanno=-1) const;
236
237 int getBeam(int whichrow) const;
238 int getIF(int whichrow) const;
239 int getPol(int whichrow) const;
240 int getCycle(int whichrow) const { return cycleCol_(whichrow); }
241 int getScan(int whichrow) const { return scanCol_(whichrow); }
242 int getChannels(int whichrow) const;
243
244 double getInterval(int whichrow) const
245 { return integrCol_(whichrow); }
246
247 float getTsys(int whichrow) const
248 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
249 float getElevation(int whichrow) const
250 { return elCol_(whichrow); }
251 float getAzimuth(int whichrow) const
252 { return azCol_(whichrow); }
253 float getParAngle(int whichrow) const
254 { return paraCol_(whichrow); }
255
256 std::string getSourceName(int whichrow) const
257 { return srcnCol_(whichrow); }
258
259 std::vector<bool> getMask(int whichrow) const;
260 std::vector<float> getSpectrum(int whichrow,
261 const std::string& poltype = "" ) const;
262
263 void setSpectrum(const std::vector<float>& spec, int whichrow);
264
265 std::string getPolarizationLabel(int index, const std::string& ptype) const
266 { return STPol::getPolLabel(index, ptype ); }
267
268 /**
269 * Write the Scantable to disk
270 * @param filename the output file name
271 */
272 void makePersistent(const std::string& filename);
273
274 std::vector<std::string> getHistory() const
275 { return historyTable_.getHistory(); };
276
277 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
278
279 void appendToHistoryTable(const STHistory& otherhist)
280 { historyTable_.append(otherhist); }
281
282 std::string summary(bool verbose=false);
283 std::string getTime(int whichrow=-1, bool showdate=true) const;
284
285 // returns unit, conversion frame, doppler, base-frame
286
287 /**
288 * Get the frequency set up
289 * This is forwarded to the STFrequencies subtable
290 * @return unit, frame, doppler
291 */
292 std::vector<std::string> getCoordInfo() const
293 { return freqTable_.getInfo(); };
294
295 void setCoordInfo(std::vector<string> theinfo)
296 { return freqTable_.setInfo(theinfo); };
297
298
299 std::vector<double> getAbcissa(int whichrow) const;
300
301 std::string getAbcissaLabel(int whichrow) const;
302 std::vector<double> getRestFrequencies() const
303 { return moleculeTable_.getRestFrequencies(); }
304
305 void setRestFrequencies(double rf, const std::string& = "Hz");
306 void setRestFrequencies(const std::string& name);
307
308 void convertDirection(const std::string& newframe);
309
310 STFrequencies& frequencies() { return freqTable_; }
311 STWeather& weather() { return weatherTable_; }
312 STFocus& focus() { return focusTable_; }
313 STTcal& tcal() { return tcalTable_; }
314 STMolecules& molecules() { return moleculeTable_; }
315 STHistory& history() { return historyTable_; }
316 STFit& fit() { return fitTable_; }
317
318 std::vector<std::string> columnNames() const;
319
320 void addFit(const STFitEntry& fit, int row);
321 STFitEntry getFit(int row) const
322 { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
323
324private:
325
326 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
327
328 /**
329 * Turns a time vale into a formatted string
330 * @param x
331 * @return
332 */
333 std::string formatSec(casa::Double x) const;
334
335 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
336
337 /**
338 * Turns a casa::MDirection into a nicely formatted string
339 * @param md an casa::MDirection
340 * @return
341 */
342 std::string formatDirection(const casa::MDirection& md) const;
343
344
345 /**
346 * Create a unique file name for the paged (temporary) table
347 * @return just the name
348 */
349 static casa::String generateName();
350
351 /**
352 * attach to cached columns
353 */
354 void attach();
355
356 /**
357 * Set up the main casa::Table
358 */
359 void setupMainTable();
360
361 void attachSubtables();
362 void copySubtables(const Scantable& other);
363
364 /**
365 * Convert an "old" asap1 style row index into a new index
366 * @param[in] therow
367 * @return and index into @table_
368 */
369 int rowToScanIndex(int therow);
370
371 static const casa::uInt version_ = 2;
372
373 STSelector selector_;
374
375 casa::Table::TableType type_;
376
377 // the actual data
378 casa::Table table_;
379 casa::Table originalTable_;
380
381 STTcal tcalTable_;
382 STFrequencies freqTable_;
383 STWeather weatherTable_;
384 STFocus focusTable_;
385 STMolecules moleculeTable_;
386 STHistory historyTable_;
387 STFit fitTable_;
388
389 // Cached Columns to avoid reconstructing them for each row get/put
390 casa::ScalarColumn<casa::Double> integrCol_;
391 casa::MDirection::ScalarColumn dirCol_;
392 casa::MEpoch::ScalarColumn timeCol_;
393 casa::ScalarColumn<casa::Float> azCol_;
394 casa::ScalarColumn<casa::Float> elCol_;
395 casa::ScalarColumn<casa::Float> paraCol_;
396 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
397 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
398 casa::ScalarColumn<casa::Int> rbeamCol_;
399 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
400 casa::ArrayColumn<casa::uChar> flagsCol_;
401
402 // id in frequencies table
403 casa::ScalarColumn<casa::uInt> mfreqidCol_;
404 // id in tcal table
405 casa::ScalarColumn<casa::uInt> mtcalidCol_;
406
407 casa::ArrayColumn<casa::String> histitemCol_;
408 casa::ScalarColumn<casa::Int> mfitidCol_;
409 casa::ScalarColumn<casa::uInt> mweatheridCol_;
410
411 casa::ScalarColumn<casa::uInt> mfocusidCol_;
412
413 casa::ScalarColumn<casa::uInt> mmolidCol_;
414
415 static std::map<std::string, STPol::STPolFactory *> factories_;
416 void initFactories();
417
418};
419
420
421} // namespace
422
423#endif
Note: See TracBrowser for help on using the repository browser.