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