source: trunk/src/Scantable.h@ 948

Last change on this file since 948 was 923, checked in by mar637, 19 years ago

fixed az/el data type to be Float. added getChannels function. to get cnumber of channels per row. (nchan retrurns by IF)

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