source: trunk/src/Scantable.h@ 1537

Last change on this file since 1537 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
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
[80]24#include <tables/Tables/Table.h>
[322]25#include <tables/Tables/ArrayColumn.h>
26#include <tables/Tables/ScalarColumn.h>
27
[824]28#include <measures/TableMeasures/ScalarMeasColumn.h>
29
[894]30#include "Logger.h"
[901]31#include "STHeader.h"
[824]32#include "STFrequencies.h"
33#include "STWeather.h"
34#include "STFocus.h"
35#include "STTcal.h"
36#include "STMolecules.h"
37#include "STSelector.h"
[860]38#include "STHistory.h"
[896]39#include "STPol.h"
[960]40#include "STFit.h"
[972]41#include "STFitEntry.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 */
[1350]72 explicit 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 */
[1385]78 explicit 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
[1104]90 * @return const \ref casa::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
[1295]120 * @param[in] sth 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;
[1068]129
[824]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);
[430]137
[824]138 /**
[1068]139 *
140 * @param stype The type of the source, 0 = on, 1 = off
141 */
142 void setSourceType(int stype);
143
144
145 /**
[1104]146 * The number of scans in the table
[824]147 * @return number of scans in the table
148 */
[845]149 int nscan() const;
[490]150
[915]151 casa::MEpoch::Types getTimeReference() const;
[21]152
[1411]153
154 casa::MEpoch getEpoch(int whichrow) const;
155
[824]156 /**
157 * Get global antenna position
[845]158 * @return casa::MPosition
[824]159 */
160 casa::MPosition getAntennaPosition() const;
[490]161
[1441]162 /**
163 * the @ref casa::MDirection for a specific row
164 * @param[in] whichrow the row number
165 * return casa::MDirection
166 */
[987]167 casa::MDirection getDirection( int whichrow ) const;
[1441]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 */
[1068]174 std::string getDirectionString( int whichrow ) const;
175
[1441]176 /**
177 * set the direction type as a string, e.g. "J2000"
178 * @param[in] refstr the direction type
179 */
[987]180 void setDirectionRefString(const std::string& refstr="");
[1441]181
[1104]182 /**
183 * get the direction reference string
184 * @return a string describing the direction reference
185 */
[1441]186 std::string getDirectionRefString() const;
[987]187
[824]188 /**
[845]189 * Return the Flux unit of the data, e.g. "Jy" or "K"
190 * @return string
[824]191 */
192 std::string getFluxUnit() const;
[472]193
[824]194 /**
[845]195 * Set the Flux unit of the data
196 * @param unit a string representing the unit, e.g "Jy" or "K"
[824]197 */
198 void setFluxUnit( const std::string& unit );
[472]199
[824]200 /**
[1189]201 * Set the Stokes type of the data
[1295]202 * @param feedtype a string representing the type, e.g "circular" or "linear"
[1189]203 */
204 void setFeedType( const std::string& feedtype );
205
206 /**
[824]207 *
[845]208 * @param instrument a string representing an insturment. see xxx
[824]209 */
210 void setInstrument( const std::string& instrument );
[2]211
[845]212 /**
213 * (Re)calculate the azimuth and elevationnfor all rows
214 */
[824]215 void calculateAZEL();
[745]216
[824]217 /**
[845]218 * "hard" flag the data, this flags everything selected in setSelection()
[1104]219 * param[in] msk a boolean mask of length nchan describing the points to
220 * to be flagged
[824]221 */
[1430]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);
[455]224
[852]225 /**
226 * Return a list of row numbers with respect to the original table.
[902]227 * @return a list of unsigned ints
[852]228 */
229 std::vector<unsigned int> rownumbers() const;
[845]230
[852]231
[845]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 */
[824]238 int nbeam(int scanno=-1) const;
[845]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 */
[824]245 int nif(int scanno=-1) const;
[845]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 */
[824]252 int npol(int scanno=-1) const;
[794]253
[896]254 std::string getPolType() const;
255
[845]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.
[1104]261 * @return the number of rows (for the specified scanno)
[845]262 */
[824]263 int nrow(int scanno=-1) const;
[794]264
[1111]265 int getBeam(int whichrow) const;
266 std::vector<uint> getBeamNos() { return getNumbers(beamCol_); }
[50]267
[847]268 int getIF(int whichrow) const;
[1111]269 std::vector<uint> getIFNos() { return getNumbers(ifCol_); }
270
[847]271 int getPol(int whichrow) const;
[1111]272 std::vector<uint> getPolNos() { return getNumbers(polCol_); }
273
274 std::vector<uint> getScanNos() { return getNumbers(scanCol_); }
[865]275 int getScan(int whichrow) const { return scanCol_(whichrow); }
[1111]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;
[923]285 int getChannels(int whichrow) const;
[206]286
[1111]287 int ncycle(int scanno=-1) const;
288 int getCycle(int whichrow) const { return cycleCol_(whichrow); }
289
[847]290 double getInterval(int whichrow) const
291 { return integrCol_(whichrow); }
[845]292
[865]293 float getTsys(int whichrow) const
294 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
[847]295 float getElevation(int whichrow) const
296 { return elCol_(whichrow); }
297 float getAzimuth(int whichrow) const
298 { return azCol_(whichrow); }
[865]299 float getParAngle(int whichrow) const
[847]300 { return paraCol_(whichrow); }
[386]301
[865]302 std::string getSourceName(int whichrow) const
303 { return srcnCol_(whichrow); }
304
[847]305 std::vector<bool> getMask(int whichrow) const;
[896]306 std::vector<float> getSpectrum(int whichrow,
[905]307 const std::string& poltype = "" ) const;
[847]308
[884]309 void setSpectrum(const std::vector<float>& spec, int whichrow);
310
[902]311 std::string getPolarizationLabel(int index, const std::string& ptype) const
312 { return STPol::getPolLabel(index, ptype ); }
[401]313
[845]314 /**
315 * Write the Scantable to disk
316 * @param filename the output file name
317 */
[824]318 void makePersistent(const std::string& filename);
[745]319
[860]320 std::vector<std::string> getHistory() const
321 { return historyTable_.getHistory(); };
[483]322
[860]323 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
[488]324
[860]325 void appendToHistoryTable(const STHistory& otherhist)
326 { historyTable_.append(otherhist); }
327
[824]328 std::string summary(bool verbose=false);
329 std::string getTime(int whichrow=-1, bool showdate=true) const;
[1350]330 double getIntTime(int whichrow) const { return integrCol_(whichrow); }
[19]331
[847]332 // returns unit, conversion frame, doppler, base-frame
[18]333
[847]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
[865]345
346 std::vector<double> getAbcissa(int whichrow) const;
347
[847]348 std::string getAbcissaLabel(int whichrow) const;
349 std::vector<double> getRestFrequencies() const
350 { return moleculeTable_.getRestFrequencies(); }
351
[1170]352 void setRestFrequencies(double rf, const std::string& name = "",
353 const std::string& = "Hz");
[847]354 void setRestFrequencies(const std::string& name);
355
[1360]356 void shift(int npix);
357
[987]358 void convertDirection(const std::string& newframe);
359
[824]360 STFrequencies& frequencies() { return freqTable_; }
[1375]361 const STFrequencies& frequencies() const { return freqTable_; }
[824]362 STWeather& weather() { return weatherTable_; }
[1375]363 const STWeather& weather() const { return weatherTable_; }
[824]364 STFocus& focus() { return focusTable_; }
[1375]365 const STFocus& focus() const { return focusTable_; }
[824]366 STTcal& tcal() { return tcalTable_; }
[1375]367 const STTcal& tcal() const { return tcalTable_; }
[824]368 STMolecules& molecules() { return moleculeTable_; }
[1375]369 const STMolecules& molecules() const { return moleculeTable_; }
[860]370 STHistory& history() { return historyTable_; }
[1375]371 const STHistory& history() const { return historyTable_; }
[972]372 STFit& fit() { return fitTable_; }
[1375]373 const STFit& fit() const { return fitTable_; }
[2]374
[902]375 std::vector<std::string> columnNames() const;
[896]376
[972]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
[1391]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
[824]404private:
[896]405
406 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
407
[824]408 /**
409 * Turns a time vale into a formatted string
410 * @param x
411 * @return
412 */
413 std::string formatSec(casa::Double x) const;
[18]414
[824]415 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
[22]416
[824]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;
[19]423
[286]424
[824]425 /**
426 * Create a unique file name for the paged (temporary) table
427 * @return just the name
428 */
429 static casa::String generateName();
[286]430
[824]431 /**
432 * attach to cached columns
433 */
434 void attach();
[50]435
[824]436 /**
437 * Set up the main casa::Table
438 */
439 void setupMainTable();
[88]440
[859]441 void attachSubtables();
[865]442 void copySubtables(const Scantable& other);
443
[824]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);
[212]450
[1111]451 std::vector<uint> getNumbers(casa::ScalarColumn<casa::uInt>& col);
452
[1030]453 static const casa::uInt version_ = 2;
[286]454
[824]455 STSelector selector_;
[236]456
[824]457 casa::Table::TableType type_;
[465]458
[824]459 // the actual data
460 casa::Table table_;
461 casa::Table originalTable_;
[745]462
[824]463 STTcal tcalTable_;
464 STFrequencies freqTable_;
465 STWeather weatherTable_;
466 STFocus focusTable_;
467 STMolecules moleculeTable_;
[860]468 STHistory historyTable_;
[960]469 STFit fitTable_;
[860]470
[824]471 // Cached Columns to avoid reconstructing them for each row get/put
[847]472 casa::ScalarColumn<casa::Double> integrCol_;
[824]473 casa::MDirection::ScalarColumn dirCol_;
[847]474 casa::MEpoch::ScalarColumn timeCol_;
[923]475 casa::ScalarColumn<casa::Float> azCol_;
476 casa::ScalarColumn<casa::Float> elCol_;
[824]477 casa::ScalarColumn<casa::Float> paraCol_;
478 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
[847]479 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
[1068]480 casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
[865]481 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
[824]482 casa::ArrayColumn<casa::uChar> flagsCol_;
[430]483
[824]484 // id in frequencies table
485 casa::ScalarColumn<casa::uInt> mfreqidCol_;
486 // id in tcal table
487 casa::ScalarColumn<casa::uInt> mtcalidCol_;
[430]488
[824]489 casa::ArrayColumn<casa::String> histitemCol_;
[972]490 casa::ScalarColumn<casa::Int> mfitidCol_;
[824]491 casa::ScalarColumn<casa::uInt> mweatheridCol_;
[322]492
[824]493 casa::ScalarColumn<casa::uInt> mfocusidCol_;
494
495 casa::ScalarColumn<casa::uInt> mmolidCol_;
496
[896]497 static std::map<std::string, STPol::STPolFactory *> factories_;
498 void initFactories();
499
[2]500};
501
[824]502
503} // namespace
504
[2]505#endif
Note: See TracBrowser for help on using the repository browser.