source: tags/Release2.1.1b/src/Scantable.h @ 1287

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

doxygen tag fixes

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