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