source: trunk/src/Scantable.h@ 1911

Last change on this file since 1911 was 1908, checked in by WataruKawasaki, 14 years ago

New Development: No

JIRA Issue: Yes CAS-1937, CAS-2373

Ready to Release: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sdbaseline

Description: Changing some function names


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