source: trunk/src/Scantable.h@ 1928

Last change on this file since 1928 was 1919, checked in by Takeshi Nakazato, 14 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: ori_sio_task_regression

Put in Release Notes: No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Changed variables for memory address in C++ int to long.
I don't believe that this change essentially fixes the problem.
However, it may improve the situation since 'long' is able to
represent larger integer value than 'int'.


  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.3 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 <tables/Tables/Table.h>
25#include <tables/Tables/ArrayColumn.h>
26#include <tables/Tables/ScalarColumn.h>
27
28#include <measures/TableMeasures/ScalarMeasColumn.h>
29
30#include <coordinates/Coordinates/SpectralCoordinate.h>
31
32#include <casa/Arrays/Vector.h>
33#include <casa/Quanta/Quantum.h>
34
35#include <casa/Exceptions/Error.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#include "STFitter.h"
50
51namespace asap {
52
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*/
71class Scantable : private Logger
72{
73
74friend class STMath;
75
76public:
77 /**
78 * Default constructor
79 */
80 explicit Scantable(casa::Table::TableType ttype = casa::Table::Memory);
81
82 /**
83 * Create a Scantable object form an existing table on disk
84 * @param[in] name the name of the existing Scantable
85 */
86 explicit Scantable(const std::string& name, casa::Table::TableType ttype = casa::Table::Memory);
87
88 /// @fixme this is only sensible for MemoryTables....
89 Scantable(const Scantable& other, bool clear=true);
90
91 /**
92 * Destructor
93 */
94 virtual ~Scantable();
95
96 /**
97 * get a const reference to the underlying casa::Table
98 * @return const \ref casa::Table reference
99 */
100 const casa::Table& table() const;
101
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();
108
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 */
120 void setSelection(const STSelector& selection);
121
122 /**
123 * unset the selection of the data
124 */
125 void unsetSelection();
126 /**
127 * set the header
128 * @param[in] sth an STHeader object
129 */
130 void setHeader( const STHeader& sth );
131
132 /**
133 * get the header information
134 * @return an STHeader object
135 */
136 STHeader getHeader( ) const;
137
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);
145
146 /**
147 *
148 * @param stype The type of the source, 0 = on, 1 = off
149 */
150 void setSourceType(int stype);
151
152
153 /**
154 * The number of scans in the table
155 * @return number of scans in the table
156 */
157 int nscan() const;
158
159 casa::MEpoch::Types getTimeReference() const;
160
161
162 casa::MEpoch getEpoch(int whichrow) const;
163
164 /**
165 * Get global antenna position
166 * @return casa::MPosition
167 */
168 casa::MPosition getAntennaPosition() const;
169
170 /**
171 * the @ref casa::MDirection for a specific row
172 * @param[in] whichrow the row number
173 * return casa::MDirection
174 */
175 casa::MDirection getDirection( int whichrow ) const;
176
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 */
182 std::string getDirectionString( int whichrow ) const;
183
184 /**
185 * set the direction type as a string, e.g. "J2000"
186 * @param[in] refstr the direction type
187 */
188 void setDirectionRefString(const std::string& refstr="");
189
190 /**
191 * get the direction reference string
192 * @return a string describing the direction reference
193 */
194 std::string getDirectionRefString() const;
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 * 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 /**
261 * Return a list of row numbers with respect to the original table.
262 * @return a list of unsigned ints
263 */
264 std::vector<unsigned int> rownumbers() const;
265
266
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 */
273 int nbeam(int scanno=-1) const;
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 */
280 int nif(int scanno=-1) const;
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 */
287 int npol(int scanno=-1) const;
288
289 std::string getPolType() const;
290
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.
296 * @return the number of rows (for the specified scanno)
297 */
298 int nrow(int scanno=-1) const;
299
300 int getBeam(int whichrow) const;
301 std::vector<uint> getBeamNos() const { return getNumbers(beamCol_); }
302
303 int getIF(int whichrow) const;
304 std::vector<uint> getIFNos() const { return getNumbers(ifCol_); }
305
306 int getPol(int whichrow) const;
307 std::vector<uint> getPolNos() const { return getNumbers(polCol_); }
308
309 std::vector<uint> getScanNos() const { return getNumbers(scanCol_); }
310 int getScan(int whichrow) const { return scanCol_(whichrow); }
311
312 //TT addition
313 std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); }
314
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;
323 int getChannels(int whichrow) const;
324
325 int ncycle(int scanno=-1) const;
326 int getCycle(int whichrow) const { return cycleCol_(whichrow); }
327
328 double getInterval(int whichrow) const
329 { return integrCol_(whichrow); }
330
331 float getTsys(int whichrow) const
332 { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
333 float getElevation(int whichrow) const
334 { return elCol_(whichrow); }
335 float getAzimuth(int whichrow) const
336 { return azCol_(whichrow); }
337 float getParAngle(int whichrow) const
338 { return focus().getParAngle(mfocusidCol_(whichrow)); }
339 int getTcalId(int whichrow) const
340 { return mtcalidCol_(whichrow); }
341
342 std::string getSourceName(int whichrow) const
343 { return srcnCol_(whichrow); }
344
345 std::vector<bool> getMask(int whichrow) const;
346 std::vector<float> getSpectrum(int whichrow,
347 const std::string& poltype = "" ) const;
348
349 void setSpectrum(const std::vector<float>& spec, int whichrow);
350
351 std::string getPolarizationLabel(int index, const std::string& ptype) const
352 { return STPol::getPolLabel(index, ptype ); }
353
354 /**
355 * Write the Scantable to disk
356 * @param filename the output file name
357 */
358 void makePersistent(const std::string& filename);
359
360 std::vector<std::string> getHistory() const
361 { return historyTable_.getHistory(); };
362
363 void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
364
365 void appendToHistoryTable(const STHistory& otherhist)
366 { historyTable_.append(otherhist); }
367
368 std::string summary(bool verbose=false);
369 std::string getTime(int whichrow=-1, bool showdate=true) const;
370 double getIntTime(int whichrow) const { return integrCol_(whichrow); }
371
372 // returns unit, conversion frame, doppler, base-frame
373
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
385
386 std::vector<double> getAbcissa(int whichrow) const;
387
388 std::vector<float> getWeather(int whichrow) const;
389
390 std::string getAbcissaLabel(int whichrow) const;
391 std::vector<double> getRestFrequencies() const
392 { return moleculeTable_.getRestFrequencies(); }
393 std::vector<double> getRestFrequency(int id) const
394 { return moleculeTable_.getRestFrequency(id); }
395
396 /**
397 void setRestFrequencies(double rf, const std::string& name = "",
398 const std::string& = "Hz");
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");
408
409 //void setRestFrequencies(const std::string& name);
410 void setRestFrequencies(const vector<std::string>& name);
411
412 void shift(int npix);
413
414 casa::SpectralCoordinate getSpectralCoordinate(int whichrow) const;
415
416 void convertDirection(const std::string& newframe);
417
418 STFrequencies& frequencies() { return freqTable_; }
419 const STFrequencies& frequencies() const { return freqTable_; }
420 STWeather& weather() { return weatherTable_; }
421 const STWeather& weather() const { return weatherTable_; }
422 STFocus& focus() { return focusTable_; }
423 const STFocus& focus() const { return focusTable_; }
424 STTcal& tcal() { return tcalTable_; }
425 const STTcal& tcal() const { return tcalTable_; }
426 STMolecules& molecules() { return moleculeTable_; }
427 const STMolecules& molecules() const { return moleculeTable_; }
428 STHistory& history() { return historyTable_; }
429 const STHistory& history() const { return historyTable_; }
430 STFit& fit() { return fitTable_; }
431 const STFit& fit() const { return fitTable_; }
432
433 std::vector<std::string> columnNames() const;
434
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
439 //Added by TT
440 /**
441 * Get the antenna name
442 * @return antenna name string
443 */
444 casa::String getAntennaName() const;
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
462 /**
463 * Set a flag indicating whether the data was parallactified
464 * @param[in] flag true or false
465 */
466 void parallactify(bool flag)
467 { focus().setParallactify(flag); }
468
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
489 bool getFlagtraFast(int whichrow);
490
491 void polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno);
492 void polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size);
493
494
495private:
496
497 casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
498
499 /**
500 * Turns a time vale into a formatted string
501 * @param x
502 * @return
503 */
504 std::string formatSec(casa::Double x) const;
505
506 std::string formatTime(const casa::MEpoch& me, bool showdate)const;
507
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;
514
515 /**
516 * Create a unique file name for the paged (temporary) table
517 * @return just the name
518 */
519 static casa::String generateName();
520
521 /**
522 * attach to cached columns
523 */
524 void attach();
525
526 /**
527 * Set up the main casa::Table
528 */
529 void setupMainTable();
530
531 void attachSubtables();
532 void copySubtables(const Scantable& other);
533
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);
540
541 std::vector<uint> getNumbers(const casa::ScalarColumn<casa::uInt>& col) const;
542
543 static const casa::uInt version_ = 3;
544
545 STSelector selector_;
546
547 casa::Table::TableType type_;
548
549 // the actual data
550 casa::Table table_;
551 casa::Table originalTable_;
552
553 STTcal tcalTable_;
554 STFrequencies freqTable_;
555 STWeather weatherTable_;
556 STFocus focusTable_;
557 STMolecules moleculeTable_;
558 STHistory historyTable_;
559 STFit fitTable_;
560
561 // Cached Columns to avoid reconstructing them for each row get/put
562 casa::ScalarColumn<casa::Double> integrCol_;
563 casa::MDirection::ScalarColumn dirCol_;
564 casa::MEpoch::ScalarColumn timeCol_;
565 casa::ScalarColumn<casa::Float> azCol_;
566 casa::ScalarColumn<casa::Float> elCol_;
567 casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
568 casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_, flagrowCol_;
569 casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
570 casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
571 casa::ArrayColumn<casa::uChar> flagsCol_;
572
573 // id in frequencies table
574 casa::ScalarColumn<casa::uInt> mfreqidCol_;
575 // id in tcal table
576 casa::ScalarColumn<casa::uInt> mtcalidCol_;
577
578 casa::ArrayColumn<casa::String> histitemCol_;
579 casa::ScalarColumn<casa::Int> mfitidCol_;
580 casa::ScalarColumn<casa::uInt> mweatheridCol_;
581
582 casa::ScalarColumn<casa::uInt> mfocusidCol_;
583
584 casa::ScalarColumn<casa::uInt> mmolidCol_;
585
586 static std::map<std::string, STPol::STPolFactory *> factories_;
587 void initFactories();
588
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>&);
605
606 void doPolyBaseline(const std::vector<bool>& mask, int order, int rowno, Fitter& fitter);
607};
608
609
610} // namespace
611
612#endif
Note: See TracBrowser for help on using the repository browser.