source: trunk/src/SDMath.h@ 740

Last change on this file since 740 was 716, checked in by mar637, 19 years ago

added frequency switching; implemented use of SDLog

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 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#include "SDLog.h"
42
43class casa::Table;
44class casa::MEpoch;
45class casa::MPosition;
46template<class T> class casa::PtrBlock;
47template<class T> class casa::Matrix;
48template<class T> class casa::ROScalarColumn;
49template<class T> class casa::ROArrayColumn;
50
51namespace asap {
52
53class SDMemTable;
54class SDDataDesc;
55
56class SDMath : private SDLog {
57
58public:
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
140 private:
141
142// Weighting type for time averaging
143
144 enum WeightType {NONE=0,VAR,TSYS,TINT,TINTSYS,nWeightTypes};
145
146// Function to use accumulate data during time averaging
147
148 void accumulate(casa::Double& timeSum, casa::Double& intSum,
149 casa::Int& nAccum,
150 casa::MaskedArray<casa::Float>& sum,
151 casa::Array<casa::Float>& sumSq,
152 casa::Array<casa::Float>& nPts,
153 casa::Array<casa::Float>& tSysSum,
154 casa::Array<casa::Float>& tSysSqSum,
155 const casa::Array<casa::Float>& tSys,
156 const casa::Array<casa::Float>& nInc,
157 const casa::Vector<casa::Bool>& mask,
158 casa::Double time, casa::Double interval,
159 const std::vector<casa::CountedPtr<SDMemTable> >& in,
160 casa::uInt iTab, casa::uInt iRow,
161 casa::uInt axis, casa::uInt nAxesSub,
162 casa::Bool useMask, WeightType wtType);
163
164// Work out conversion factor for converting Jy<->K per IF per row and apply
165 void convertBrightnessUnits(SDMemTable* pTabOut, const SDMemTable& in,
166 casa::Bool toKelvin, casa::Float sFac, casa::Bool doAll);
167
168// Convert weight string to enum value
169
170 void convertWeightString(WeightType& wt, const casa::String& weightStr,
171 casa::Bool listType);;
172
173// Convert interpolation type string
174// void convertInterpString(casa::Int& type, const casa::String& interp);
175 void convertInterpString(casa::InterpolateArray1D<casa::Double,casa::Float>::InterpolationMethod& method,
176 const casa::String& interp);
177
178// Scale data with values from an ascii Table
179 void scaleFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in,
180 const casa::String& fileName,
181 const casa::String& col0, const casa::String& col1,
182 const casa::String& methodStr, casa::Bool doAll,
183 const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
184
185// Scale data with values from a Table
186 void scaleFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable,
187 const casa::String& col0, const casa::String& col1,
188 const casa::String& methodStr, casa::Bool doAll,
189 const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
190
191// Scale data and optionally TSys by values in a Vector
192 void scaleByVector(SDMemTable* pTabOut, const SDMemTable& in,
193 casa::Bool doAll, const casa::Vector<casa::Float>& factor,
194 casa::Bool doTSys);
195
196// Convert time String to Epoch
197 casa::MEpoch epochFromString(const casa::String& str, casa::MEpoch::Types timeRef);
198
199// Function to fill Scan Container when averaging in time
200
201 void fillSDC(SDContainer& sc, const casa::Array<casa::Bool>& mask,
202 const casa::Array<casa::Float>& data,
203 const casa::Array<casa::Float>& tSys,
204 casa::Int scanID, casa::Double timeStamp,
205 casa::Double interval, const casa::String& sourceName,
206 const casa::Vector<casa::uInt>& freqID);
207
208// Format EPoch
209 casa::String formatEpoch(const casa::MEpoch& epoch) const;
210
211// Align in Frequency
212 SDMemTable* frequencyAlign(const SDMemTable& in,
213 casa::MFrequency::Types system,
214 const casa::String& timeRef,
215 const casa::String& method,
216 casa::Bool perIF);
217
218// Generate frequency aligners
219 void generateFrequencyAligners(casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a,
220 const SDDataDesc& dDesc,
221 const SDMemTable& in, casa::uInt nChan,
222 casa::MFrequency::Types system,
223 const casa::MPosition& refPos,
224 const casa::MEpoch& refEpoch,
225 casa::Bool perFreqID);
226
227// Generate data description table(combines source and freqID);
228 void generateDataDescTable(casa::Matrix<casa::uInt>& ddIdx,
229 SDDataDesc& dDesc,
230 casa::uInt nIF,
231 const SDMemTable& in,
232 const casa::Table& tabIn,
233 const casa::ROScalarColumn<casa::String>& srcCol,
234 const casa::ROArrayColumn<casa::uInt>& fqIDCol,
235 casa::Bool perFreqID);
236
237// Get row range from SDMemTable state
238 casa::Vector<casa::uInt> getRowRange(const SDMemTable& in) const;
239
240// Is row in the row range ?
241 casa::Bool rowInRange(casa::uInt i, const casa::Vector<casa::uInt>& range) const;
242
243// Set slice to cursor or all axes
244 void setCursorSlice(casa::IPosition& start, casa::IPosition& end,
245 casa::Bool doAll, const SDMemTable& in) const;
246
247// Function to normalize data when averaging in time
248
249 void normalize(casa::MaskedArray<casa::Float>& data,
250 const casa::Array<casa::Float>& sumSq,
251 const casa::Array<casa::Float>& tSysSumSq,
252 const casa::Array<casa::Float>& nPts,
253 casa::Double intSum,
254 WeightType wtType, casa::Int axis, casa::Int nAxes);
255
256// Put the data and mask into the SDContainer
257 void putDataInSDC(SDContainer& sc, const casa::Array<casa::Float>& data,
258 const casa::Array<casa::Bool>& mask);
259
260// Read ascii file into a Table
261
262 casa::Table readAsciiFile(const casa::String& fileName) const;
263
264}; // class
265
266} // namespace
267
268#endif
Note: See TracBrowser for help on using the repository browser.