| 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 | 
 | 
|---|
| 39 | class casa::Table;
 | 
|---|
| 40 | 
 | 
|---|
| 41 | namespace asap {
 | 
|---|
| 42 | 
 | 
|---|
| 43 | class SDMemTable;
 | 
|---|
| 44 | 
 | 
|---|
| 45 | class SDMath {
 | 
|---|
| 46 | 
 | 
|---|
| 47 |  public:
 | 
|---|
| 48 | 
 | 
|---|
| 49 | // Default constructor 
 | 
|---|
| 50 |    SDMath();
 | 
|---|
| 51 | 
 | 
|---|
| 52 | // Copy Constructor (copy semantics)
 | 
|---|
| 53 |    SDMath (const SDMath& other);
 | 
|---|
| 54 | 
 | 
|---|
| 55 | // Assignment  (copy semantics)
 | 
|---|
| 56 |    SDMath &operator=(const SDMath& other);
 | 
|---|
| 57 | 
 | 
|---|
| 58 | // Destructor
 | 
|---|
| 59 |    ~SDMath();
 | 
|---|
| 60 | 
 | 
|---|
| 61 | // Quotient
 | 
|---|
| 62 |    casa::CountedPtr<SDMemTable> quotient(const casa::CountedPtr<SDMemTable>& on, 
 | 
|---|
| 63 |                                          const casa::CountedPtr<SDMemTable>& off);
 | 
|---|
| 64 | 
 | 
|---|
| 65 | // Average in time
 | 
|---|
| 66 |    casa::CountedPtr<SDMemTable>  average(const casa::Block<casa::CountedPtr<SDMemTable> >& in,
 | 
|---|
| 67 |                                          const casa::Vector<casa::Bool>& mask,
 | 
|---|
| 68 |                                          casa::Bool scanAverage, const casa::String& weightStr);
 | 
|---|
| 69 | //                                         casa::Bool alignVelocity);
 | 
|---|
| 70 | 
 | 
|---|
| 71 | // Statistics
 | 
|---|
| 72 |    std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in, 
 | 
|---|
| 73 |                                 const std::vector<bool>& mask, const casa::String& which);
 | 
|---|
| 74 | 
 | 
|---|
| 75 | // Bin up spectra
 | 
|---|
| 76 |    SDMemTable* bin(const SDMemTable& in, casa::Int width);
 | 
|---|
| 77 | 
 | 
|---|
| 78 | // Smooth
 | 
|---|
| 79 |    SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel,
 | 
|---|
| 80 |                        casa::Float width, casa::Bool doAll);
 | 
|---|
| 81 | 
 | 
|---|
| 82 | // Flux conversion between Jansky and Kelvin
 | 
|---|
| 83 |    SDMemTable* convertFlux (const SDMemTable& in, casa::Float area, 
 | 
|---|
| 84 |                             casa::Float eta, casa::Bool doAll);
 | 
|---|
| 85 | 
 | 
|---|
| 86 | // Gain-elevation correction
 | 
|---|
| 87 |    SDMemTable* gainElevation (const SDMemTable& in, const casa::String& fileName,
 | 
|---|
| 88 |                               const casa::String& method, casa::Bool doAll);
 | 
|---|
| 89 | 
 | 
|---|
| 90 | // Simple mathematical operations.  what=0 (mul) or 1 (add)
 | 
|---|
| 91 |    SDMemTable* simpleOperate(const SDMemTable& in, casa::Float offset, 
 | 
|---|
| 92 |                              casa::Bool doAll, casa::uInt what);
 | 
|---|
| 93 | 
 | 
|---|
| 94 | // Average polarizations
 | 
|---|
| 95 |    SDMemTable* averagePol(const SDMemTable& in, const casa::Vector<casa::Bool>& mask);
 | 
|---|
| 96 | 
 | 
|---|
| 97 |  private:
 | 
|---|
| 98 | 
 | 
|---|
| 99 | // Weighting type for time averaging
 | 
|---|
| 100 | 
 | 
