source: trunk/src/Scantable.h @ 846

Last change on this file since 846 was 845, checked in by mar637, 18 years ago

changed getSDHeader -> getHeader
changed nrow interface
added ncycle()

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 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 "SDLog.h"
33#include "SDContainer.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
41
42
43namespace asap {
44
45/**
46  * This class contains and wraps a casa::Table, which is used to store
47  * all the information. This can be either a MemoryTable or a
48  * disk based Table.
49  * It provides access functions to the underlying table
50  * It contains n subtables:
51  * @li weather
52  * @li frequencies
53  * @li molecules
54  * @li tcal
55  * @li focus
56  * @li fits
57  *
58  * @brief The main ASAP data container
59  * @author Malte Marquarding
60  * @date
61  * @version
62*/
63class Scantable : private SDLog
64{
65public:
66  /**
67   * Default constructor
68   */
69  Scantable(casa::Table::TableType ttype = casa::Table::Memory);
70
71  /**
72   * Create a Scantable object form an existing table on disk
73   * @param[in] name the name of the existing Scantable
74   */
75  Scantable(const std::string& name, casa::Table::TableType ttype = casa::Table::Memory);
76
77  /// @fixme this is only sensible for MemoryTables....
78  Scantable(const Scantable& other, bool clear=true);
79
80  /**
81   * Destructor
82   */
83  virtual ~Scantable();
84
85  /**
86   * get a const reference to the underlying casa::Table
87   * @return consantcasa::Table reference
88   */
89  const casa::Table& table() const;
90
91  /**
92   * get a reference to the underlying casa::Table with the Selection
93   * object applied if set
94   * @return casa::Table reference
95   */
96  casa::Table& table();
97
98
99  /**
100   * Get a handle to the selection object
101   * @return constant STSelector reference
102   */
103  const STSelector& getSelection() const { return selector_; }
104
105  /**
106   * Set the data to be a subset as defined by the STSelector
107   * @param selection a STSelector object
108   */
109  void setSelection(const STSelector& selection);
110
111  /**
112   * unset the selection of the data
113   */
114  void unsetSelection();
115  /**
116   * set the header
117   * @param[in] sdh an SDHeader object
118   */
119  void setHeader( const SDHeader& sdh );
120
121  /**
122   * get the header information
123   * @return an SDHeader object
124   */
125  SDHeader getHeader( ) const;
126  /**
127   * Checks if the "other" Scantable is conformant with this,
128   * i.e. if  header values are the same.
129   * @param[in] other another Scantable
130   * @return true or false
131   */
132  bool conformant( const Scantable& other);
133
134  /**
135   * return the number of scans in the table
136   * @return number of scans in the table
137   */
138  int nscan() const;
139
140  //casa::MDirection::Types getDirectionReference() const;
141  //casa::MEpoch::Types getTimeReference() const;
142
143  /**
144   * Get global antenna position
145   * @return casa::MPosition
146   */
147  casa::MPosition getAntennaPosition() const;
148
149  /**
150   *  Return the Flux unit of the data, e.g. "Jy" or "K"
151   * @return string
152   */
153  std::string getFluxUnit() const;
154
155  /**
156   * Set the Flux unit of the data
157   * @param unit a string representing the unit, e.g "Jy" or "K"
158   */
159  void setFluxUnit( const std::string& unit );
160
161  /**
162   *
163   * @param instrument a string representing an insturment. see xxx
164   */
165  void setInstrument( const std::string& instrument );
166
167  /**
168   * (Re)calculate the azimuth and elevationnfor all rows
169   */
170  void calculateAZEL();
171
172  /**
173   * "hard" flag the data, this flags everything selected in setSelection()
174   */
175  void flag();
176
177
178  /**
179   * Get the number of beams in the data or a specific scan
180   * @param scanno the scan number to get the number of beams for.
181   * If scanno<0 the number is retrieved from the header.
182   * @return an integer number
183   */
184  int nbeam(int scanno=-1) const;
185  /**
186   * Get the number of IFs in the data or a specific scan
187   * @param scanno the scan number to get the number of IFs for.
188   * If scanno<0 the number is retrieved from the header.
189   * @return an integer number
190   */
191  int nif(int scanno=-1) const;
192  /**
193   * Get the number of polarizations in the data or a specific scan
194   * @param scanno the scan number to get the number of polarizations for.
195   * If scanno<0 the number is retrieved from the header.
196   * @return an integer number
197   */
198  int npol(int scanno=-1) const;
199
200  /**
201   * Get the number of channels in the data or a specific IF. This currently
202   * varies only with IF number
203   * @param ifno the IF number to get the number of channels for.
204   * If ifno<0 the number is retrieved from the header.
205   * @return an integer number
206   */
207  int nchan(int ifno=-1) const;
208
209  /**
210   * Get the number of integartion cycles
211   * @param scanno the scan number to get the number of rows for.
212   * If scanno<0 the number is retrieved from the header.
213   * @return
214   */
215  int nrow(int scanno=-1) const;
216
217  int ncycle(int scanno=-1) const;
218
219  double getInterval(int scanno=0) const;
220
221  float getTsys(int scanno=0) const;
222
223  std::vector<bool> getMask(int whichrow=0) const;
224  std::vector<float> getSpectrum(int whichrow=0) const;
225
226  std::vector<float> getStokesSpectrum( int whichrow=0,
227                                        bool dopol=false) const;
228  std::string getPolarizationLabel(bool linear, bool stokes,
229                                   bool linpol,
230                                   int polidx=-1) const;
231
232  /**
233   * Write the Scantable to disk
234   * @param filename the output file name
235   */
236  void makePersistent(const std::string& filename);
237
238  std::vector<std::string> getHistory() const;
239  void addHistory(const std::string& hist);
240
241  casa::Table getHistoryTable() const;
242  void appendToHistoryTable(const casa::Table& otherHist);
243
244  std::string summary(bool verbose=false);
245  std::string getTime(int whichrow=-1, bool showdate=true) const;
246
247
248  STFrequencies& frequencies() { return freqTable_; }
249  STWeather& weather() { return weatherTable_; }
250  STFocus& focus() { return focusTable_; }
251  STTcal& tcal() { return tcalTable_; }
252  STMolecules& molecules() { return moleculeTable_; }
253
254private:
255  /**
256   * Turns a time vale into a formatted string
257   * @param x
258   * @return
259   */
260  std::string formatSec(casa::Double x) const;
261
262  std::string formatTime(const casa::MEpoch& me, bool showdate)const;
263
264  /**
265   *  Turns a casa::MDirection into a nicely formatted string
266   * @param md an casa::MDirection
267   * @return
268   */
269  std::string formatDirection(const casa::MDirection& md) const;
270
271
272  /**
273   * Create a unique file name for the paged (temporary) table
274   * @return just the name
275   */
276  static casa::String generateName();
277
278  /**
279   * attach to cached columns
280   */
281  void attach();
282
283  /**
284   * Set up the main casa::Table
285   */
286  void setupMainTable();
287
288  void setupHistoryTable();
289  void setupMoleculeTable();
290  void setupFitTable();
291
292  /**
293   * Convert an "old" asap1 style row index into a new index
294   * @param[in] therow
295   * @return and index into @table_
296   */
297  int rowToScanIndex(int therow);
298
299  static const unsigned int version_ = 2;
300
301  STSelector selector_;
302
303  casa::Table::TableType type_;
304
305  // the actual data
306  casa::Table table_;
307  casa::Table originalTable_;
308
309  STTcal tcalTable_;
310  STFrequencies freqTable_;
311  STWeather weatherTable_;
312  STFocus focusTable_;
313  STMolecules moleculeTable_;
314  casa::Table fitTable_;
315  casa::Table historyTable_;
316
317  // Cached Columns to avoid reconstructing them for each row get/put
318  casa::ScalarColumn<casa::Double> timeCol_, integrCol_;
319  casa::MDirection::ScalarColumn dirCol_;
320  casa::ScalarColumn<casa::Double> azCol_;
321  casa::ScalarColumn<casa::Double> elCol_;
322  casa::ScalarColumn<casa::Float> paraCol_;
323  casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
324  casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, cycleCol_;
325  casa::ScalarColumn<casa::Int> rbeamCol_;
326  casa::ArrayColumn<casa::Float> specCol_, tsCol_;
327  casa::ArrayColumn<casa::uChar> flagsCol_;
328
329  // id in frequencies table
330  casa::ScalarColumn<casa::uInt> mfreqidCol_;
331  // id in tcal table
332  casa::ScalarColumn<casa::uInt> mtcalidCol_;
333
334  casa::ArrayColumn<casa::String> histitemCol_;
335  casa::ScalarColumn<casa::uInt> mfitidCol_, fitidCol_;
336  // id in weather table and main table
337  casa::ScalarColumn<casa::uInt> mweatheridCol_;
338
339  casa::ScalarColumn<casa::uInt> mfocusidCol_;
340
341  casa::ScalarColumn<casa::uInt> mmolidCol_;
342
343};
344
345
346} // namespace
347
348#endif
Note: See TracBrowser for help on using the repository browser.