source: trunk/src/SDMath.h@ 295

Last change on this file since 295 was 294, checked in by kil064, 20 years ago

move some code into function generateVelocityAligners
add arg. doTSys to binaryOperate and unaryOperate

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 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/VelocityAligner.h>
39
40#include "SDDefs.h"
41
42class casa::Table;
43class casa::MEpoch;
44class casa::MPosition;
45template<class T> class casa::PtrBlock;
46//template<class T> class casa::VelocityAligner;
47
48
49namespace asap {
50
51class SDMemTable;
52
53class SDMath {
54
55 public:
56
57// Default constructor
58 SDMath();
59
60// Copy Constructor (copy semantics)
61 SDMath (const SDMath& other);
62
63// Assignment (copy semantics)
64 SDMath &operator=(const SDMath& other);
65
66// Destructor
67 ~SDMath();
68
69// Binary Table operators. op=ADD, SUB, MUL, DIV, QUOTIENT
70 casa::CountedPtr<SDMemTable> binaryOperate (const casa::CountedPtr<SDMemTable>& left,
71 const casa::CountedPtr<SDMemTable>& right,
72 const casa::String& op, casa::Bool preserve,
73 casa::Bool tSys) const;
74
75// Average in time
76 casa::CountedPtr<SDMemTable> average(const casa::Block<casa::CountedPtr<SDMemTable> >& in,
77 const casa::Vector<casa::Bool>& mask,
78 casa::Bool scanAverage,
79 const casa::String& weightStr,
80 casa::Bool alignVelocity=casa::False) const;
81
82// Statistics. If row<0, all rows are done otherwise, just the
83// specified row.
84 std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in,
85 const casa::Vector<casa::Bool>& mask,
86 const casa::String& which, casa::Int row) const;
87
88// Bin up spectra
89 SDMemTable* bin(const SDMemTable& in, casa::Int width) const;
90
91// Smooth
92 SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel,
93 casa::Float width, casa::Bool doAll) const;
94
95// Flux conversion between Jansky and Kelvin
96 SDMemTable* convertFlux (const SDMemTable& in, casa::Float area,
97 casa::Float eta, casa::Bool doAll) const;
98
99// Gain-elevation correction
100 SDMemTable* gainElevation (const SDMemTable& in, const casa::Vector<casa::Float>& coeffs,
101 const casa::String& fileName,
102 const casa::String& method, casa::Bool doAll) const;
103
104// Velocity Alignment
105 SDMemTable* velocityAlignment (const SDMemTable& in, const casa::String& refTime) const;
106
107// Opacity correction
108 SDMemTable* opacity (const SDMemTable& in, casa::Float tau, casa::Bool doAll) const;
109
110// Simple unary mathematical operations. what=0 (mul) or 1 (add)
111 SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset,
112 casa::Bool doAll, casa::uInt what, casa::Bool tSys) const;
113
114// Average polarizations
115 SDMemTable* averagePol(const SDMemTable& in, const casa::Vector<casa::Bool>& mask) const;
116
117 private:
118
119// Weighting type for time averaging
120
121 enum WeightType {NONE,VAR,TSYS};
122
123// Function to use accumulate data during time averaging
124
125 void accumulate (casa::Double& timeSum, casa::Double& intSum, casa::Int& nAccum,
126 casa::MaskedArray<casa::Float>& sum, casa::Array<casa::Float>& sumSq,
127 casa::Array<casa::Float>& nPts, casa::Array<casa::Float>& tSysSum,
128 const casa::Array<casa::Float>& tSys, const casa::Array<casa::Float>& nInc,
129 const casa::Vector<casa::Bool>& mask, casa::Double time, casa::Double interval,
130 const casa::Block<casa::CountedPtr<SDMemTable> >& in,
131 casa::uInt iTab, casa::uInt iRow, casa::uInt axis, casa::uInt nAxesSub,
132 casa::Bool useMask, WeightType wtType) const;
133
134// Function to fill Scan Container when averaging in time
135
136 void fillSDC (SDContainer& sc, const casa::Array<casa::Bool>& mask,
137 const casa::Array<casa::Float>& data,
138 const casa::Array<casa::Float>& tSys,
139 casa::Int scanID, casa::Double timeStamp,
140 casa::Double interval, const casa::String& sourceName,
141 const casa::Vector<casa::uInt>& freqID) const;
142
143// Put the data and mask into the SDContainer
144 void putDataInSDC (SDContainer& sc, const casa::Array<casa::Float>& data,
145 const casa::Array<casa::Bool>& mask) const;
146
147// Function to normalize data when averaging in time
148
149 void normalize (casa::MaskedArray<casa::Float>& data,
150 const casa::Array<casa::Float>& sumSq,
151 const casa::Array<casa::Float>& nPts,
152 WeightType wtType, casa::Int axis, casa::Int nAxes) const;
153
154// Function to get the current cursor location
155 void getCursorLocation (casa::IPosition& start, casa::IPosition& end,
156 const SDMemTable& in) const;
157
158// Convert weight string to enum value
159
160 void convertWeightString (WeightType& wt, const casa::String& weightStr) const;
161
162// Convert interpolation type string
163 void convertInterpString(casa::Int& type, const casa::String& interp) const;
164
165// Correct data from an ascii Table
166 void correctFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in,
167 const casa::String& fileName,
168 const casa::String& col0, const casa::String& col1,
169 const casa::String& methodStr, casa::Bool doAll,
170 const casa::Vector<casa::Float>& xOut) const;
171
172// Correct data from a Table
173 void correctFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable,
174 const casa::String& col0, const casa::String& col1,
175 const casa::String& methodStr, casa::Bool doAll,
176 const casa::Vector<casa::Float>& xOut) const;
177
178// Correct data from a Vector
179 void correctFromVector (SDMemTable* pTabOut, const SDMemTable& in,
180 casa::Bool doAll, const casa::Vector<casa::Float>& factor) const;
181
182// Read ascii file into a Table
183
184 casa::Table readAsciiFile (const casa::String& fileName) const;
185
186// Generate source table
187 void generateSourceTable (casa::Vector<casa::String>& srcTab,
188 casa::Vector<casa::uInt>& srcIdx,
189 casa::Vector<casa::uInt>& firstRow,
190 const casa::Vector<casa::String>& srcNames) const;
191
192// Generate velocity aligners
193 void generateVelocityAligners (casa::PtrBlock<casa::VelocityAligner<casa::Float>* >& vA,
194 const SDMemTable& in, casa::uInt nChan,
195 casa::uInt nFreqIDs, casa::uInt nSrcTab,
196 const casa::Vector<casa::uInt>& firstRow,
197 casa::MFrequency::Types velSystem,
198 const casa::String& velUnit,
199 casa::MDoppler::Types doppler,
200 const casa::MPosition& refPos,
201 const casa::MEpoch& refEpoch) const;
202
203// Align in Velocity
204 SDMemTable* velocityAlign (const SDMemTable& in,
205 casa::MFrequency::Types velSystem,
206 const casa::String& velUnit,
207 casa::MDoppler::Types doppler,
208 const casa::String& timeRef) const;
209
210// Convert time String to Epoch
211 casa::MEpoch epochFromString (const casa::String& str, casa::MEpoch::Types timeRef) const;
212
213// Format EPoch
214 casa::String formatEpoch(const casa::MEpoch& epoch) const;
215};
216
217} // namespace
218
219#endif
Note: See TracBrowser for help on using the repository browser.