source: branches/Release12/src/SDMath.h@ 1224

Last change on this file since 1224 was 798, checked in by phi196, 19 years ago

Added swap_pol & invert_phase

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
RevLine 
[2]1//#---------------------------------------------------------------------------
2//# SDMath.h: A collection of single dish mathematical operations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
[125]5//# ATNF
[2]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//#---------------------------------------------------------------------------
[125]31#ifndef SDMATH_H
32#define SDMATH_H
[2]33
[38]34#include <string>
35#include <vector>
[130]36#include <casa/aips.h>
[81]37#include <casa/Utilities/CountedPtr.h>
[309]38#include <coordinates/Coordinates/FrequencyAligner.h>
[294]39
[234]40#include "SDDefs.h"
[716]41#include "SDLog.h"
[2]42
[227]43class casa::Table;
[272]44class casa::MEpoch;
[294]45class casa::MPosition;
46template<class T> class casa::PtrBlock;
[330]47template<class T> class casa::Matrix;
48template<class T> class casa::ROScalarColumn;
49template<class T> class casa::ROArrayColumn;
[227]50
[83]51namespace asap {
[2]52
53class SDMemTable;
[330]54class SDDataDesc;
[716]55
56class SDMath : private SDLog {
[2]57
[716]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
[171]91// Bin up spectra
[716]92 SDMemTable* bin(const SDMemTable& in, casa::Int width);
[171]93
[716]94 // Resample spectra
[299]95 SDMemTable* resample(const SDMemTable& in, const casa::String& method,
[716]96 casa::Float factor);
[299]97
[177]98// Smooth
[716]99 SDMemTable* smooth(const SDMemTable& in, const casa::String& kernel,
100 casa::Float width, casa::Bool doAll);
[177]101
[221]102// Flux conversion between Jansky and Kelvin
[716]103 SDMemTable* convertFlux(const SDMemTable& in, casa::Float D,
104 casa::Float etaAp,
105 casa::Float JyPerK, casa::Bool doAll);
[221]106
[227]107// Gain-elevation correction
[716]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);
[227]113
[309]114// Frequency Alignment
[716]115 SDMemTable* frequencyAlignment(const SDMemTable& in, const casa::String& refTime,
116 const casa::String& method, casa::Bool perFreqID);
[262]117
[234]118// Opacity correction
[716]119 SDMemTable* opacity(const SDMemTable& in, casa::Float tau, casa::Bool doAll);
[234]120
[248]121// Simple unary mathematical operations. what=0 (mul) or 1 (add)
122 SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset,
[716]123 casa::Bool doAll, casa::uInt what, casa::Bool tSys);
[169]124
[716]125 // Average polarizations.
126 SDMemTable* averagePol(const SDMemTable& in,
127 const casa::Vector<casa::Bool>& mask,
128 const casa::String& wtStr);
[169]129
[716]130 SDMemTable* frequencySwitch(const SDMemTable& in);
131
132
[502]133// Rotate XY phase. Value in degrees.
[716]134 void rotateXYPhase(SDMemTable& in, casa::Float value, casa::Bool doAll);
[457]135
[502]136// Rotate Q & U by operating on the raw correlations.Value in degrees.
[716]137 void rotateLinPolPhase(SDMemTable& in, casa::Float value, casa::Bool doAll);
[457]138
[798]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);
[716]144
[170]145 private:
[169]146
[152]147// Weighting type for time averaging
148
[536]149 enum WeightType {NONE=0,VAR,TSYS,TINT,TINTSYS,nWeightTypes};
[144]150
[152]151// Function to use accumulate data during time averaging
152
[653]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,
[716]167 casa::Bool useMask, WeightType wtType);
[146]168
[354]169// Work out conversion factor for converting Jy<->K per IF per row and apply
[716]170 void convertBrightnessUnits(SDMemTable* pTabOut, const SDMemTable& in,
171 casa::Bool toKelvin, casa::Float sFac, casa::Bool doAll);
[152]172
[162]173// Convert weight string to enum value
174
[716]175 void convertWeightString(WeightType& wt, const casa::String& weightStr,
176 casa::Bool listType);;
[227]177
178// Convert interpolation type string
[716]179// void convertInterpString(casa::Int& type, const casa::String& interp);
[317]180 void convertInterpString(casa::InterpolateArray1D<casa::Double,casa::Float>::InterpolationMethod& method,
[716]181 const casa::String& interp);
[227]182
[480]183// Scale data with values from an ascii Table
184 void scaleFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in,
[234]185 const casa::String& fileName,
186 const casa::String& col0, const casa::String& col1,
187 const casa::String& methodStr, casa::Bool doAll,
[716]188 const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
[230]189
[480]190// Scale data with values from a Table
191 void scaleFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable,
[234]192 const casa::String& col0, const casa::String& col1,
193 const casa::String& methodStr, casa::Bool doAll,
[716]194 const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
[230]195
[480]196// Scale data and optionally TSys by values in a Vector
[716]197 void scaleByVector(SDMemTable* pTabOut, const SDMemTable& in,
[480]198 casa::Bool doAll, const casa::Vector<casa::Float>& factor,
[716]199 casa::Bool doTSys);
[234]200
[354]201// Convert time String to Epoch
[716]202 casa::MEpoch epochFromString(const casa::String& str, casa::MEpoch::Types timeRef);
[234]203
[354]204// Function to fill Scan Container when averaging in time
[234]205
[716]206 void fillSDC(SDContainer& sc, const casa::Array<casa::Bool>& mask,
[354]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,
[716]211 const casa::Vector<casa::uInt>& freqID);
[354]212
213// Format EPoch
[716]214 casa::String formatEpoch(const casa::MEpoch& epoch) const;
[354]215
216// Align in Frequency
[716]217 SDMemTable* frequencyAlign(const SDMemTable& in,
[354]218 casa::MFrequency::Types system,
219 const casa::String& timeRef,
[653]220 const casa::String& method,
[716]221 casa::Bool perIF);
[354]222
[309]223// Generate frequency aligners
[716]224 void generateFrequencyAligners(casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a,
[330]225 const SDDataDesc& dDesc,
[309]226 const SDMemTable& in, casa::uInt nChan,
227 casa::MFrequency::Types system,
228 const casa::MPosition& refPos,
[653]229 const casa::MEpoch& refEpoch,
[716]230 casa::Bool perFreqID);
[294]231
[716]232// Generate data description table(combines source and freqID);
233 void generateDataDescTable(casa::Matrix<casa::uInt>& ddIdx,
[330]234 SDDataDesc& dDesc,
235 casa::uInt nIF,
236 const SDMemTable& in,
237 const casa::Table& tabIn,
238 const casa::ROScalarColumn<casa::String>& srcCol,
[397]239 const casa::ROArrayColumn<casa::uInt>& fqIDCol,
[716]240 casa::Bool perFreqID);
[330]241
[480]242// Get row range from SDMemTable state
[716]243 casa::Vector<casa::uInt> getRowRange(const SDMemTable& in) const;
[480]244
245// Is row in the row range ?
[716]246 casa::Bool rowInRange(casa::uInt i, const casa::Vector<casa::uInt>& range) const;
[480]247
[434]248// Set slice to cursor or all axes
[716]249 void setCursorSlice(casa::IPosition& start, casa::IPosition& end,
250 casa::Bool doAll, const SDMemTable& in) const;
[272]251
[354]252// Function to normalize data when averaging in time
[272]253
[716]254 void normalize(casa::MaskedArray<casa::Float>& data,
[354]255 const casa::Array<casa::Float>& sumSq,
[518]256 const casa::Array<casa::Float>& tSysSumSq,
[354]257 const casa::Array<casa::Float>& nPts,
[518]258 casa::Double intSum,
[716]259 WeightType wtType, casa::Int axis, casa::Int nAxes);
[354]260
261// Put the data and mask into the SDContainer
[716]262 void putDataInSDC(SDContainer& sc, const casa::Array<casa::Float>& data,
263 const casa::Array<casa::Bool>& mask);
[354]264
265// Read ascii file into a Table
266
[716]267 casa::Table readAsciiFile(const casa::String& fileName) const;
[146]268
[716]269}; // class
[330]270
[165]271} // namespace
[146]272
[165]273#endif
Note: See TracBrowser for help on using the repository browser.