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

Last change on this file since 1732 was 1707, checked in by WataruKawasaki, 15 years ago

New Development: No

JIRA Issue: Yes (CAS-1807)

Ready to Release: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sdflag

Description: added Scantable::getClipMask() and Scantable::srchChannelsToClip().


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