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 <coordinates/Coordinates/SpectralCoordinate.h>
|
---|
25 |
|
---|
26 | #include <tables/Tables/Table.h>
|
---|
27 | #include <tables/Tables/ArrayColumn.h>
|
---|
28 | #include <tables/Tables/ScalarColumn.h>
|
---|
29 |
|
---|
30 | #include <measures/TableMeasures/ScalarMeasColumn.h>
|
---|
31 |
|
---|
32 | #include "Logger.h"
|
---|
33 | #include "STHeader.h"
|
---|
34 | #include "STFrequencies.h"
|
---|
35 | #include "STWeather.h"
|
---|
36 | #include "STFocus.h"
|
---|
37 | #include "STTcal.h"
|
---|
38 | #include "STMolecules.h"
|
---|
39 | #include "STSelector.h"
|
---|
40 | #include "STHistory.h"
|
---|
41 | #include "STPol.h"
|
---|
42 | #include "STFit.h"
|
---|
43 | #include "STFitEntry.h"
|
---|
44 |
|
---|
45 | namespace asap {
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * This class contains and wraps a casa::Table, which is used to store
|
---|
49 | * all the information. This can be either a MemoryTable or a
|
---|
50 | * disk based Table.
|
---|
51 | * It provides access functions to the underlying table
|
---|
52 | * It contains n subtables:
|
---|
53 | * @li weather
|
---|
54 | * @li frequencies
|
---|
55 | * @li molecules
|
---|
56 | * @li tcal
|
---|
57 | * @li focus
|
---|
58 | * @li fits
|
---|
59 | *
|
---|
60 | * @brief The main ASAP data container
|
---|
61 | * @author Malte Marquarding
|
---|
62 | * @date
|
---|
63 | * @version
|
---|
64 | */
|
---|
65 | class Scantable : private Logger
|
---|
66 | {
|
---|
67 |
|
---|
68 | friend class STMath;
|
---|
69 |
|
---|
70 | public:
|
---|
71 | /**
|
---|
72 | * Default constructor
|
---|
73 | */
|
---|
74 | explicit Scantable(casa::Table::TableType ttype = casa::Table::Memory);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Create a Scantable object form an existing table on disk
|
---|
78 | * @param[in] name the name of the existing Scantable
|
---|
79 | */
|
---|
80 | explicit Scantable(const std::string& name, casa::Table::TableType ttype = casa::Table::Memory);
|
---|
81 |
|
---|
82 | /// @fixme this is only sensible for MemoryTables....
|
---|
83 | Scantable(const Scantable& other, bool clear=true);
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Destructor
|
---|
87 | */
|
---|
88 | virtual ~Scantable();
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * get a const reference to the underlying casa::Table
|
---|
92 | * @return const \ref casa::Table reference
|
---|
93 | */
|
---|
94 | const casa::Table& table() const;
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * get a reference to the underlying casa::Table with the Selection
|
---|
98 | * object applied if set
|
---|
99 | * @return casa::Table reference
|
---|
100 | */
|
---|
101 | casa::Table& table();
|
---|
102 |
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Get a handle to the selection object
|
---|
106 | * @return constant STSelector reference
|
---|
107 | */
|
---|
108 | const STSelector& getSelection() const { return selector_; }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Set the data to be a subset as defined by the STSelector
|
---|
112 | * @param selection a STSelector object
|
---|
113 | */
|
---|
114 | void setSelection(const STSelector& selection);
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * unset the selection of the data
|
---|
118 | */
|
---|
119 | void unsetSelection();
|
---|
120 | /**
|
---|
121 | * set the header
|
---|
122 | * @param[in] sth an STHeader object
|
---|
123 | */
|
---|
124 | void setHeader( const STHeader& sth );
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * get the header information
|
---|
128 | * @return an STHeader object
|
---|
129 | */
|
---|
130 | STHeader getHeader( ) const;
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Checks if the "other" Scantable is conformant with this,
|
---|
134 | * i.e. if header values are the same.
|
---|
135 | * @param[in] other another Scantable
|
---|
136 | * @return true or false
|
---|
137 | */
|
---|
138 | bool conformant( const Scantable& other);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | *
|
---|
142 | * @param stype The type of the source, 0 = on, 1 = off
|
---|
143 | */
|
---|
144 | void setSourceType(int stype);
|
---|
145 |
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * The number of scans in the table
|
---|
149 | * @return number of scans in the table
|
---|
150 | */
|
---|
151 | int nscan() const;
|
---|
152 |
|
---|
153 | casa::MEpoch::Types getTimeReference() const;
|
---|
154 |
|
---|
155 |
|
---|
156 | casa::MEpoch getEpoch(int whichrow) const;
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Get global antenna position
|
---|
160 | * @return casa::MPosition
|
---|
161 | */
|
---|
162 | casa::MPosition getAntennaPosition() const;
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * the @ref casa::MDirection for a specific row
|
---|
166 | * @param[in] whichrow the row number
|
---|
167 | * return casa::MDirection
|
---|
168 | */
|
---|
169 | casa::MDirection getDirection( int whichrow ) const;
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * get the direction type as a string, e.g. "J2000"
|
---|
173 | * @param[in] whichrow the row number
|
---|
174 | * return the direction string
|
---|
175 | */
|
---|
176 | std::string getDirectionString( int whichrow ) const;
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * set the direction type as a string, e.g. "J2000"
|
---|
180 | * @param[in] refstr the direction type
|
---|
181 | */
|
---|
182 | void setDirectionRefString(const std::string& refstr="");
|
---|
183 | /**
|
---|
184 | * get the direction reference string
|
---|
185 | * @return a string describing the direction reference
|
---|
186 | */
|
---|
187 | std::string getDirectionRefString() const; /**
|
---|
188 | * get the direction type as a string, e.g. "J2000"
|
---|
189 | * param[in] whichrow the row number
|
---|
190 | * return the direction string
|
---|
191 | */
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Return the Flux unit of the data, e.g. "Jy" or "K"
|
---|
196 | * @return string
|
---|
197 | */
|
---|
198 | std::string getFluxUnit() const;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Set the Flux unit of the data
|
---|
202 | * @param unit a string representing the unit, e.g "Jy" or "K"
|
---|
203 | */
|
---|
204 | void setFluxUnit( const std::string& unit );
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Set the Stokes type of the data
|
---|
208 | * @param feedtype a string representing the type, e.g "circular" or "linear"
|
---|
209 | */
|
---|
210 | void setFeedType( const std::string& feedtype );
|
---|
211 |
|
---|
212 | /**
|
---|
213 | *
|
---|
214 | * @param instrument a string representing an insturment. see xxx
|
---|
215 | */
|
---|
216 | void setInstrument( const std::string& instrument );
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * (Re)calculate the azimuth and elevationnfor all rows
|
---|
220 | */
|
---|
221 | void calculateAZEL();
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * "hard" flag the data, this flags everything selected in setSelection()
|
---|
225 | * param[in] msk a boolean mask of length nchan describing the points to
|
---|
226 | * to be flagged
|
---|
227 | */
|
---|
228 | //void flag( const std::vector<bool>& msk = std::vector<bool>());
|
---|
229 | void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Return a list of row numbers with respect to the original table.
|
---|
233 | * @return a list of unsigned ints
|
---|
234 | */
|
---|
235 | std::vector<unsigned int> rownumbers() const;
|
---|
236 |
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * Get the number of beams in the data or a specific scan
|
---|
240 | * @param scanno the scan number to get the number of beams for.
|
---|
241 | * If scanno<0 the number is retrieved from the header.
|
---|
242 | * @return an integer number
|
---|
243 | */
|
---|
244 | int nbeam(int scanno=-1) const;
|
---|
245 | /**
|
---|
246 | * Get the number of IFs in the data or a specific scan
|
---|
247 | * @param scanno the scan number to get the number of IFs for.
|
---|
248 | * If scanno<0 the number is retrieved from the header.
|
---|
249 | * @return an integer number
|
---|
250 | */
|
---|
251 | int nif(int scanno=-1) const;
|
---|
252 | /**
|
---|
253 | * Get the number of polarizations in the data or a specific scan
|
---|
254 | * @param scanno the scan number to get the number of polarizations for.
|
---|
255 | * If scanno<0 the number is retrieved from the header.
|
---|
256 | * @return an integer number
|
---|
257 | */
|
---|
258 | int npol(int scanno=-1) const;
|
---|
259 |
|
---|
260 | std::string getPolType() const;
|
---|
261 |
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Get the number of integartion cycles
|
---|
265 | * @param scanno the scan number to get the number of rows for.
|
---|
266 | * If scanno<0 the number is retrieved from the header.
|
---|
267 | * @return the number of rows (for the specified scanno)
|
---|
268 | */
|
---|
269 | int nrow(int scanno=-1) const;
|
---|
270 |
|
---|
271 | int getBeam(int whichrow) const;
|
---|
272 | std::vector<uint> getBeamNos() { return getNumbers(beamCol_); }
|
---|
273 |
|
---|
274 | int getIF(int whichrow) const;
|
---|
275 | std::vector<uint> getIFNos() { return getNumbers(ifCol_); }
|
---|
276 |
|
---|
277 | int getPol(int whichrow) const;
|
---|
278 | std::vector<uint> getPolNos() { return getNumbers(polCol_); }
|
---|
279 |
|
---|
280 | std::vector<uint> getScanNos() { return getNumbers(scanCol_); }
|
---|
281 | int getScan(int whichrow) const { return scanCol_(whichrow); }
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Get the number of channels in the data or a specific IF. This currently
|
---|
285 | * varies only with IF number
|
---|
286 | * @param ifno the IF number to get the number of channels for.
|
---|
287 | * If ifno<0 the number is retrieved from the header.
|
---|
288 | * @return an integer number
|
---|
289 | */
|
---|
290 | int nchan(int ifno=-1) const;
|
---|
291 | int getChannels(int whichrow) const;
|
---|
292 |
|
---|
293 | int ncycle(int scanno=-1) const;
|
---|
294 | int getCycle(int whichrow) const { return cycleCol_(whichrow); }
|
---|
295 |
|
---|
296 | double getInterval(int whichrow) const
|
---|
297 | { return integrCol_(whichrow); }
|
---|
298 |
|
---|
299 | float getTsys(int whichrow) const
|
---|
300 | { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
|
---|
301 | float getElevation(int whichrow) const
|
---|
302 | { return elCol_(whichrow); }
|
---|
303 | float getAzimuth(int whichrow) const
|
---|
304 | { return azCol_(whichrow); }
|
---|
305 | float getParAngle(int whichrow) const
|
---|
306 | { return paraCol_(whichrow); }
|
---|
307 |
|
---|
308 | std::string getSourceName(int whichrow) const
|
---|
309 | { return srcnCol_(whichrow); }
|
---|
310 |
|
---|
311 | std::vector<bool> getMask(int whichrow) const;
|
---|
312 | std::vector<float> getSpectrum(int whichrow,
|
---|
313 | const std::string& poltype = "" ) const;
|
---|
314 |
|
---|
315 | void setSpectrum(const std::vector<float>& spec, int whichrow);
|
---|
316 |
|
---|
317 | std::string getPolarizationLabel(int index, const std::string& ptype) const
|
---|
318 | { return STPol::getPolLabel(index, ptype ); }
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Write the Scantable to disk
|
---|
322 | * @param filename the output file name
|
---|
323 | */
|
---|
324 | void makePersistent(const std::string& filename);
|
---|
325 |
|
---|
326 | std::vector<std::string> getHistory() const
|
---|
327 | { return historyTable_.getHistory(); };
|
---|
328 |
|
---|
329 | void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
|
---|
330 |
|
---|
331 | void appendToHistoryTable(const STHistory& otherhist)
|
---|
332 | { historyTable_.append(otherhist); }
|
---|
333 |
|
---|
334 | std::string summary(bool verbose=false);
|
---|
335 | std::string getTime(int whichrow=-1, bool showdate=true) const;
|
---|
336 | double getIntTime(int whichrow) const { return integrCol_(whichrow); }
|
---|
337 |
|
---|
338 | // returns unit, conversion frame, doppler, base-frame
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * Get the frequency set up
|
---|
342 | * This is forwarded to the STFrequencies subtable
|
---|
343 | * @return unit, frame, doppler
|
---|
344 | */
|
---|
345 | std::vector<std::string> getCoordInfo() const
|
---|
346 | { return freqTable_.getInfo(); };
|
---|
347 |
|
---|
348 | void setCoordInfo(std::vector<string> theinfo)
|
---|
349 | { return freqTable_.setInfo(theinfo); };
|
---|
350 |
|
---|
351 |
|
---|
352 | std::vector<double> getAbcissa(int whichrow) const;
|
---|
353 |
|
---|
354 | std::string getAbcissaLabel(int whichrow) const;
|
---|
355 | std::vector<double> getRestFrequencies() const
|
---|
356 | { return moleculeTable_.getRestFrequencies(); }
|
---|
357 |
|
---|
358 | void setRestFrequencies(double rf, const std::string& name = "",
|
---|
359 | const std::string& = "Hz");
|
---|
360 | void setRestFrequencies(const std::string& name);
|
---|
361 |
|
---|
362 | void shift(int npix);
|
---|
363 |
|
---|
364 | void convertDirection(const std::string& newframe);
|
---|
365 |
|
---|
366 | STFrequencies& frequencies() { return freqTable_; }
|
---|
367 | const STFrequencies& frequencies() const { return freqTable_; }
|
---|
368 | STWeather& weather() { return weatherTable_; }
|
---|
369 | const STWeather& weather() const { return weatherTable_; }
|
---|
370 | STFocus& focus() { return focusTable_; }
|
---|
371 | const STFocus& focus() const { return focusTable_; }
|
---|
372 | STTcal& tcal() { return tcalTable_; }
|
---|
373 | const STTcal& tcal() const { return tcalTable_; }
|
---|
374 | STMolecules& molecules() { return moleculeTable_; }
|
---|
375 | const STMolecules& molecules() const { return moleculeTable_; }
|
---|
376 | STHistory& history() { return historyTable_; }
|
---|
377 | const STHistory& history() const { return historyTable_; }
|
---|
378 | STFit& fit() { return fitTable_; }
|
---|
379 | const STFit& fit() const { return fitTable_; }
|
---|
380 |
|
---|
381 | std::vector<std::string> columnNames() const;
|
---|
382 |
|
---|
383 | void addFit(const STFitEntry& fit, int row);
|
---|
384 | STFitEntry getFit(int row) const
|
---|
385 | { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
|
---|
386 |
|
---|
387 | //Added by TT
|
---|
388 | /**
|
---|
389 | * Get the antenna name
|
---|
390 | * @return antenna name string
|
---|
391 | */
|
---|
392 | std::string getAntennaName() const;
|
---|
393 |
|
---|
394 | /**
|
---|
395 | * For GBT MS data only. check a scan list
|
---|
396 | * against the information found in GBT_GO table for
|
---|
397 | * scan number orders to get correct pairs.
|
---|
398 | * @param[in] scan list
|
---|
399 | * @return status
|
---|
400 | */
|
---|
401 | int checkScanInfo(const std::vector<int>& scanlist) const;
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * Get the direction as a vector, for a specific row
|
---|
405 | * @param[in] whichrow the row numbyyer
|
---|
406 | * @return the direction in a vector
|
---|
407 | */
|
---|
408 | std::vector<double> getDirectionVector(int whichrow) const;
|
---|
409 |
|
---|
410 | private:
|
---|
411 |
|
---|
412 | casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
|
---|
413 |
|
---|
414 | /**
|
---|
415 | * Turns a time vale into a formatted string
|
---|
416 | * @param x
|
---|
417 | * @return
|
---|
418 | */
|
---|
419 | std::string formatSec(casa::Double x) const;
|
---|
420 |
|
---|
421 | std::string formatTime(const casa::MEpoch& me, bool showdate)const;
|
---|
422 |
|
---|
423 | /**
|
---|
424 | * Turns a casa::MDirection into a nicely formatted string
|
---|
425 | * @param md an casa::MDirection
|
---|
426 | * @return
|
---|
427 | */
|
---|
428 | std::string formatDirection(const casa::MDirection& md) const;
|
---|
429 |
|
---|
430 |
|
---|
431 | /**
|
---|
432 | * Create a unique file name for the paged (temporary) table
|
---|
433 | * @return just the name
|
---|
434 | */
|
---|
435 | static casa::String generateName();
|
---|
436 |
|
---|
437 | /**
|
---|
438 | * attach to cached columns
|
---|
439 | */
|
---|
440 | void attach();
|
---|
441 |
|
---|
442 | /**
|
---|
443 | * Set up the main casa::Table
|
---|
444 | */
|
---|
445 | void setupMainTable();
|
---|
446 |
|
---|
447 | void attachSubtables();
|
---|
448 | void copySubtables(const Scantable& other);
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * Convert an "old" asap1 style row index into a new index
|
---|
452 | * @param[in] therow
|
---|
453 | * @return and index into @table_
|
---|
454 | */
|
---|
455 | int rowToScanIndex(int therow);
|
---|
456 |
|
---|
457 | std::vector<uint> getNumbers(casa::ScalarColumn<casa::uInt>& col);
|
---|
458 |
|
---|
459 | static const casa::uInt version_ = 2;
|
---|
460 |
|
---|
461 | STSelector selector_;
|
---|
462 |
|
---|
463 | casa::Table::TableType type_;
|
---|
464 |
|
---|
465 | // the actual data
|
---|
466 | casa::Table table_;
|
---|
467 | casa::Table originalTable_;
|
---|
468 |
|
---|
469 | STTcal tcalTable_;
|
---|
470 | STFrequencies freqTable_;
|
---|
471 | STWeather weatherTable_;
|
---|
472 | STFocus focusTable_;
|
---|
473 | STMolecules moleculeTable_;
|
---|
474 | STHistory historyTable_;
|
---|
475 | STFit fitTable_;
|
---|
476 |
|
---|
477 | // Cached Columns to avoid reconstructing them for each row get/put
|
---|
478 | casa::ScalarColumn<casa::Double> integrCol_;
|
---|
479 | casa::MDirection::ScalarColumn dirCol_;
|
---|
480 | casa::MEpoch::ScalarColumn timeCol_;
|
---|
481 | casa::ScalarColumn<casa::Float> azCol_;
|
---|
482 | casa::ScalarColumn<casa::Float> elCol_;
|
---|
483 | casa::ScalarColumn<casa::Float> paraCol_;
|
---|
484 | casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
|
---|
485 | casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_;
|
---|
486 | casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
|
---|
487 | casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
|
---|
488 | casa::ArrayColumn<casa::uChar> flagsCol_;
|
---|
489 |
|
---|
490 | // id in frequencies table
|
---|
491 | casa::ScalarColumn<casa::uInt> mfreqidCol_;
|
---|
492 | // id in tcal table
|
---|
493 | casa::ScalarColumn<casa::uInt> mtcalidCol_;
|
---|
494 |
|
---|
495 | casa::ArrayColumn<casa::String> histitemCol_;
|
---|
496 | casa::ScalarColumn<casa::Int> mfitidCol_;
|
---|
497 | casa::ScalarColumn<casa::uInt> mweatheridCol_;
|
---|
498 |
|
---|
499 | casa::ScalarColumn<casa::uInt> mfocusidCol_;
|
---|
500 |
|
---|
501 | casa::ScalarColumn<casa::uInt> mmolidCol_;
|
---|
502 |
|
---|
503 | static std::map<std::string, STPol::STPolFactory *> factories_;
|
---|
504 | void initFactories();
|
---|
505 |
|
---|
506 | };
|
---|
507 |
|
---|
508 |
|
---|
509 | } // namespace
|
---|
510 |
|
---|
511 | #endif
|
---|