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

Last change on this file since 1470 was 1446, checked in by TakTsutsumi, 16 years ago

Merged recent updates (since 2007) from nrao-asap

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 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 * Get global antenna position
162 * @return casa::MPosition
163 */
164 casa::MPosition getAntennaPosition() const;
165
166 /**
167 * the @ref casa::MDirection for a specific row
168 * @param[in] whichrow the row number
169 * return casa::MDirection
170 */
171 casa::MDirection getDirection( int whichrow ) const;
172
173 /**
174 * get the direction as a string
175 * @param[in] whichrow the row number
176 * return the direction string
177 */
178 std::string getDirectionString( int whichrow ) const;
179
180 /**
181 * set the direction type as a string, e.g. "J2000"
182 * @param[in] refstr the direction type
183 */
184 void setDirectionRefString(const std::string& refstr="");
185 /**
186 * get the direction reference string
187 * @return a string describing the direction reference
188 */
189 std::string getDirectionRefString() const; /**
190 * get the direction type as a string, e.g. "J2000"
191 * param[in] whichrow the row number
192 * return the direction string
193 */
194
195
196 /**
197 * Return the Flux unit of the data, e.g. "Jy" or "K"
198 * @return string
199 */
200 std::string getFluxUnit() const;
201
202 /**
203 * Set the Flux unit of the data
204 * @param unit a string representing the unit, e.g "Jy" or "K"
205 */
206 void setFluxUnit( const std::string& unit );
207
208 /**
209 * Set the Stokes type of the data
210 * @param feedtype a string representing the type, e.g "circular" or "linear"
211 */
212 void setFeedType( const std::string& feedtype );
213
214 /**
215 *
216 * @param instrument a string representing an insturment. see xxx
217 */
218 void setInstrument( const std::string& instrument );
219
220 /**
221 * (Re)calculate the azimuth and elevationnfor all rows
222 */
223 void calculateAZEL();
224
225 /**
226 * "hard" flag the data, this flags everything selected in setSelection()
227 * param[in] msk a boolean mask of length nchan describing the points to
228 * to be flagged
229 */
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);
232
233 /**
234 * Return a list of row numbers with respect to the original table.
235 * @return a list of unsigned ints
236 */
237 std::vector<unsigned int> rownumbers() const;
238
239
240 /**
241 * Get the number of beams in the data or a specific scan
242 * @param scanno the scan number to get the number of beams for.
243 * If scanno<0 the number is retrieved from the header.
244 * @return an integer number
245 */
246 int nbeam(int scanno=-1) const;
247 /**
248 * Get the number of IFs in the data or a specific scan
249 * @param scanno the scan number to get the number of IFs for.
250 * If scanno<0 the number is retrieved from the header.
251 * @return an integer number
252 */
253 int nif(int scanno=-1) const;
254 /**
255 * Get the number of polarizations in the data or a specific scan
256 * @param scanno the scan number to get the number of polarizations for.
257 * If scanno<0 the number is retrieved from the header.
258 * @return an integer number
259 */
260 int npol(int scanno=-1) const;
261
262 std::string getPolType() const;
263
264
265 /**
266 * Get the number of integartion cycles
267 * @param scanno the scan number to get the number of rows for.
268 * If scanno<0 the number is retrieved from the header.
269 * @return the number of rows (for the specified scanno)
270 */
271 int nrow(int scanno=-1) const;
272
273 int getBeam(int whichrow) const;
274 std::vector<uint> getBeamNos() { return getNumbers(beamCol_); }
275
276 int getIF(int whichrow) const;
277 std::vector<uint> getIFNos() { return getNumbers(ifCol_); }
278
279 int getPol(int whichrow) const;
280 std::vector<uint> getPolNos() { return getNumbers(polCol_); }
281
282 std::vector<uint> getScanNos() { return getNumbers(scanCol_); }
283 int getScan(int whichrow) const { return scanCol_(whichrow); }
284
285 //TT addition
286 std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); }
287
288 /**
289 * Get the number of channels in the data or a specific IF. This currently
290 * varies only with IF number
291 * @param ifno the IF number to get the number of channels for.
292 * If ifno<0 the number is retrieved from the header.
293 * @return an integer number
294 */
295 int nchan(int ifno=-1) const;
296 int getChannels(int whichrow) const;
297
298 int ncycle(int scanno=-1) const;
299 int getCycle(int whichrow) const { return cycleCol_(whichrow); }
300
301 double getInterval(int whichrow) const
302 { return integrCol_(whichrow); }
303
304 float getTsys(int whichrow) const
305 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
306 float getElevation(int whichrow) const
307 { return elCol_(whichrow); }
308 float getAzimuth(int whichrow) const
309 { return azCol_(whichrow); }
310 float getParAngle(int whichrow) const
311 { return paraCol_(whichrow); }
312
313 std::string getSourceName(int whichrow) const
314 { return srcnCol_(whichrow); }
315
316 std::vector<bool> getMask(int whichrow) const;
317 std::vector<float> getSpectrum(int whichrow,
318 const std::string& poltype = "" ) const;
319
320 void setSpectrum(const std::vector<float>& spec, int whichrow);
321
322 std::string getPolarizationLabel(int index, const std::string& ptype) const
323 { return STPol::getPolLabel(index, ptype ); }
324
325 /**
326 * Write the Scantable to disk
327 * @param filename the output file name
328 */
329 void makePersistent(const std::string& filename);
330
331 std::vector<std::string> getHistory() const
332 { return historyTable_.getHistory(); };
333
334 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
335
336 void appendToHistoryTable(const STHistory& otherhist)
337 { historyTable_.append(otherhist); }
338
339 std::string summary(bool verbose=false);
340 std::string getTime(int whichrow=-1, bool showdate=true) const;
341 double getIntTime(int whichrow) const { return integrCol_(whichrow); }
342
343 // returns unit, conversion frame, doppler, base-frame
344
345 /**
346 * Get the frequency set up
347 * This is forwarded to the STFrequencies subtable
348 * @return unit, frame, doppler
349 */
350 std::vector<std::string> getCoordInfo() const
351 { return freqTable_.getInfo(); };
352
353 void setCoordInfo(std::vector<string> theinfo)
354 { return freqTable_.setInfo(theinfo); };
355
356
357 std::vector<double> getAbcissa(int whichrow) const;
358
359 std::string getAbcissaLabel(int whichrow) const;
360 std::vector<double> getRestFrequencies() const
361 { return moleculeTable_.getRestFrequencies(); }
362 std::vector<double> getRestFrequency(int id) const
363 { return moleculeTable_.getRestFrequency(id); }
364
365 /**
366 void setRestFrequencies(double rf, const std::string& name = "",
367 const std::string& = "Hz");
368 **/
369 // Modified by Takeshi Nakazato 05/09/2008
370 /***
371 void setRestFrequencies(vector<double> rf, const vector<std::string>& name = "",
372 const std::string& = "Hz");
373 ***/
374 void setRestFrequencies(vector<double> rf,
375 const vector<std::string>& name = vector<std::string>(1,""),
376 const std::string& = "Hz");
377
378 //void setRestFrequencies(const std::string& name);
379 void setRestFrequencies(const vector<std::string>& name);
380
381 void shift(int npix);
382
383 void convertDirection(const std::string& newframe);
384
385 STFrequencies& frequencies() { return freqTable_; }
386 const STFrequencies& frequencies() const { return freqTable_; }
387 STWeather& weather() { return weatherTable_; }
388 const STWeather& weather() const { return weatherTable_; }
389 STFocus& focus() { return focusTable_; }
390 const STFocus& focus() const { return focusTable_; }
391 STTcal& tcal() { return tcalTable_; }
392 const STTcal& tcal() const { return tcalTable_; }
393 STMolecules& molecules() { return moleculeTable_; }
394 const STMolecules& molecules() const { return moleculeTable_; }
395 STHistory& history() { return historyTable_; }
396 const STHistory& history() const { return historyTable_; }
397 STFit& fit() { return fitTable_; }
398 const STFit& fit() const { return fitTable_; }
399
400 std::vector<std::string> columnNames() const;
401
402 void addFit(const STFitEntry& fit, int row);
403 STFitEntry getFit(int row) const
404 { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
405
406 //Added by TT
407 /**
408 * Get the antenna name
409 * @return antenna name string
410 */
411 std::string getAntennaName() const;
412
413 /**
414 * For GBT MS data only. check a scan list
415 * against the information found in GBT_GO table for
416 * scan number orders to get correct pairs.
417 * @param[in] scan list
418 * @return status
419 */
420 int checkScanInfo(const std::vector<int>& scanlist) const;
421
422 /**
423 * Get the direction as a vector, for a specific row
424 * @param[in] whichrow the row numbyyer
425 * @return the direction in a vector
426 */
427 std::vector<double> getDirectionVector(int whichrow) const;
428
429 /**
430 * Reshape spectrum
431 * @param[in] nmin, nmax minimum and maximum channel
432 * @param[in] irow row number
433 *
434 * 30/07/2008 Takeshi Nakazato
435 **/
436 void reshapeSpectrum( int nmin, int nmax ) throw( casa::AipsError );
437 void reshapeSpectrum( int nmin, int nmax, int irow ) ;
438
439 /**
440 * Change channel number under fixed bandwidth
441 * @param[in] nchan, dnu new channel number and spectral resolution
442 * @param[in] irow row number
443 *
444 * 27/08/2008 Takeshi Nakazato
445 **/
446 void regridChannel( int nchan, double dnu ) ;
447 void regridChannel( int nchan, double dnu, int irow ) ;
448
449private:
450
451 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
452
453 /**
454 * Turns a time vale into a formatted string
455 * @param x
456 * @return
457 */
458 std::string formatSec(casa::Double x) const;
459
460 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
461
462 /**
463 * Turns a casa::MDirection into a nicely formatted string
464 * @param md an casa::MDirection
465 * @return
466 */
467 std::string formatDirection(const casa::MDirection& md) const;
468
469
470 /**
471 * Create a unique file name for the paged (temporary) table
472 * @return just the name
473 */
474 static casa::String generateName();
475
476 /**
477 * attach to cached columns
478 */
479 void attach();
480
481 /**
482 * Set up the main casa::Table
483 */
484 void setupMainTable();
485
486 void attachSubtables();
487 void copySubtables(const Scantable& other);
488
489 /**
490 * Convert an "old" asap1 style row index into a new index
491 * @param[in] therow
492 * @return and index into @table_
493 */
494 int rowToScanIndex(int therow);
495
496 std::vector<uint> getNumbers(casa::ScalarColumn<casa::uInt>& col);
497
498 static const casa::uInt version_ = 2;
499
500 STSelector selector_;
501
502 casa::Table::TableType type_;
503
504 // the actual data
505 casa::Table table_;
506 casa::Table originalTable_;
507
508 STTcal tcalTable_;
509 STFrequencies freqTable_;
510 STWeather weatherTable_;
511 STFocus focusTable_;
512 STMolecules moleculeTable_;
513 STHistory historyTable_;
514 STFit fitTable_;
515
516 // Cached Columns to avoid reconstructing them for each row get/put
517 casa::ScalarColumn<casa::Double> integrCol_;
518 casa::MDirection::ScalarColumn dirCol_;
519 casa::MEpoch::ScalarColumn timeCol_;
520 casa::ScalarColumn<casa::Float> azCol_;
521 casa::ScalarColumn<casa::Float> elCol_;
522 casa::ScalarColumn<casa::Float> paraCol_;
523 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
524 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
525 casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
526 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
527 casa::ArrayColumn<casa::uChar> flagsCol_;
528
529 // id in frequencies table
530 casa::ScalarColumn<casa::uInt> mfreqidCol_;
531 // id in tcal table
532 casa::ScalarColumn<casa::uInt> mtcalidCol_;
533
534 casa::ArrayColumn<casa::String> histitemCol_;
535 casa::ScalarColumn<casa::Int> mfitidCol_;
536 casa::ScalarColumn<casa::uInt> mweatheridCol_;
537
538 casa::ScalarColumn<casa::uInt> mfocusidCol_;
539
540 casa::ScalarColumn<casa::uInt> mmolidCol_;
541
542 static std::map<std::string, STPol::STPolFactory *> factories_;
543 void initFactories();
544
545};
546
547
548} // namespace
549
550#endif
Note: See TracBrowser for help on using the repository browser.