source: trunk/src/Scantable.h @ 923

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

fixed az/el data type to be Float. added getChannels function. to get cnumber of channels per row. (nchan retrurns by IF)

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