source: trunk/src/Scantable.h@ 962

Last change on this file since 962 was 960, checked in by mar637, 19 years ago

c++ side of Ticket #7

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