source: trunk/src/Scantable.h @ 1411

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

added getEpoch member function

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