source: trunk/src/Scantable.h @ 902

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

More work on polarisation. STPol and labelling

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.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"
[2]42
[824]43namespace asap {
[2]44
[824]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*/
[890]63class Scantable : private Logger
[824]64{
[902]65
66friend class STMath;
67
[2]68public:
[824]69  /**
70   * Default constructor
71   */
72  Scantable(casa::Table::TableType ttype = casa::Table::Memory);
[19]73
[824]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);
[2]79
[824]80  /// @fixme this is only sensible for MemoryTables....
81  Scantable(const Scantable& other, bool clear=true);
[161]82
[824]83  /**
84   * Destructor
85   */
86  virtual ~Scantable();
[745]87
[824]88  /**
89   * get a const reference to the underlying casa::Table
[845]90   * @return consantcasa::Table reference
[824]91   */
92  const casa::Table& table() const;
[19]93
[824]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();
[21]100
[845]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   */
[824]112  void setSelection(const STSelector& selection);
[845]113
114  /**
115   * unset the selection of the data
116   */
[824]117  void unsetSelection();
118  /**
119   * set the header
[901]120   * @param[in] sdh an STHeader object
[824]121   */
[901]122  void setHeader( const STHeader& sth );
[386]123
[824]124  /**
125   * get the header information
[901]126   * @return an STHeader object
[824]127   */
[901]128  STHeader getHeader( ) const;
[824]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);
[430]136
[824]137  /**
138   * return the number of scans in the table
139   * @return number of scans in the table
140   */
[845]141  int nscan() const;
[490]142
[824]143  //casa::MDirection::Types getDirectionReference() const;
144  //casa::MEpoch::Types getTimeReference() const;
[21]145
[824]146  /**
147   * Get global antenna position
[845]148   * @return casa::MPosition
[824]149   */
150  casa::MPosition getAntennaPosition() const;
[490]151
[824]152  /**
[845]153   *  Return the Flux unit of the data, e.g. "Jy" or "K"
154   * @return string
[824]155   */
156  std::string getFluxUnit() const;
[472]157
[824]158  /**
[845]159   * Set the Flux unit of the data
160   * @param unit a string representing the unit, e.g "Jy" or "K"
[824]161   */
162  void setFluxUnit( const std::string& unit );
[472]163
[824]164  /**
165   *
[845]166   * @param instrument a string representing an insturment. see xxx
[824]167   */
168  void setInstrument( const std::string& instrument );
[2]169
[845]170  /**
171   * (Re)calculate the azimuth and elevationnfor all rows
172   */
[824]173  void calculateAZEL();
[745]174
[824]175  /**
[845]176   * "hard" flag the data, this flags everything selected in setSelection()
[824]177   */
178  void flag();
[455]179
[852]180  /**
181   * Return a list of row numbers with respect to the original table.
[902]182   * @return a list of unsigned ints
[852]183   */
184  std::vector<unsigned int> rownumbers() const;
[845]185
[852]186
[845]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   */
[824]193  int nbeam(int scanno=-1) const;
[845]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   */
[824]200  int nif(int scanno=-1) const;
[845]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   */
[824]207  int npol(int scanno=-1) const;
[794]208
[896]209  std::string getPolType() const;
210
[845]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   */
[824]226  int nrow(int scanno=-1) const;
[794]227
[845]228  int ncycle(int scanno=-1) const;
[50]229
[847]230  int getBeam(int whichrow) const;
231  int getIF(int whichrow) const;
232  int getPol(int whichrow) const;
[865]233  int getCycle(int whichrow) const { return cycleCol_(whichrow); }
234  int getScan(int whichrow) const { return scanCol_(whichrow); }
[206]235
[847]236  double getInterval(int whichrow) const
237    { return integrCol_(whichrow); }
[845]238
[865]239  float getTsys(int whichrow) const
240    { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
[847]241  float getElevation(int whichrow) const
242    { return elCol_(whichrow); }
243  float getAzimuth(int whichrow) const
244    { return azCol_(whichrow); }
[865]245  float getParAngle(int whichrow) const
[847]246    { return paraCol_(whichrow); }
[386]247
[865]248  std::string getSourceName(int whichrow) const
249    { return srcnCol_(whichrow); }
250
[847]251  std::vector<bool> getMask(int whichrow) const;
[896]252  std::vector<float> getSpectrum(int whichrow,
253                                 const std::string& poltype ="linear") const;
[847]254
[884]255  void setSpectrum(const std::vector<float>& spec, int whichrow);
256
[902]257  std::string getPolarizationLabel(int index, const std::string& ptype) const
258    { return STPol::getPolLabel(index, ptype ); }
[401]259
[845]260  /**
261   * Write the Scantable to disk
262   * @param filename the output file name
263   */
[824]264  void makePersistent(const std::string& filename);
[745]265
[860]266  std::vector<std::string> getHistory() const
267    { return historyTable_.getHistory(); };
[483]268
[860]269  void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
[488]270
[860]271  void appendToHistoryTable(const STHistory& otherhist)
272    { historyTable_.append(otherhist); }
273
[824]274  std::string summary(bool verbose=false);
275  std::string getTime(int whichrow=-1, bool showdate=true) const;
[19]276
[847]277  // returns unit, conversion frame, doppler, base-frame
[18]278
[847]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
[865]290
291  std::vector<double> getAbcissa(int whichrow) const;
292
[847]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
[824]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_; }
[860]305  STHistory& history() { return historyTable_; }
[2]306
[902]307  std::vector<std::string> columnNames() const;
[896]308
[824]309private:
[896]310
311  casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
312
[824]313  /**
314   * Turns a time vale into a formatted string
315   * @param x
316   * @return
317   */
318  std::string formatSec(casa::Double x) const;
[18]319
[824]320  std::string formatTime(const casa::MEpoch& me, bool showdate)const;
[22]321
[824]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;
[19]328
[286]329
[824]330  /**
331   * Create a unique file name for the paged (temporary) table
332   * @return just the name
333   */
334  static casa::String generateName();
[286]335
[824]336  /**
337   * attach to cached columns
338   */
339  void attach();
[50]340
[824]341  /**
342   * Set up the main casa::Table
343   */
344  void setupMainTable();
[88]345
[824]346  void setupFitTable();
[212]347
[859]348  void attachSubtables();
[865]349  void copySubtables(const Scantable& other);
350
[824]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);
[212]357
[824]358  static const unsigned int version_ = 2;
[286]359
[824]360  STSelector selector_;
[236]361
[824]362  casa::Table::TableType type_;
[465]363
[824]364  // the actual data
365  casa::Table table_;
366  casa::Table originalTable_;
[745]367
[824]368  STTcal tcalTable_;
369  STFrequencies freqTable_;
370  STWeather weatherTable_;
371  STFocus focusTable_;
372  STMolecules moleculeTable_;
[860]373  STHistory historyTable_;
374
[824]375  casa::Table fitTable_;
[777]376
[824]377  // Cached Columns to avoid reconstructing them for each row get/put
[847]378  casa::ScalarColumn<casa::Double> integrCol_;
[824]379  casa::MDirection::ScalarColumn dirCol_;
[847]380  casa::MEpoch::ScalarColumn timeCol_;
[824]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_;
[847]385  casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
[824]386  casa::ScalarColumn<casa::Int> rbeamCol_;
[865]387  casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
[824]388  casa::ArrayColumn<casa::uChar> flagsCol_;
[430]389
[824]390  // id in frequencies table
391  casa::ScalarColumn<casa::uInt> mfreqidCol_;
392  // id in tcal table
393  casa::ScalarColumn<casa::uInt> mtcalidCol_;
[430]394
[824]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_;
[322]399
[824]400  casa::ScalarColumn<casa::uInt> mfocusidCol_;
401
402  casa::ScalarColumn<casa::uInt> mmolidCol_;
403
[896]404  static std::map<std::string, STPol::STPolFactory *> factories_;
405  void initFactories();
406
[2]407};
408
[824]409
410} // namespace
411
[2]412#endif
Note: See TracBrowser for help on using the repository browser.