source: trunk/src/Scantable.h@ 909

Last change on this file since 909 was 905, checked in by mar637, 19 years ago

change default polytype passed as argument to "", to then apply Scantable::poltype if empty.
added poltype to STHeader

  • 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
236 double getInterval(int whichrow) const
237 { return integrCol_(whichrow); }
238
239 float getTsys(int whichrow) const
240 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
241 float getElevation(int whichrow) const
242 { return elCol_(whichrow); }
243 float getAzimuth(int whichrow) const
244 { return azCol_(whichrow); }
245 float getParAngle(int whichrow) const
246 { return paraCol_(whichrow); }
247
248 std::string getSourceName(int whichrow) const
249 { return srcnCol_(whichrow); }
250
251 std::vector<bool> getMask(int whichrow) const;
252 std::vector<float> getSpectrum(int whichrow,
253 const std::string& poltype = "" ) const;
254
255 void setSpectrum(const std::vector<float>& spec, int whichrow);
256
257 std::string getPolarizationLabel(int index, const std::string& ptype) const
258 { return STPol::getPolLabel(index, ptype ); }
259
260 /**
261 * Write the Scantable to disk
262 * @param filename the output file name
263 */
264 void makePersistent(const std::string& filename);
265
266 std::vector<std::string> getHistory() const
267 { return historyTable_.getHistory(); };
268
269 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
270
271 void appendToHistoryTable(const STHistory& otherhist)
272 { historyTable_.append(otherhist); }
273
274 std::string summary(bool verbose=false);
275 std::string getTime(int whichrow=-1, bool showdate=true) const;
276
277 // returns unit, conversion frame, doppler, base-frame
278
279 /**
280 * Get the frequency set up
281 * This is forwarded to the STFrequencies subtable
282 * @return unit, frame, doppler
283 */
284 std::vector<std::string> getCoordInfo() const
285 { return freqTable_.getInfo(); };
286
287 void setCoordInfo(std::vector<string> theinfo)
288 { return freqTable_.setInfo(theinfo); };
289
290
291 std::vector<double> getAbcissa(int whichrow) const;
292
293 std::string getAbcissaLabel(int whichrow) const;
294 std::vector<double> getRestFrequencies() const
295 { return moleculeTable_.getRestFrequencies(); }
296
297 void setRestFrequencies(double rf, const std::string& = "Hz");
298 void setRestFrequencies(const std::string& name);
299
300 STFrequencies& frequencies() { return freqTable_; }
301 STWeather& weather() { return weatherTable_; }
302 STFocus& focus() { return focusTable_; }
303 STTcal& tcal() { return tcalTable_; }
304 STMolecules& molecules() { return moleculeTable_; }
305 STHistory& history() { return historyTable_; }
306
307 std::vector<std::string> columnNames() const;
308
309private:
310
311 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
312
313 /**
314 * Turns a time vale into a formatted string
315 * @param x
316 * @return
317 */
318 std::string formatSec(casa::Double x) const;
319
320 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
321
322 /**
323 * Turns a casa::MDirection into a nicely formatted string
324 * @param md an casa::MDirection
325 * @return
326 */
327 std::string formatDirection(const casa::MDirection& md) const;
328
329
330 /**
331 * Create a unique file name for the paged (temporary) table
332 * @return just the name
333 */
334 static casa::String generateName();
335
336 /**
337 * attach to cached columns
338 */
339 void attach();
340
341 /**
342 * Set up the main casa::Table
343 */
344 void setupMainTable();
345
346 void setupFitTable();
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
375 casa::Table fitTable_;
376
377 // Cached Columns to avoid reconstructing them for each row get/put
378 casa::ScalarColumn<casa::Double> integrCol_;
379 casa::MDirection::ScalarColumn dirCol_;
380 casa::MEpoch::ScalarColumn timeCol_;
381 casa::ScalarColumn<casa::Double> azCol_;
382 casa::ScalarColumn<casa::Double> elCol_;
383 casa::ScalarColumn<casa::Float> paraCol_;
384 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
385 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
386 casa::ScalarColumn<casa::Int> rbeamCol_;
387 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
388 casa::ArrayColumn<casa::uChar> flagsCol_;
389
390 // id in frequencies table
391 casa::ScalarColumn<casa::uInt> mfreqidCol_;
392 // id in tcal table
393 casa::ScalarColumn<casa::uInt> mtcalidCol_;
394
395 casa::ArrayColumn<casa::String> histitemCol_;
396 casa::ScalarColumn<casa::uInt> mfitidCol_, fitidCol_;
397 // id in weather table and main table
398 casa::ScalarColumn<casa::uInt> mweatheridCol_;
399
400 casa::ScalarColumn<casa::uInt> mfocusidCol_;
401
402 casa::ScalarColumn<casa::uInt> mmolidCol_;
403
404 static std::map<std::string, STPol::STPolFactory *> factories_;
405 void initFactories();
406
407};
408
409
410} // namespace
411
412#endif
Note: See TracBrowser for help on using the repository browser.