source: trunk/src/SDMath.h@ 742

Last change on this file since 742 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
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
[716]139
[170]140 private:
[169]141
[152]142// Weighting type for time averaging
143
[536]144 enum WeightType {NONE=0,VAR,TSYS,TINT,TINTSYS,nWeightTypes};
[144]145
[152]146// Function to use accumulate data during time averaging
147
[653]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,
[716]162 casa::Bool useMask, WeightType wtType);
[146]163
[354]164// Work out conversion factor for converting Jy<->K per IF per row and apply
[716]165 void convertBrightnessUnits(SDMemTable* pTabOut, const SDMemTable& in,
166 casa::Bool toKelvin, casa::Float sFac, casa::Bool doAll);
[152]167
[162]168// Convert weight string to enum value
169
[716]170 void convertWeightString(WeightType& wt, const casa::String& weightStr,
171 casa::Bool listType);;
[227]172
173// Convert interpolation type string
[716]174// void convertInterpString(casa::Int& type, const casa::String& interp);
[317]175 void convertInterpString(casa::InterpolateArray1D<casa::Double,casa::Float>::InterpolationMethod& method,
[716]176 const casa::String& interp);
[227]177
[480]178// Scale data with values from an ascii Table
179 void scaleFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in,
[234]180 const casa::String& fileName,
181 const casa::String& col0, const casa::String& col1,
182 const casa::String& methodStr, casa::Bool doAll,
[716]183 const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
[230]184
[480]185// Scale data with values from a Table
186 void scaleFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable,
[234]187 const casa::String& col0, const casa::String& col1,
188 const casa::String& methodStr, casa::Bool doAll,
[716]189 const casa::Vector<casa::Float>& xOut, casa::Bool doTSys);
[230]190
[480]191// Scale data and optionally TSys by values in a Vector
[716]192 void scaleByVector(SDMemTable* pTabOut, const SDMemTable& in,
[480]193 casa::Bool doAll, const casa::Vector<casa::Float>& factor,
[716]194 casa::Bool doTSys);
[234]195
[354]196// Convert time String to Epoch
[716]197 casa::MEpoch epochFromString(const casa::String& str, casa::MEpoch::Types timeRef);
[234]198
[354]199// Function to fill Scan Container when averaging in time
[234]200
[716]201 void fillSDC(SDContainer& sc, const casa::Array<casa::Bool>& mask,
[354]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,
[716]206 const casa::Vector<casa::uInt>& freqID);
[354]207
208// Format EPoch
[716]209 casa::String formatEpoch(const casa::MEpoch& epoch) const;
[354]210
211// Align in Frequency
[716]212 SDMemTable* frequencyAlign(const SDMemTable& in,
[354]213 casa::MFrequency::Types system,
214 const casa::String& timeRef,
[653]215 const casa::String& method,
[716]216 casa::Bool perIF);
[354]217
[309]218// Generate frequency aligners
[716]219 void generateFrequencyAligners(casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a,
[330]220 const SDDataDesc& dDesc,
[309]221 const SDMemTable& in, casa::uInt nChan,
222 casa::MFrequency::Types system,
223 const casa::MPosition& refPos,
[653]224 const casa::MEpoch& refEpoch,
[716]225 casa::Bool perFreqID);
[294]226
[716]227// Generate data description table(combines source and freqID);
228 void generateDataDescTable(casa::Matrix<casa::uInt>& ddIdx,
[330]229 SDDataDesc& dDesc,
230 casa::uInt nIF,
231 const SDMemTable& in,
232 const casa::Table& tabIn,
233 const casa::ROScalarColumn<casa::String>& srcCol,
[397]234 const casa::ROArrayColumn<casa::uInt>& fqIDCol,
[716]235 casa::Bool perFreqID);
[330]236
[480]237// Get row range from SDMemTable state
[716]238 casa::Vector<casa::uInt> getRowRange(const SDMemTable& in) const;
[480]239
240// Is row in the row range ?
[716]241 casa::Bool rowInRange(casa::uInt i, const casa::Vector<casa::uInt>& range) const;
[480]242
[434]243// Set slice to cursor or all axes
[716]244 void setCursorSlice(casa::IPosition& start, casa::IPosition& end,
245 casa::Bool doAll, const SDMemTable& in) const;
[272]246
[354]247// Function to normalize data when averaging in time
[272]248
[716]249 void normalize(casa::MaskedArray<casa::Float>& data,
[354]250 const casa::Array<casa::Float>& sumSq,
[518]251 const casa::Array<casa::Float>& tSysSumSq,
[354]252 const casa::Array<casa::Float>& nPts,
[518]253 casa::Double intSum,
[716]254 WeightType wtType, casa::Int axis, casa::Int nAxes);
[354]255
256// Put the data and mask into the SDContainer
[716]257 void putDataInSDC(SDContainer& sc, const casa::Array<casa::Float>& data,
258 const casa::Array<casa::Bool>& mask);
[354]259
260// Read ascii file into a Table
261
[716]262 casa::Table readAsciiFile(const casa::String& fileName) const;
[146]263
[716]264}; // class
[330]265
[165]266} // namespace
[146]267
[165]268#endif
Note: See TracBrowser for help on using the repository browser.