source: trunk/src/Scantable.h@ 1110

Last change on this file since 1110 was 1104, checked in by mar637, 18 years ago

added doxygen documentation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 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 const \ref casa::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 /**
133 * Checks if the "other" Scantable is conformant with this,
134 * i.e. if header values are the same.
135 * @param[in] other another Scantable
136 * @return true or false
137 */
138 bool conformant( const Scantable& other);
139
140 /**
141 *
142 * @param stype The type of the source, 0 = on, 1 = off
143 */
144 void setSourceType(int stype);
145
146
147 /**
148 * The number of scans in the table
149 * @return number of scans in the table
150 */
151 int nscan() const;
152
153 casa::MEpoch::Types getTimeReference() const;
154
155 /**
156 * Get global antenna position
157 * @return casa::MPosition
158 */
159 casa::MPosition getAntennaPosition() const;
160
161 /**
162 * the @ref casa::MDirection for a specific row
163 * @param[in] whichrow the row number
164 * return casa::MDirection
165 */
166 casa::MDirection getDirection( int whichrow ) const;
167
168 /**
169 * get the direction type as a string, e.g. "J2000"
170 * @param[in] whichrow the row number
171 * return the direction string
172 */
173 std::string getDirectionString( int whichrow ) const;
174
175 /**
176 * set the direction type as a string, e.g. "J2000"
177 * @param[in] the direction type
178 */
179 void setDirectionRefString(const std::string& refstr="");
180 /**
181 * get the direction reference string
182 * @return a string describing the direction reference
183 */
184 std::string getDirectionRefString() const; /**
185 * get the direction type as a string, e.g. "J2000"
186 * param[in] whichrow the row number
187 * return the direction string
188 */
189
190
191 /**
192 * Return the Flux unit of the data, e.g. "Jy" or "K"
193 * @return string
194 */
195 std::string getFluxUnit() const;
196
197 /**
198 * Set the Flux unit of the data
199 * @param unit a string representing the unit, e.g "Jy" or "K"
200 */
201 void setFluxUnit( const std::string& unit );
202
203 /**
204 *
205 * @param instrument a string representing an insturment. see xxx
206 */
207 void setInstrument( const std::string& instrument );
208
209 /**
210 * (Re)calculate the azimuth and elevationnfor all rows
211 */
212 void calculateAZEL();
213
214 /**
215 * "hard" flag the data, this flags everything selected in setSelection()
216 * param[in] msk a boolean mask of length nchan describing the points to
217 * to be flagged
218 */
219 void flag( const std::vector<bool>& msk = std::vector<bool>());
220
221 /**
222 * Return a list of row numbers with respect to the original table.
223 * @return a list of unsigned ints
224 */
225 std::vector<unsigned int> rownumbers() const;
226
227
228 /**
229 * Get the number of beams in the data or a specific scan
230 * @param scanno the scan number to get the number of beams for.
231 * If scanno<0 the number is retrieved from the header.
232 * @return an integer number
233 */
234 int nbeam(int scanno=-1) const;
235 /**
236 * Get the number of IFs in the data or a specific scan
237 * @param scanno the scan number to get the number of IFs for.
238 * If scanno<0 the number is retrieved from the header.
239 * @return an integer number
240 */
241 int nif(int scanno=-1) const;
242 /**
243 * Get the number of polarizations in the data or a specific scan
244 * @param scanno the scan number to get the number of polarizations for.
245 * If scanno<0 the number is retrieved from the header.
246 * @return an integer number
247 */
248 int npol(int scanno=-1) const;
249
250 std::string getPolType() const;
251
252 /**
253 * Get the number of channels in the data or a specific IF. This currently
254 * varies only with IF number
255 * @param ifno the IF number to get the number of channels for.
256 * If ifno<0 the number is retrieved from the header.
257 * @return an integer number
258 */
259 int nchan(int ifno=-1) const;
260
261 /**
262 * Get the number of integartion cycles
263 * @param scanno the scan number to get the number of rows for.
264 * If scanno<0 the number is retrieved from the header.
265 * @return the number of rows (for the specified scanno)
266 */
267 int nrow(int scanno=-1) const;
268
269 int ncycle(int scanno=-1) const;
270
271 int getBeam(int whichrow) const;
272 int getIF(int whichrow) const;
273 int getPol(int whichrow) const;
274 int getCycle(int whichrow) const { return cycleCol_(whichrow); }
275 int getScan(int whichrow) const { return scanCol_(whichrow); }
276 int getChannels(int whichrow) const;
277
278 double getInterval(int whichrow) const
279 { return integrCol_(whichrow); }
280
281 float getTsys(int whichrow) const
282 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
283 float getElevation(int whichrow) const
284 { return elCol_(whichrow); }
285 float getAzimuth(int whichrow) const
286 { return azCol_(whichrow); }
287 float getParAngle(int whichrow) const
288 { return paraCol_(whichrow); }
289
290 std::string getSourceName(int whichrow) const
291 { return srcnCol_(whichrow); }
292
293 std::vector<bool> getMask(int whichrow) const;
294 std::vector<float> getSpectrum(int whichrow,
295 const std::string& poltype = "" ) const;
296
297 void setSpectrum(const std::vector<float>& spec, int whichrow);
298
299 std::string getPolarizationLabel(int index, const std::string& ptype) const
300 { return STPol::getPolLabel(index, ptype ); }
301
302 /**
303 * Write the Scantable to disk
304 * @param filename the output file name
305 */
306 void makePersistent(const std::string& filename);
307
308 std::vector<std::string> getHistory() const
309 { return historyTable_.getHistory(); };
310
311 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
312
313 void appendToHistoryTable(const STHistory& otherhist)
314 { historyTable_.append(otherhist); }
315
316 std::string summary(bool verbose=false);
317 std::string getTime(int whichrow=-1, bool showdate=true) const;
318
319 // returns unit, conversion frame, doppler, base-frame
320
321 /**
322 * Get the frequency set up
323 * This is forwarded to the STFrequencies subtable
324 * @return unit, frame, doppler
325 */
326 std::vector<std::string> getCoordInfo() const
327 { return freqTable_.getInfo(); };
328
329 void setCoordInfo(std::vector<string> theinfo)
330 { return freqTable_.setInfo(theinfo); };
331
332
333 std::vector<double> getAbcissa(int whichrow) const;
334
335 std::string getAbcissaLabel(int whichrow) const;
336 std::vector<double> getRestFrequencies() const
337 { return moleculeTable_.getRestFrequencies(); }
338
339 void setRestFrequencies(double rf, const std::string& = "Hz");
340 void setRestFrequencies(const std::string& name);
341
342 void convertDirection(const std::string& newframe);
343
344 STFrequencies& frequencies() { return freqTable_; }
345 STWeather& weather() { return weatherTable_; }
346 STFocus& focus() { return focusTable_; }
347 STTcal& tcal() { return tcalTable_; }
348 STMolecules& molecules() { return moleculeTable_; }
349 STHistory& history() { return historyTable_; }
350 STFit& fit() { return fitTable_; }
351
352 std::vector<std::string> columnNames() const;
353
354 void addFit(const STFitEntry& fit, int row);
355 STFitEntry getFit(int row) const
356 { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
357
358private:
359
360 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
361
362 /**
363 * Turns a time vale into a formatted string
364 * @param x
365 * @return
366 */
367 std::string formatSec(casa::Double x) const;
368
369 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
370
371 /**
372 * Turns a casa::MDirection into a nicely formatted string
373 * @param md an casa::MDirection
374 * @return
375 */
376 std::string formatDirection(const casa::MDirection& md) const;
377
378
379 /**
380 * Create a unique file name for the paged (temporary) table
381 * @return just the name
382 */
383 static casa::String generateName();
384
385 /**
386 * attach to cached columns
387 */
388 void attach();
389
390 /**
391 * Set up the main casa::Table
392 */
393 void setupMainTable();
394
395 void attachSubtables();
396 void copySubtables(const Scantable& other);
397
398 /**
399 * Convert an "old" asap1 style row index into a new index
400 * @param[in] therow
401 * @return and index into @table_
402 */
403 int rowToScanIndex(int therow);
404
405 static const casa::uInt version_ = 2;
406
407 STSelector selector_;
408
409 casa::Table::TableType type_;
410
411 // the actual data
412 casa::Table table_;
413 casa::Table originalTable_;
414
415 STTcal tcalTable_;
416 STFrequencies freqTable_;
417 STWeather weatherTable_;
418 STFocus focusTable_;
419 STMolecules moleculeTable_;
420 STHistory historyTable_;
421 STFit fitTable_;
422
423 // Cached Columns to avoid reconstructing them for each row get/put
424 casa::ScalarColumn<casa::Double> integrCol_;
425 casa::MDirection::ScalarColumn dirCol_;
426 casa::MEpoch::ScalarColumn timeCol_;
427 casa::ScalarColumn<casa::Float> azCol_;
428 casa::ScalarColumn<casa::Float> elCol_;
429 casa::ScalarColumn<casa::Float> paraCol_;
430 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
431 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
432 casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
433 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
434 casa::ArrayColumn<casa::uChar> flagsCol_;
435
436 // id in frequencies table
437 casa::ScalarColumn<casa::uInt> mfreqidCol_;
438 // id in tcal table
439 casa::ScalarColumn<casa::uInt> mtcalidCol_;
440
441 casa::ArrayColumn<casa::String> histitemCol_;
442 casa::ScalarColumn<casa::Int> mfitidCol_;
443 casa::ScalarColumn<casa::uInt> mweatheridCol_;
444
445 casa::ScalarColumn<casa::uInt> mfocusidCol_;
446
447 casa::ScalarColumn<casa::uInt> mmolidCol_;
448
449 static std::map<std::string, STPol::STPolFactory *> factories_;
450 void initFactories();
451
452};
453
454
455} // namespace
456
457#endif
Note: See TracBrowser for help on using the repository browser.