source: trunk/src/Scantable.h@ 2009

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

New Development: No

JIRA Issue: Yes (CAS-2817/ASAP-232)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: added a new function SrcType::getName(int)

Test Programs: sdlist (CASA) or scantable.summary()

Put in Release Notes: No

Module(s): scantable, sdlist, sdplot

Description:

Added a new function SrcType::getName(int srctype) which returns
a source type in string.
The source type of each scan is retuned by Scantable::summary.


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