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