source: branches/Release-2-fixes/src/SDMath.h@ 1123

Last change on this file since 1123 was 699, checked in by mar637, 19 years ago

whitespace tidy

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