1 | //#---------------------------------------------------------------------------
|
---|
2 | //# SDMemTable.h: A MemoryTable container for single dish integrations
|
---|
3 | //#---------------------------------------------------------------------------
|
---|
4 | //# Copyright (C) 2004
|
---|
5 | //# ATNF
|
---|
6 | //#
|
---|
7 | //# This program is free software; you can redistribute it and/or modify it
|
---|
8 | //# under the terms of the GNU General Public License as published by the Free
|
---|
9 | //# Software Foundation; either version 2 of the License, or (at your option)
|
---|
10 | //# any later version.
|
---|
11 | //#
|
---|
12 | //# This program is distributed in the hope that it will be useful, but
|
---|
13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
---|
15 | //# Public License for more details.
|
---|
16 | //#
|
---|
17 | //# You should have received a copy of the GNU General Public License along
|
---|
18 | //# with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
|
---|
20 | //#
|
---|
21 | //# Correspondence concerning this software should be addressed as follows:
|
---|
22 | //# Internet email: Malte.Marquarding@csiro.au
|
---|
23 | //# Postal address: Malte Marquarding,
|
---|
24 | //# Australia Telescope National Facility,
|
---|
25 | //# P.O. Box 76,
|
---|
26 | //# Epping, NSW, 2121,
|
---|
27 | //# AUSTRALIA
|
---|
28 | //#
|
---|
29 | //# $Id:
|
---|
30 | //#---------------------------------------------------------------------------
|
---|
31 | #ifndef SDMEMTABLE_H
|
---|
32 | #define SDMEMTABLE_H
|
---|
33 |
|
---|
34 | // STL
|
---|
35 | #include <string>
|
---|
36 | #include <vector>
|
---|
37 | // AIPS++
|
---|
38 | #include <casa/aips.h>
|
---|
39 | #include <casa/Arrays/MaskedArray.h>
|
---|
40 | #include <casa/BasicSL/String.h>
|
---|
41 | #include <coordinates/Coordinates/SpectralCoordinate.h>
|
---|
42 | #include <tables/Tables/Table.h>
|
---|
43 | #include <tables/Tables/ArrayColumn.h>
|
---|
44 | #include <tables/Tables/ScalarColumn.h>
|
---|
45 |
|
---|
46 | #include "SDDefs.h"
|
---|
47 | #include "SDFitTable.h"
|
---|
48 |
|
---|
49 | namespace asap {
|
---|
50 |
|
---|
51 | class SDContainer;
|
---|
52 | class SDHeader;
|
---|
53 | class SDFrequencyTable;
|
---|
54 | class SDFitTable;
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | class SDMemTable {
|
---|
59 | public:
|
---|
60 | // create a new (empty) SDMemTable
|
---|
61 | SDMemTable();
|
---|
62 | // create a SDMemTable from an (aips++) table on disk
|
---|
63 | SDMemTable(const std::string& name);
|
---|
64 |
|
---|
65 | // Copy Construct a SDMemTable, if clear==True only header and
|
---|
66 | // skeleton are copied, otherwise the whole table is copied.
|
---|
67 | SDMemTable(const SDMemTable& other, casa::Bool clear=casa::False);
|
---|
68 |
|
---|
69 | // Copy Construct (copy semantics) a SDMemTable, give a scanid constraint
|
---|
70 | // see also getScan()
|
---|
71 | SDMemTable(const casa::Table& tab, const std::string& expr);
|
---|
72 |
|
---|
73 | // Assignment operator (copy semantics)
|
---|
74 | SDMemTable &operator=(const SDMemTable& other);
|
---|
75 |
|
---|
76 | virtual ~SDMemTable();
|
---|
77 |
|
---|
78 | // put data from meta conatiner into the table
|
---|
79 | bool putSDContainer(const SDContainer& sdc);
|
---|
80 | bool putSDHeader(const SDHeader& sdh);
|
---|
81 | bool putSDFreqTable(const SDFrequencyTable& sdft);
|
---|
82 |
|
---|
83 | //get the data wrapped up in a meta container
|
---|
84 |
|
---|
85 | SDContainer getSDContainer(casa::uInt whichRow=0) const;
|
---|
86 | SDHeader getSDHeader() const;
|
---|
87 |
|
---|
88 | // Get SD Frequency table.
|
---|
89 | SDFrequencyTable getSDFreqTable() const;
|
---|
90 |
|
---|
91 | // get spectrum,mask and tsys for the given row, at the selected
|
---|
92 | // cursor - all as stl vectors
|
---|
93 | virtual std::vector<float> getSpectrum(casa::Int whichRow=0) const;
|
---|
94 | virtual std::vector<bool> getMask(casa::Int whichRow=0) const;
|
---|
95 |
|
---|
96 | // When we can handle input correlations being either circular or
|
---|
97 | // linear, we should probably have functions; getLinear,
|
---|
98 | // getCircular, getStokes since one can inter-convert between all
|
---|
99 | // three regardless of the input provided there are 4
|
---|
100 | // polarizations. For now, we are assuming, if there are 4
|
---|
101 | // polarizations, that we have linears. getSpectrum is then
|
---|
102 | // 'getLinear', getStokesSpectrum is 'getStokes' and
|
---|
103 | // getCircularSpectrum is 'getCircular'
|
---|
104 |
|
---|
105 | // Get specific Stokes at cursor location. One of either I,Q,U,V or I,P,PA,V (doPol=True)
|
---|
106 | // (determined by the polSel cursor location 0->3)
|
---|
107 | // If the latter, you can add a PA offset (degrees)
|
---|
108 | virtual std::vector<float> getStokesSpectrum(casa::Int whichRow=0,
|
---|
109 | casa::Bool doPol=casa::False,
|
---|
110 | casa::Float paOffset=0.0) const;
|
---|
111 |
|
---|
112 | // Get RR or LL at cursor location (except not polSel_)
|
---|
113 | virtual std::vector<float> getCircularSpectrum(casa::Int whichRow=0,
|
---|
114 | casa::Bool rr=casa::True) const;
|
---|
115 |
|
---|
116 | // Get all Stokes at the specified Beam/IF cursor location (ignoring
|
---|
117 | // the internal cursor). -1 means all on that axis. Really, this function
|
---|
118 | // should not be here, and the SDContainer should hold the stokes spectrum
|
---|
119 | // as well. However, because the Stokes column is virtual, and its shape
|
---|
120 | // is not the same as nPol(), I have put it here for direct access as needed
|
---|
121 | virtual casa::Array<casa::Float> getStokesSpectrum(casa::Int whichRow=0,
|
---|
122 | casa::Int iBeam=-1,
|
---|
123 | casa::Int iIF=-1) const;
|
---|
124 |
|
---|
125 | // Get Tsys at cursor location
|
---|
126 | virtual casa::Float getTsys(casa::Int whichRow=0) const;
|
---|
127 |
|
---|
128 | // get all as aips++ Vectors
|
---|
129 | virtual void getSpectrum(casa::Vector<casa::Float>& spectrum,
|
---|
130 | casa::Int whichRow=0) const;
|
---|
131 | //virtual void getMask(Vector<Bool>& mask,Int whichRow=0) const;
|
---|
132 |
|
---|
133 | // Get rest frequencies
|
---|
134 | std::vector<double> getRestFreqs() const;
|
---|
135 |
|
---|
136 | // get info for current row
|
---|
137 | // if whichRow == -1 the Header time is given
|
---|
138 | std::string getTime(casa::Int whichRow=0,
|
---|
139 | casa::Bool showDate=casa::False) const ;
|
---|
140 | casa::MEpoch getEpoch(casa::Int whichRow=0) const;
|
---|
141 | casa::MDirection getDirection(casa::Int whichRow=0,
|
---|
142 | casa::Bool refBeam=casa::False) const;
|
---|
143 |
|
---|
144 | std::string getSourceName(casa::Int whichRow=0) const;
|
---|
145 | double getInterval(casa::Int whichRow=0) const;
|
---|
146 |
|
---|
147 | virtual void setSpectrum(std::vector<float> spectrum, int whichRow=0);
|
---|
148 | virtual void setCoordInfo(std::vector<string> theinfo);
|
---|
149 |
|
---|
150 | // Set RestFreqID. source="" and IF=-1 means select all
|
---|
151 | virtual casa::Bool setRestFreqs(const casa::Vector<casa::Double>& restFreqs,
|
---|
152 | const casa::String& unit,
|
---|
153 | const std::vector<std::string>& lines,
|
---|
154 | const casa::String& source,
|
---|
155 | casa::Int whichIF=-1);
|
---|
156 |
|
---|
157 | // List lines
|
---|
158 | void spectralLines() const;
|
---|
159 |
|
---|
160 | // Get/Set flux unit
|
---|
161 | std::string getFluxUnit() const;
|
---|
162 | void setFluxUnit (const std::string& unit);
|
---|
163 |
|
---|
164 | // Set Instrument
|
---|
165 | void setInstrument (const std::string& instrument);
|
---|
166 |
|
---|
167 | // set the current value
|
---|
168 | virtual bool setIF(casa::Int whichIF=0);
|
---|
169 | virtual bool setBeam(casa::Int whichBeam=0);
|
---|
170 | virtual bool setPol(casa::Int whichPol=0);
|
---|
171 |
|
---|
172 | // REset cursor to 0
|
---|
173 | virtual void resetCursor();
|
---|
174 |
|
---|
175 | //sets the user mask applied to all spectra
|
---|
176 | virtual bool setMask(std::vector<int> whichChans);
|
---|
177 | // Hard flags the current spectrum, not reversible
|
---|
178 | virtual void flag(int whichRow);
|
---|
179 |
|
---|
180 | // return the currently selected values
|
---|
181 | virtual casa::Int getIF() const { return IFSel_; }
|
---|
182 | virtual casa::Int getBeam() const { return beamSel_; }
|
---|
183 | virtual casa::Int getPol() const { return polSel_; }
|
---|
184 |
|
---|
185 | // returns unit, conversion frame, doppler, base-frame
|
---|
186 | virtual std::vector<std::string> getCoordInfo() const;
|
---|
187 |
|
---|
188 | // number of scans in table
|
---|
189 | virtual casa::Int nScan() const;
|
---|
190 |
|
---|
191 | // get a summary of the table
|
---|
192 | virtual std::string summary(bool verbose=false) const;
|
---|
193 |
|
---|
194 | // get/set the history
|
---|
195 | std::vector<std::string> getHistory() const;
|
---|
196 | void addHistory(const std::string& hist);
|
---|
197 |
|
---|
198 | casa::Table getHistoryTable() const;
|
---|
199 | void appendToHistoryTable(const casa::Table& otherHist);
|
---|
200 |
|
---|
201 | // write to disk as aips++ table
|
---|
202 | void makePersistent(const std::string& filename);
|
---|
203 |
|
---|
204 | // get a new SDMemTable containing all rows with the same give SCANID
|
---|
205 | SDMemTable getScan(casa::Int scanID) const;
|
---|
206 | SDMemTable getSource(const std::string& source) const;
|
---|
207 |
|
---|
208 | const casa::TableRecord& getHeader() const {return table_.keywordSet();}
|
---|
209 | // get a handle to the "raw" aips++ table
|
---|
210 | const casa::Table& table() const { return table_; }
|
---|
211 |
|
---|
212 | // return the number of values
|
---|
213 | casa::Int nBeam() const;
|
---|
214 | casa::Int nIF() const;
|
---|
215 | casa::Int nPol() const;
|
---|
216 | casa::Int nChan() const;
|
---|
217 |
|
---|
218 | // return the number of rows (integrations) in the table
|
---|
219 | casa::Int nRow() const { return table_.nrow(); }
|
---|
220 |
|
---|
221 | // return a row as a Masked array, internally converting uChar flags
|
---|
222 | // to bool mask
|
---|
223 | casa::MaskedArray<casa::Float> rowAsMaskedArray(casa::uInt whichRow,
|
---|
224 | casa::Bool toStokes=casa::False) const;
|
---|
225 |
|
---|
226 | // Return SC, setting only the basic construction state (i.e.
|
---|
227 | // no conversion or velocity or rest frequency state).
|
---|
228 | // Specify the index of the FreqID you want
|
---|
229 | casa::SpectralCoordinate getSpectralCoordinate(casa::uInt whichIdx) const;
|
---|
230 |
|
---|
231 | // Return SC. Set velocity conversion state (unit,doppler), and
|
---|
232 | // rest frequency. If row number given (>=0), also set
|
---|
233 | // frame conversion layer (needs direction & time which require row)
|
---|
234 | casa::SpectralCoordinate getSpectralCoordinate(casa::uInt freqID,
|
---|
235 | casa::uInt restFreqID,
|
---|
236 | casa::uInt row) const;
|
---|
237 |
|
---|
238 | // Set just the reference value, pixel and increment into the table
|
---|
239 | // No other state is extracted.
|
---|
240 | casa::Bool setCoordinate(const casa::SpectralCoordinate& speccord,
|
---|
241 | casa::uInt whichIdx);
|
---|
242 |
|
---|
243 | casa::Int nCoordinates() const;
|
---|
244 |
|
---|
245 | std::vector<double> getAbcissa(int whichRow=0) const;
|
---|
246 | std::string getAbcissaString(casa::Int whichRow=0) const;
|
---|
247 |
|
---|
248 | // Get global reference types
|
---|
249 | casa::MDirection::Types getDirectionReference() const;
|
---|
250 | casa::MEpoch::Types getTimeReference() const;
|
---|
251 |
|
---|
252 | // Get global antenna position
|
---|
253 | casa::MPosition getAntennaPosition() const;
|
---|
254 |
|
---|
255 | bool putSDFitTable(const SDFitTable& sdft);
|
---|
256 | SDFitTable getSDFitTable() const;
|
---|
257 | SDFitTable getSDFitTable(casa::uInt whichRow) const;
|
---|
258 |
|
---|
259 | void addFit(casa::uInt whichRow,
|
---|
260 | const casa::Vector<casa::Double>& p,
|
---|
261 | const casa::Vector<casa::Bool>& m,
|
---|
262 | const casa::Vector<casa::String>& f,
|
---|
263 | const casa::Vector<casa::Int>& c);
|
---|
264 |
|
---|
265 |
|
---|
266 | private:
|
---|
267 | // utility func for nice printout
|
---|
268 | casa::String formatSec(casa::Double x) const;
|
---|
269 | casa::String formatDirection(const casa::MDirection& md) const;
|
---|
270 | std::vector<float> getFloatSpectrum(const casa::Array<casa::Float>& arr) const;
|
---|
271 | void setup();
|
---|
272 | void attach();
|
---|
273 | void renumber();
|
---|
274 |
|
---|
275 | // Generate start and end for shape and current cursor selection
|
---|
276 | void getCursorSlice(casa::IPosition& start, casa::IPosition& end,
|
---|
277 | const casa::IPosition& shape) const;
|
---|
278 |
|
---|
279 | // the current cursor into the array
|
---|
280 | casa::Int IFSel_,beamSel_,polSel_;
|
---|
281 | std::vector<bool> chanMask_;
|
---|
282 | // the underlying memory table
|
---|
283 | casa::Table table_;
|
---|
284 | // The current table version
|
---|
285 | static const casa::uInt version_ = 1;
|
---|
286 |
|
---|
287 | // Cached Columns to avoid reconstructing them for each row get/put
|
---|
288 | casa::ScalarColumn<casa::Double> timeCol_, integrCol_;
|
---|
289 | casa::ScalarColumn<casa::Float> azCol_, elCol_, paraCol_;
|
---|
290 | casa::ScalarColumn<casa::String> srcnCol_, fldnCol_, tcaltCol_;
|
---|
291 | casa::ScalarColumn<casa::Int> scanCol_, rbeamCol_;
|
---|
292 | casa::ArrayColumn<casa::Float> specCol_, tsCol_, tcalCol_;
|
---|
293 | casa::ArrayColumn<casa::Double> dirCol_;
|
---|
294 | casa::ArrayColumn<casa::uChar> flagsCol_;
|
---|
295 | casa::ArrayColumn<casa::uInt> freqidCol_, restfreqidCol_;
|
---|
296 | casa::ArrayColumn<casa::String> histCol_;
|
---|
297 | casa::ArrayColumn<casa::Int> fitCol_;
|
---|
298 | casa::ROArrayColumn<casa::Float> stokesCol_;
|
---|
299 | };
|
---|
300 |
|
---|
301 | }// namespace
|
---|
302 | #endif
|
---|