[2] | 1 | //#---------------------------------------------------------------------------
|
---|
| 2 | //# SDMath.cc: A collection of single dish mathematical operations
|
---|
| 3 | //#---------------------------------------------------------------------------
|
---|
| 4 | //# Copyright (C) 2004
|
---|
| 5 | //# Malte Marquarding, 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 | #include <aips/aips.h>
|
---|
| 32 | #include <aips/Utilities/String.h>
|
---|
| 33 | #include <aips/Arrays/IPosition.h>
|
---|
| 34 | #include <aips/Arrays/Array.h>
|
---|
| 35 | #include <aips/Arrays/ArrayMath.h>
|
---|
| 36 | #include <aips/Arrays/ArrayLogical.h>
|
---|
| 37 | #include <aips/Arrays/MaskedArray.h>
|
---|
| 38 | #include <aips/Arrays/MaskArrMath.h>
|
---|
| 39 | #include <aips/Arrays/MaskArrLogi.h>
|
---|
| 40 |
|
---|
| 41 | #include <aips/Tables/Table.h>
|
---|
| 42 | #include <aips/Tables/ScalarColumn.h>
|
---|
| 43 | #include <aips/Tables/ArrayColumn.h>
|
---|
| 44 |
|
---|
| 45 | #include "SDContainer.h"
|
---|
| 46 | #include "SDMemTable.h"
|
---|
| 47 |
|
---|
| 48 | #include "SDMath.h"
|
---|
| 49 |
|
---|
| 50 | using namespace atnf_sd;
|
---|
| 51 |
|
---|
| 52 | static CountedPtr<SDMemTable> SDMath::average(const CountedPtr<SDMemTable>& in) {
|
---|
| 53 | Table t = in->table();
|
---|
| 54 | ROArrayColumn<Float> tsys(t, "TSYS");
|
---|
| 55 | ROScalarColumn<Double> mjd(t, "TIME");
|
---|
| 56 | ROScalarColumn<String> srcn(t, "SRCNAME");
|
---|
| 57 | IPosition ip = in->rowAsMaskedArray(0).shape();
|
---|
| 58 | Array<Float> outarr(ip); outarr =0.0;
|
---|
| 59 | Array<Float> narr(ip);narr = 0.0;
|
---|
| 60 | Array<Float> narrinc(ip);narrinc = 1.0;
|
---|
| 61 |
|
---|
| 62 | Array<Float> tsarr(tsys.shape(0));
|
---|
| 63 | Array<Float> outtsarr(tsys.shape(0));
|
---|
| 64 | Double tme = 0.0;
|
---|
| 65 |
|
---|
| 66 | for (uInt i=0; i < t.nrow(); i++) {
|
---|
| 67 | // data stuff
|
---|
| 68 | MaskedArray<Float> marr(in->rowAsMaskedArray(i));
|
---|
| 69 | outarr += marr;
|
---|
| 70 | MaskedArray<Float> n(narrinc,marr.getMask());
|
---|
| 71 | narr += n;
|
---|
| 72 | // get
|
---|
| 73 | tsys.get(i, tsarr);// this is probably unneccessary as tsys should
|
---|
| 74 | outtsarr += tsarr; // be constant
|
---|
| 75 | Double tmp;
|
---|
| 76 | mjd.get(i,tmp);
|
---|
| 77 | tme += tmp;// average time
|
---|
| 78 | }
|
---|
| 79 | // averaging using mask
|
---|
| 80 | MaskedArray<Float> nma (narr,(narr > Float(0)));
|
---|
| 81 | outarr /= nma;
|
---|
| 82 |
|
---|
| 83 | SDContainer sc(ip(0),ip(1),ip(2),ip(3));
|
---|
| 84 |
|
---|
| 85 | Int n = t.nrow();
|
---|
| 86 | outtsarr /= Float(n/2);
|
---|
| 87 | sc.timestamp = tme/Double(n/2);
|
---|
| 88 |
|
---|
| 89 | String tstr; srcn.getScalar(n,tstr);// get sourcename of "mid" point
|
---|
| 90 | sc.sourcename = tstr;
|
---|
| 91 | sc.putSpectrum(outarr);
|
---|
| 92 | //sc.putFlags(outflags);
|
---|
| 93 | SDMemTable* sdmt = new SDMemTable(*in);
|
---|
| 94 | sdmt->putSDContainer(sc);
|
---|
| 95 | return CountedPtr<SDMemTable>(sdmt);
|
---|
| 96 | }
|
---|