1 | //#---------------------------------------------------------------------------
|
---|
2 | //# SDMath.h: A collection of single dish mathematical operations
|
---|
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 SDMATH_H
|
---|
32 | #define SDMATH_H
|
---|
33 |
|
---|
34 | #include <string>
|
---|
35 | #include <vector>
|
---|
36 | #include <casa/aips.h>
|
---|
37 | #include <casa/Utilities/CountedPtr.h>
|
---|
38 | #include <coordinates/Coordinates/FrequencyAligner.h>
|
---|
39 |
|
---|
40 | #include "SDDefs.h"
|
---|
41 | #include "SDLog.h"
|
---|
42 |
|
---|
43 | class casa::Table;
|
---|
44 | class casa::MEpoch;
|
---|
45 | class casa::MPosition;
|
---|
46 | template<class T> class casa::PtrBlock;
|
---|
47 | template<class T> class casa::Matrix;
|
---|
48 | template<class T> class casa::ROScalarColumn;
|
---|
49 | template<class T> class casa::ROArrayColumn;
|
---|
50 |
|
---|
51 | namespace asap {
|
---|
52 |
|
---|
53 | class SDMemTable;
|
---|
54 | class SDDataDesc;
|
---|
55 |
|
---|
56 | class SDMath : private SDLog {
|
---|
57 |
|
---|
58 | public:
|
---|
59 |
|
---|
60 | // Default constructor
|
---|
61 | SDMath();
|
---|
62 |
|
---|
63 | // Copy Constructor (copy semantics)
|
---|
64 | SDMath(const SDMath& other);
|
---|
65 |
|
---|
66 | // Assignment (copy semantics)
|
---|
67 | SDMath &operator=(const SDMath& other);
|
---|
68 |
|
---|
69 | // Destructor
|
---|
70 | ~SDMath();
|
---|
71 |
|
---|
72 | // Binary Table operators. op=ADD, SUB, MUL, DIV, QUOTIENT
|
---|
73 | casa::CountedPtr<SDMemTable> binaryOperate(const casa::CountedPtr<SDMemTable>& left,
|
---|
74 | const casa::CountedPtr<SDMemTable>& right,
|
---|
75 | const casa::String& op, casa::Bool preserve,
|
---|
76 | casa::Bool tSys);
|
---|
77 |
|
---|
78 | // Average in time
|
---|
79 | casa::CountedPtr<SDMemTable> average(const std::vector<casa::CountedPtr<SDMemTable> >& in,
|
---|
80 | const casa::Vector<casa::Bool>& mask,
|
---|
81 | casa::Bool scanAverage,
|
---|
82 | const casa::String& weightStr,
|
---|
83 | casa::Bool align=casa::False);
|
---|
84 |
|
---|
85 | // Statistics. If row<0, all rows are done otherwise, just the
|
---|
86 | // specified row.
|
---|
87 | std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in,
|
---|
88 | const casa::Vector<casa::Bool>& mask,
|
---|
89 | const casa::String& which, casa::Int row) const;
|
---|
90 |
|
---|
91 | // Bin up spectra
|
---|
92 | SDMemTable* bin(const SDMemTable& in, casa::Int width);
|
---|
93 |
|
---|
94 | // Resample spectra
|
---|
95 | SDMemTable* resample(const SDMemTable& in, const casa::String& method,
|
---|
96 | casa::Float factor);
|
---|
97 |
|
---|
98 | // Smooth
|
---|
99 | SDMemTable* smooth(const SDMemTable& in, const casa::String& kernel,
|
---|
100 | casa::Float width, casa::Bool doAll);
|
---|
101 |
|
---|
102 | // Flux conversion between Jansky and Kelvin
|
---|
103 | SDMemTable* convertFlux(const SDMemTable& in, casa::Float D,
|
---|
104 | casa::Float etaAp,
|
---|
105 | casa::Float JyPerK, casa::Bool doAll);
|
---|
106 |
|
---|
107 | // Gain-elevation correction
|
---|
108 | SDMemTable* gainElevation(const SDMemTable& in,
|
---|
109 | const casa::Vector<casa::Float>& coeffs,
|
---|
110 | const casa::String& fileName,
|
---|
111 | const casa::String& method,
|
---|
112 | casa::Bool doAll);
|
---|
113 |
|
---|
114 | // Frequency Alignment
|
---|
115 | SDMemTable* frequencyAlignment(const SDMemTable& in, const casa::String& refTime,
|
---|
116 | const casa::String& method, casa::Bool perFreqID);
|
---|
117 |
|
---|
118 | // Opacity correction
|
---|
119 | SDMemTable* opacity(const SDMemTable& in, casa::Float tau, casa::Bool doAll);
|
---|
120 |
|
---|
121 | // Simple unary mathematical operations. what=0 (mul) or 1 (add)
|
---|
122 | SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset,
|
---|
123 | casa::Bool doAll, casa::uInt what, casa::Bool tSys);
|
---|
124 |
|
---|
125 | // Average polarizations.
|
---|
126 | SDMemTable* averagePol(const SDMemTable& in,
|
---|
127 | const casa::Vector<casa::Bool>& mask,
|
---|
128 | const casa::String& wtStr);
|
---|
129 |
|
---|
130 | SDMemTable* frequencySwitch(const SDMemTable& in);
|
---|
131 |
|
---|
132 |
|
---|
133 | // Rotate XY phase. Value in degrees.
|
---|
134 | void rotateXYPhase(SDMemTable& in, casa::Float value, casa::Bool doAll);
|
---|
135 |
|
---|
136 | // Rotate Q & U by operating on the raw correlations.Value in degrees.
|
---|
137 | void rotateLinPolPhase(SDMemTable& in, casa::Float value, casa::Bool doAll);
|
---|
138 |
|
---|
139 | // Complex conjugate of phase
|
---|
140 | void invertPhase(SDMemTable& in, casa::Bool doAll);
|
---|
141 |
|
---|
142 | // Swap polarisation order
|
---|
143 | void swapPol(SDMemTable& in, casa::Bool doAll);
|
---|
144 |
|
---|
145 | private:
|
---|
146 |
|
---|
147 | // Weighting type for time averaging
|
---|
148 |
|
---|
149 | enum WeightType {NONE=0,VAR,TSYS,TINT,TINTSYS,nWeightTypes};
|
---|
150 |
|
---|
151 | // Function to use accumulate data during time averaging
|
---|
152 |
|
---|
153 | void accumulate(casa::Double& timeSum, casa::Double& intSum,
|
---|
154 | casa::Int& nAccum,
|
---|
155 | casa::MaskedArray<casa::Float>& sum,
|
---|
156 | casa::Array<casa::Float>& sumSq,
|
---|
157 | casa::Array<casa::Float>& nPts,
|
---|
158 | casa::Array<casa::Float>& tSysSum,
|
---|
159 | casa::Array<casa::Float>& tSysSqSum,
|
---|
160 | const casa::Array<casa::Float>& tSys,
|
---|
161 | const casa::Array<casa::Float>& nInc,
|
---|
162 | const casa::Vector<casa::Bool>& mask,
|
---|
163 | casa::Double time, casa::Double interval,
|
---|
164 | const std::vector<casa::CountedPtr<SDMemTable> >& in,
|
---|
165 | casa::uInt iTab, casa::uInt iRow,
|
---|
166 | casa::uInt axis, casa::uInt nAxesSub,
|
---|
167 | casa::Bool useMask, WeightType wtType);
|
---|
168 |
|
---|
169 | // Work out conversion factor for converting Jy<->K per IF per row and apply
|
---|
170 | void convertBrightnessUnits(SDMemTable* pTabOut, const SDMemTable& in,
|
---|
171 | casa::Bool toKelvin, casa::Float sFac, casa::Bool doAll);
|
---|
172 |
|
---|
173 | // Convert weight string to enum value
|
---|
174 |
|
---|
175 | void convertWeightString(WeightType& wt, const casa::String& weightStr,
|
---|
176 | casa::Bool listType);;
|
---|
177 |
|
---|
178 | // Convert interpolation type string
|
---|
179 | // void convertInterpString(casa::Int& type, const casa::String& interp);
|
---|
180 | void convertInterpString(casa::InterpolateArray1D<casa::Double,casa::Float>::InterpolationMethod& method,
|
---|
181 | const casa::String& interp);
|
---|
182 |
|
---|
183 | // Scale data with values from an ascii Table
|
---|
184 | void scaleFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in,
|
---|
185 | const casa::String& fileName,
|
---|
186 | const casa::String& col0, const casa::String& col1,
|
---|
187 | const casa::String& methodStr, casa::Bool doAll,
|
---|
188 | const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
|
---|
189 |
|
---|
190 | // Scale data with values from a Table
|
---|
191 | void scaleFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable,
|
---|
192 | const casa::String& col0, const casa::String& col1,
|
---|
193 | const casa::String& methodStr, casa::Bool doAll,
|
---|
194 | const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
|
---|
195 |
|
---|
196 | // Scale data and optionally TSys by values in a Vector
|
---|
197 | void scaleByVector(SDMemTable* pTabOut, const SDMemTable& in,
|
---|
198 | casa::Bool doAll, const casa::Vector<casa::Float>& factor,
|
---|
199 | casa::Bool doTSys);
|
---|
200 |
|
---|
201 | // Convert time String to Epoch
|
---|
202 | casa::MEpoch epochFromString(const casa::String& str, casa::MEpoch::Types timeRef);
|
---|
203 |
|
---|
204 | // Function to fill Scan Container when averaging in time
|
---|
205 |
|
---|
206 | void fillSDC(SDContainer& sc, const casa::Array<casa::Bool>& mask,
|
---|
207 | const casa::Array<casa::Float>& data,
|
---|
208 | const casa::Array<casa::Float>& tSys,
|
---|
209 | casa::Int scanID, casa::Double timeStamp,
|
---|
210 | casa::Double interval, const casa::String& sourceName,
|
---|
211 | const casa::Vector<casa::uInt>& freqID);
|
---|
212 |
|
---|
213 | // Format EPoch
|
---|
214 | casa::String formatEpoch(const casa::MEpoch& epoch) const;
|
---|
215 |
|
---|
216 | // Align in Frequency
|
---|
217 | SDMemTable* frequencyAlign(const SDMemTable& in,
|
---|
218 | casa::MFrequency::Types system,
|
---|
219 | const casa::String& timeRef,
|
---|
220 | const casa::String& method,
|
---|
221 | casa::Bool perIF);
|
---|
222 |
|
---|
223 | // Generate frequency aligners
|
---|
224 | void generateFrequencyAligners(casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a,
|
---|
225 | const SDDataDesc& dDesc,
|
---|
226 | const SDMemTable& in, casa::uInt nChan,
|
---|
227 | casa::MFrequency::Types system,
|
---|
228 | const casa::MPosition& refPos,
|
---|
229 | const casa::MEpoch& refEpoch,
|
---|
230 | casa::Bool perFreqID);
|
---|
231 |
|
---|
232 | // Generate data description table(combines source and freqID);
|
---|
233 | void generateDataDescTable(casa::Matrix<casa::uInt>& ddIdx,
|
---|
234 | SDDataDesc& dDesc,
|
---|
235 | casa::uInt nIF,
|
---|
236 | const SDMemTable& in,
|
---|
237 | const casa::Table& tabIn,
|
---|
238 | const casa::ROScalarColumn<casa::String>& srcCol,
|
---|
239 | const casa::ROArrayColumn<casa::uInt>& fqIDCol,
|
---|
240 | casa::Bool perFreqID);
|
---|
241 |
|
---|
242 | // Get row range from SDMemTable state
|
---|
243 | casa::Vector<casa::uInt> getRowRange(const SDMemTable& in) const;
|
---|
244 |
|
---|
245 | // Is row in the row range ?
|
---|
246 | casa::Bool rowInRange(casa::uInt i, const casa::Vector<casa::uInt>& range) const;
|
---|
247 |
|
---|
248 | // Set slice to cursor or all axes
|
---|
249 | void setCursorSlice(casa::IPosition& start, casa::IPosition& end,
|
---|
250 | casa::Bool doAll, const SDMemTable& in) const;
|
---|
251 |
|
---|
252 | // Function to normalize data when averaging in time
|
---|
253 |
|
---|
254 | void normalize(casa::MaskedArray<casa::Float>& data,
|
---|
255 | const casa::Array<casa::Float>& sumSq,
|
---|
256 | const casa::Array<casa::Float>& tSysSumSq,
|
---|
257 | const casa::Array<casa::Float>& nPts,
|
---|
258 | casa::Double intSum,
|
---|
259 | WeightType wtType, casa::Int axis, casa::Int nAxes);
|
---|
260 |
|
---|
261 | // Put the data and mask into the SDContainer
|
---|
262 | void putDataInSDC(SDContainer& sc, const casa::Array<casa::Float>& data,
|
---|
263 | const casa::Array<casa::Bool>& mask);
|
---|
264 |
|
---|
265 | // Read ascii file into a Table
|
---|
266 |
|
---|
267 | casa::Table readAsciiFile(const casa::String& fileName) const;
|
---|
268 |
|
---|
269 | }; // class
|
---|
270 |
|
---|
271 | } // namespace
|
---|
272 |
|
---|
273 | #endif
|
---|