|---|
| 101 |   enum WeightType {NONE,VAR,TSYS};
 | 
|---|
| 102 | 
 | 
|---|
| 103 | // Function to use accumulate data during time averaging
 | 
|---|
| 104 | 
 | 
|---|
| 105 |   void accumulate (casa::Double& timeSum, casa::Double& intSum, casa::Int& nAccum,
 | 
|---|
| 106 |                    casa::MaskedArray<casa::Float>& sum, casa::Array<casa::Float>& sumSq,
 | 
|---|
| 107 |                    casa::Array<casa::Float>& nPts, casa::Array<casa::Float>& tSysSum,
 | 
|---|
| 108 |                    const casa::Array<casa::Float>& tSys,  const casa::Array<casa::Float>& nInc,
 | 
|---|
| 109 |                    const casa::Vector<casa::Bool>& mask, casa::Double time, casa::Double interval,
 | 
|---|
| 110 |                    const casa::Block<casa::CountedPtr<SDMemTable> >& in,
 | 
|---|
| 111 |                    casa::uInt iTab, casa::uInt iRow, casa::uInt axis, casa::uInt nAxesSub,
 | 
|---|
| 112 |                    casa::Bool useMask, WeightType wtType) const;
 | 
|---|
| 113 | 
 | 
|---|
| 114 | // Function to fill Scan Container when averaging in time
 | 
|---|
| 115 | 
 | 
|---|
| 116 |   void fillSDC (SDContainer& sc, const casa::Array<casa::Bool>& mask,
 | 
|---|
| 117 |                 const casa::Array<casa::Float>& data,
 | 
|---|
| 118 |                 const casa::Array<casa::Float>& tSys,
 | 
|---|
| 119 |                 casa::Int scanID, casa::Double timeStamp,
 | 
|---|
| 120 |                 casa::Double interval, const casa::String& sourceName,
 | 
|---|
| 121 |                 const casa::Vector<casa::uInt>& freqID) const;
 | 
|---|
| 122 | 
 | 
|---|
| 123 | // Put the data and mask into the SDContainer
 | 
|---|
| 124 |    void putDataInSDC (SDContainer& sc, const casa::Array<casa::Float>& data,
 | 
|---|
| 125 |                       const casa::Array<casa::Bool>& mask) const;
 | 
|---|
| 126 | 
 | 
|---|
| 127 | // Function to normalize data when averaging in time
 | 
|---|
| 128 | 
 | 
|---|
| 129 |   void normalize (casa::MaskedArray<casa::Float>& data,
 | 
|---|
| 130 |                   const casa::Array<casa::Float>& sumSq,
 | 
|---|
| 131 |                   const casa::Array<casa::Float>& nPts,
 | 
|---|
| 132 |                   WeightType wtType, casa::Int axis, casa::Int nAxes) const;
 | 
|---|
| 133 | 
 | 
|---|
| 134 | // Function to get the current cursor location
 | 
|---|
| 135 |    void getCursorLocation (casa::IPosition& start, casa::IPosition& end,
 | 
|---|
| 136 |                            const SDMemTable& in) const;
 | 
|---|
| 137 | 
 | 
|---|
| 138 | // Convert weight string to enum value
 | 
|---|
| 139 | 
 | 
|---|
| 140 |    void convertWeightString (WeightType& wt, const casa::String& weightStr) const;
 | 
|---|
| 141 | 
 | 
|---|
| 142 | // Convert interpolation type string
 | 
|---|
| 143 |    void convertInterpString(casa::Int& type, const casa::String& interp) const;
 | 
|---|
| 144 | 
 | 
|---|
| 145 | // Read ascii file
 | 
|---|
| 146 | 
 | 
|---|
| 147 |    casa::Table readAsciiFile (const casa::String& fileName) const;
 | 
|---|
| 148 |                    
 | 
|---|
| 149 | };
 | 
|---|
| 150 | 
 | 
|---|
| 151 | } // namespace
 | 
|---|
| 152 | 
 | 
|---|
| 153 | #endif
 | 
|---|