source: branches/alma/src/Scantable.h@ 2219

Last change on this file since 2219 was 1818, checked in by Kana Sugimoto, 14 years ago

New Development: Yes

JIRA Issue: No (merge)

Ready for Test: Yes

Interface Changes: No

Description:

Merged changes -r1774:1817 in newfiller branch to alma branch


  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 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
[1757]30#include <coordinates/Coordinates/SpectralCoordinate.h>
31
[1446]32#include <casa/Arrays/Vector.h>
33#include <casa/Quanta/Quantum.h>
34
[1757]35#include <casa/Exceptions/Error.h>
36
[894]37#include "Logger.h"
[901]38#include "STHeader.h"
[824]39#include "STFrequencies.h"
40#include "STWeather.h"
41#include "STFocus.h"
42#include "STTcal.h"
43#include "STMolecules.h"
44#include "STSelector.h"
[860]45#include "STHistory.h"
[896]46#include "STPol.h"
[960]47#include "STFit.h"
[972]48#include "STFitEntry.h"
[2]49
[824]50namespace asap {
[2]51
[824]52/**
53 * This class contains and wraps a casa::Table, which is used to store
54 * all the information. This can be either a MemoryTable or a
55 * disk based Table.
56 * It provides access functions to the underlying table
57 * It contains n subtables:
58 * @li weather
59 * @li frequencies
60 * @li molecules
61 * @li tcal
62 * @li focus
63 * @li fits
64 *
65 * @brief The main ASAP data container
66 * @author Malte Marquarding
67 * @date
68 * @version
69*/
[890]70class Scantable : private Logger
[824]71{
[902]72
73friend class STMath;
74
[2]75public:
[824]76 /**
77 * Default constructor
78 */
[1350]79 explicit Scantable(casa::Table::TableType ttype = casa::Table::Memory);
[19]80
[824]81 /**
82 * Create a Scantable object form an existing table on disk
83 * @param[in] name the name of the existing Scantable
84 */
[1385]85 explicit Scantable(const std::string& name, casa::Table::TableType ttype = casa::Table::Memory);
[2]86
[824]87 /// @fixme this is only sensible for MemoryTables....
88 Scantable(const Scantable& other, bool clear=true);
[161]89
[824]90 /**
91 * Destructor
92 */
93 virtual ~Scantable();
[745]94
[824]95 /**
96 * get a const reference to the underlying casa::Table
[1104]97 * @return const \ref casa::Table reference
[824]98 */
99 const casa::Table& table() const;
[19]100
[824]101 /**
102 * get a reference to the underlying casa::Table with the Selection
103 * object applied if set
104 * @return casa::Table reference
105 */
106 casa::Table& table();
[21]107
[845]108
109 /**
110 * Get a handle to the selection object
111 * @return constant STSelector reference
112 */
113 const STSelector& getSelection() const { return selector_; }
114
115 /**
116 * Set the data to be a subset as defined by the STSelector
117 * @param selection a STSelector object
118 */
[824]119 void setSelection(const STSelector& selection);
[845]120
121 /**
122 * unset the selection of the data
123 */
[824]124 void unsetSelection();
125 /**
126 * set the header
[1295]127 * @param[in] sth an STHeader object
[824]128 */
[901]129 void setHeader( const STHeader& sth );
[386]130
[824]131 /**
132 * get the header information
[901]133 * @return an STHeader object
[824]134 */
[901]135 STHeader getHeader( ) const;
[1068]136
[824]137 /**
138 * Checks if the "other" Scantable is conformant with this,
139 * i.e. if header values are the same.
140 * @param[in] other another Scantable
141 * @return true or false
142 */
143 bool conformant( const Scantable& other);
[430]144
[824]145 /**
[1068]146 *
147 * @param stype The type of the source, 0 = on, 1 = off
148 */
149 void setSourceType(int stype);
150
151
152 /**
[1104]153 * The number of scans in the table
[824]154 * @return number of scans in the table
155 */
[845]156 int nscan() const;
[490]157
[915]158 casa::MEpoch::Types getTimeReference() const;
[21]159
[1603]160
161 casa::MEpoch getEpoch(int whichrow) const;
162
[824]163 /**
164 * Get global antenna position
[845]165 * @return casa::MPosition
[824]166 */
167 casa::MPosition getAntennaPosition() const;
[490]168
[1603]169 /**
170 * the @ref casa::MDirection for a specific row
171 * @param[in] whichrow the row number
172 * return casa::MDirection
173 */
[987]174 casa::MDirection getDirection( int whichrow ) const;
[1757]175
[1603]176 /**
177 * get the direction type as a string, e.g. "J2000"
178 * @param[in] whichrow the row number
179 * return the direction string
180 */
[1068]181 std::string getDirectionString( int whichrow ) const;
182
[1603]183 /**
184 * set the direction type as a string, e.g. "J2000"
185 * @param[in] refstr the direction type
186 */
[987]187 void setDirectionRefString(const std::string& refstr="");
[1603]188
[1104]189 /**
190 * get the direction reference string
191 * @return a string describing the direction reference
192 */
[1757]193 std::string getDirectionRefString() const;
[987]194
[824]195 /**
[845]196 * Return the Flux unit of the data, e.g. "Jy" or "K"
197 * @return string
[824]198 */
199 std::string getFluxUnit() const;
[472]200
[824]201 /**
[845]202 * Set the Flux unit of the data
203 * @param unit a string representing the unit, e.g "Jy" or "K"
[824]204 */
205 void setFluxUnit( const std::string& unit );
[472]206
[824]207 /**
[1189]208 * Set the Stokes type of the data
[1295]209 * @param feedtype a string representing the type, e.g "circular" or "linear"
[1189]210 */
211 void setFeedType( const std::string& feedtype );
212
213 /**
[824]214 *
[845]215 * @param instrument a string representing an insturment. see xxx
[824]216 */
217 void setInstrument( const std::string& instrument );
[2]218
[845]219 /**
220 * (Re)calculate the azimuth and elevationnfor all rows
221 */
[824]222 void calculateAZEL();
[745]223
[824]224 /**
[845]225 * "hard" flag the data, this flags everything selected in setSelection()
[1104]226 * param[in] msk a boolean mask of length nchan describing the points to
227 * to be flagged
[824]228 */
[1400]229 //void flag( const std::vector<bool>& msk = std::vector<bool>());
230 void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
[455]231
[852]232 /**
[1656]233 * Flag the data in a row-based manner. (CAS-1433 Wataru Kawasaki)
234 * param[in] rows list of row numbers to be flagged
235 */
236 void flagRow( const std::vector<casa::uInt>& rows = std::vector<casa::uInt>(), bool unflag=false);
237
238 /**
[1818]239 * Get flagRow info at the specified row. If true, the whole data
[1656]240 * at the row should be flagged.
241 */
242 bool getFlagRow(int whichrow) const
243 { return (flagrowCol_(whichrow) > 0); }
244
245 /**
[1700]246 * Flag the data outside a specified range (in a channel-based manner).
247 * (CAS-1807 Wataru Kawasaki)
248 */
[1703]249 void clip(const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag);
[1700]250
251 /**
[1818]252 * Return a list of booleans with the size of nchan for a specified row, to get info
[1707]253 * about which channel is clipped.
254 */
255 std::vector<bool> getClipMask(int whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag);
[1818]256 void srchChannelsToClip(casa::uInt whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag,
[1707]257 casa::Vector<casa::uChar> flgs);
258
259 /**
[852]260 * Return a list of row numbers with respect to the original table.
[902]261 * @return a list of unsigned ints
[852]262 */
263 std::vector<unsigned int> rownumbers() const;
[845]264
[852]265
[845]266 /**
267 * Get the number of beams in the data or a specific scan
268 * @param scanno the scan number to get the number of beams for.
269 * If scanno<0 the number is retrieved from the header.
270 * @return an integer number
271 */
[824]272 int nbeam(int scanno=-1) const;
[845]273 /**
274 * Get the number of IFs in the data or a specific scan
275 * @param scanno the scan number to get the number of IFs for.
276 * If scanno<0 the number is retrieved from the header.
277 * @return an integer number
278 */
[824]279 int nif(int scanno=-1) const;
[845]280 /**
281 * Get the number of polarizations in the data or a specific scan
282 * @param scanno the scan number to get the number of polarizations for.
283 * If scanno<0 the number is retrieved from the header.
284 * @return an integer number
285 */
[824]286 int npol(int scanno=-1) const;
[794]287
[896]288 std::string getPolType() const;
289
[845]290
291 /**
292 * Get the number of integartion cycles
293 * @param scanno the scan number to get the number of rows for.
294 * If scanno<0 the number is retrieved from the header.
[1104]295 * @return the number of rows (for the specified scanno)
[845]296 */
[824]297 int nrow(int scanno=-1) const;
[794]298
[1111]299 int getBeam(int whichrow) const;
[1757]300 std::vector<uint> getBeamNos() const { return getNumbers(beamCol_); }
[50]301
[847]302 int getIF(int whichrow) const;
[1757]303 std::vector<uint> getIFNos() const { return getNumbers(ifCol_); }
[1111]304
[847]305 int getPol(int whichrow) const;
[1757]306 std::vector<uint> getPolNos() const { return getNumbers(polCol_); }
[1111]307
[1757]308 std::vector<uint> getScanNos() const { return getNumbers(scanCol_); }
[865]309 int getScan(int whichrow) const { return scanCol_(whichrow); }
[1111]310
[1446]311 //TT addition
312 std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); }
313
[1111]314 /**
315 * Get the number of channels in the data or a specific IF. This currently
316 * varies only with IF number
317 * @param ifno the IF number to get the number of channels for.
318 * If ifno<0 the number is retrieved from the header.
319 * @return an integer number
320 */
321 int nchan(int ifno=-1) const;
[923]322 int getChannels(int whichrow) const;
[206]323
[1111]324 int ncycle(int scanno=-1) const;
325 int getCycle(int whichrow) const { return cycleCol_(whichrow); }
326
[847]327 double getInterval(int whichrow) const
328 { return integrCol_(whichrow); }
[845]329
[865]330 float getTsys(int whichrow) const
331 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
[847]332 float getElevation(int whichrow) const
333 { return elCol_(whichrow); }
334 float getAzimuth(int whichrow) const
335 { return azCol_(whichrow); }
[865]336 float getParAngle(int whichrow) const
[1757]337 { return focus().getParAngle(mfocusidCol_(whichrow)); }
[1634]338 int getTcalId(int whichrow) const
339 { return mtcalidCol_(whichrow); }
[386]340
[865]341 std::string getSourceName(int whichrow) const
342 { return srcnCol_(whichrow); }
343
[847]344 std::vector<bool> getMask(int whichrow) const;
[896]345 std::vector<float> getSpectrum(int whichrow,
[905]346 const std::string& poltype = "" ) const;
[847]347
[884]348 void setSpectrum(const std::vector<float>& spec, int whichrow);
349
[902]350 std::string getPolarizationLabel(int index, const std::string& ptype) const
351 { return STPol::getPolLabel(index, ptype ); }
[401]352
[845]353 /**
354 * Write the Scantable to disk
355 * @param filename the output file name
356 */
[824]357 void makePersistent(const std::string& filename);
[745]358
[860]359 std::vector<std::string> getHistory() const
360 { return historyTable_.getHistory(); };
[483]361
[860]362 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
[488]363
[860]364 void appendToHistoryTable(const STHistory& otherhist)
365 { historyTable_.append(otherhist); }
366
[824]367 std::string summary(bool verbose=false);
368 std::string getTime(int whichrow=-1, bool showdate=true) const;
[1350]369 double getIntTime(int whichrow) const { return integrCol_(whichrow); }
[19]370
[847]371 // returns unit, conversion frame, doppler, base-frame
[18]372
[847]373 /**
374 * Get the frequency set up
375 * This is forwarded to the STFrequencies subtable
376 * @return unit, frame, doppler
377 */
378 std::vector<std::string> getCoordInfo() const
379 { return freqTable_.getInfo(); };
380
381 void setCoordInfo(std::vector<string> theinfo)
382 { return freqTable_.setInfo(theinfo); };
383
[865]384
385 std::vector<double> getAbcissa(int whichrow) const;
386
[1757]387 std::vector<float> getWeather(int whichrow) const;
388
[847]389 std::string getAbcissaLabel(int whichrow) const;
390 std::vector<double> getRestFrequencies() const
391 { return moleculeTable_.getRestFrequencies(); }
[1446]392 std::vector<double> getRestFrequency(int id) const
393 { return moleculeTable_.getRestFrequency(id); }
[847]394
[1446]395 /**
[1170]396 void setRestFrequencies(double rf, const std::string& name = "",
397 const std::string& = "Hz");
[1446]398 **/
399 // Modified by Takeshi Nakazato 05/09/2008
400 /***
401 void setRestFrequencies(vector<double> rf, const vector<std::string>& name = "",
402 const std::string& = "Hz");
403 ***/
404 void setRestFrequencies(vector<double> rf,
405 const vector<std::string>& name = vector<std::string>(1,""),
406 const std::string& = "Hz");
[847]407
[1446]408 //void setRestFrequencies(const std::string& name);
409 void setRestFrequencies(const vector<std::string>& name);
410
[1360]411 void shift(int npix);
412
[1757]413 casa::SpectralCoordinate getSpectralCoordinate(int whichrow) const;
414
[987]415 void convertDirection(const std::string& newframe);
416
[824]417 STFrequencies& frequencies() { return freqTable_; }
[1375]418 const STFrequencies& frequencies() const { return freqTable_; }
[824]419 STWeather& weather() { return weatherTable_; }
[1375]420 const STWeather& weather() const { return weatherTable_; }
[824]421 STFocus& focus() { return focusTable_; }
[1375]422 const STFocus& focus() const { return focusTable_; }
[824]423 STTcal& tcal() { return tcalTable_; }
[1375]424 const STTcal& tcal() const { return tcalTable_; }
[824]425 STMolecules& molecules() { return moleculeTable_; }
[1375]426 const STMolecules& molecules() const { return moleculeTable_; }
[860]427 STHistory& history() { return historyTable_; }
[1375]428 const STHistory& history() const { return historyTable_; }
[972]429 STFit& fit() { return fitTable_; }
[1375]430 const STFit& fit() const { return fitTable_; }
[2]431
[902]432 std::vector<std::string> columnNames() const;
[896]433
[972]434 void addFit(const STFitEntry& fit, int row);
435 STFitEntry getFit(int row) const
436 { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
437
[1388]438 //Added by TT
439 /**
440 * Get the antenna name
441 * @return antenna name string
442 */
[1818]443 casa::String getAntennaName() const;
[1388]444
445 /**
446 * For GBT MS data only. check a scan list
447 * against the information found in GBT_GO table for
448 * scan number orders to get correct pairs.
[1757]449 * @param[in] scan list
450 * @return status
[1388]451 */
452 int checkScanInfo(const std::vector<int>& scanlist) const;
453
454 /**
[1757]455 * Get the direction as a vector, for a specific row
[1388]456 * @param[in] whichrow the row numbyyer
[1757]457 * @return the direction in a vector
[1388]458 */
459 std::vector<double> getDirectionVector(int whichrow) const;
460
[1446]461 /**
[1757]462 * Set a flag indicating whether the data was parallactified
463 * @param[in] flag true or false
464 */
465 void parallactify(bool flag)
466 { focus().setParallactify(flag); }
467
468 /**
[1446]469 * Reshape spectrum
470 * @param[in] nmin, nmax minimum and maximum channel
471 * @param[in] irow row number
[1818]472 *
473 * 30/07/2008 Takeshi Nakazato
[1446]474 **/
475 void reshapeSpectrum( int nmin, int nmax ) throw( casa::AipsError );
476 void reshapeSpectrum( int nmin, int nmax, int irow ) ;
477
478 /**
479 * Change channel number under fixed bandwidth
480 * @param[in] nchan, dnu new channel number and spectral resolution
481 * @param[in] irow row number
482 *
483 * 27/08/2008 Takeshi Nakazato
484 **/
485 void regridChannel( int nchan, double dnu ) ;
486 void regridChannel( int nchan, double dnu, int irow ) ;
[1656]487
[1818]488
[824]489private:
[896]490
491 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
492
[824]493 /**
494 * Turns a time vale into a formatted string
495 * @param x
496 * @return
497 */
498 std::string formatSec(casa::Double x) const;
[18]499
[824]500 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
[22]501
[824]502 /**
503 * Turns a casa::MDirection into a nicely formatted string
504 * @param md an casa::MDirection
505 * @return
506 */
507 std::string formatDirection(const casa::MDirection& md) const;
[19]508
[286]509
[824]510 /**
511 * Create a unique file name for the paged (temporary) table
512 * @return just the name
513 */
514 static casa::String generateName();
[286]515
[824]516 /**
517 * attach to cached columns
518 */
519 void attach();
[50]520
[824]521 /**
522 * Set up the main casa::Table
523 */
524 void setupMainTable();
[88]525
[859]526 void attachSubtables();
[865]527 void copySubtables(const Scantable& other);
528
[824]529 /**
530 * Convert an "old" asap1 style row index into a new index
531 * @param[in] therow
532 * @return and index into @table_
533 */
534 int rowToScanIndex(int therow);
[212]535
[1757]536 std::vector<uint> getNumbers(const casa::ScalarColumn<casa::uInt>& col) const;
[1111]537
[1757]538 static const casa::uInt version_ = 3;
[286]539
[824]540 STSelector selector_;
[236]541
[824]542 casa::Table::TableType type_;
[465]543
[824]544 // the actual data
545 casa::Table table_;
546 casa::Table originalTable_;
[745]547
[824]548 STTcal tcalTable_;
549 STFrequencies freqTable_;
550 STWeather weatherTable_;
551 STFocus focusTable_;
552 STMolecules moleculeTable_;
[860]553 STHistory historyTable_;
[960]554 STFit fitTable_;
[860]555
[824]556 // Cached Columns to avoid reconstructing them for each row get/put
[847]557 casa::ScalarColumn<casa::Double> integrCol_;
[824]558 casa::MDirection::ScalarColumn dirCol_;
[847]559 casa::MEpoch::ScalarColumn timeCol_;
[923]560 casa::ScalarColumn<casa::Float> azCol_;
561 casa::ScalarColumn<casa::Float> elCol_;
[824]562 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
[1656]563 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_, flagrowCol_;
[1068]564 casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
[865]565 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
[824]566 casa::ArrayColumn<casa::uChar> flagsCol_;
[430]567
[824]568 // id in frequencies table
569 casa::ScalarColumn<casa::uInt> mfreqidCol_;
570 // id in tcal table
571 casa::ScalarColumn<casa::uInt> mtcalidCol_;
[430]572
[824]573 casa::ArrayColumn<casa::String> histitemCol_;
[972]574 casa::ScalarColumn<casa::Int> mfitidCol_;
[824]575 casa::ScalarColumn<casa::uInt> mweatheridCol_;
[322]576
[824]577 casa::ScalarColumn<casa::uInt> mfocusidCol_;
578
579 casa::ScalarColumn<casa::uInt> mmolidCol_;
580
[896]581 static std::map<std::string, STPol::STPolFactory *> factories_;
582 void initFactories();
583
[1656]584 /**
[1818]585 * Add an auxiliary column to the main table and attach it to a
[1656]586 * cached column. Use for adding new columns that the original asap2
[1818]587 * tables do not have.
[1656]588 * @param[in] col reference to the cached column to be attached
589 * @param[in] colName column name in asap table
590 * @param[in] defValue default value to fill in the column
591 *
592 * 25/10/2009 Wataru Kawasaki
593 */
594 template<class T, class T2> void attachAuxColumnDef(casa::ScalarColumn<T>&,
595 const casa::String&,
596 const T2&);
597 template<class T, class T2> void attachAuxColumnDef(casa::ArrayColumn<T>&,
598 const casa::String&,
599 const casa::Array<T2>&);
[2]600};
601
[824]602
603} // namespace
604
[2]605#endif
Note: See TracBrowser for help on using the repository browser.