source: trunk/src/Scantable.h@ 1519

Last change on this file since 1519 was 1441, checked in by Malte Marquarding, 16 years ago

tidying

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