[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
|
---|
[9] | 80 | MaskedArray<Float> nma(narr,(narr > Float(0)));
|
---|
[2] | 81 | outarr /= nma;
|
---|
[9] | 82 | Array<Bool> outflagsb = !(nma.getMask());
|
---|
| 83 | Array<uChar> outflags(outflagsb.shape());
|
---|
| 84 | convertArray(outflags,outflagsb);
|
---|
[2] | 85 | SDContainer sc(ip(0),ip(1),ip(2),ip(3));
|
---|
| 86 |
|
---|
| 87 | Int n = t.nrow();
|
---|
| 88 | outtsarr /= Float(n/2);
|
---|
| 89 | sc.timestamp = tme/Double(n/2);
|
---|
| 90 |
|
---|
| 91 | String tstr; srcn.getScalar(n,tstr);// get sourcename of "mid" point
|
---|
| 92 | sc.sourcename = tstr;
|
---|
| 93 | sc.putSpectrum(outarr);
|
---|
[9] | 94 | sc.putFlags(outflags);
|
---|
[2] | 95 | SDMemTable* sdmt = new SDMemTable(*in);
|
---|
| 96 | sdmt->putSDContainer(sc);
|
---|
| 97 | return CountedPtr<SDMemTable>(sdmt);
|
---|
| 98 | }
|
---|
[9] | 99 |
|
---|
| 100 | static CountedPtr<SDMemTable>
|
---|
| 101 | SDMath::quotient(const CountedPtr<SDMemTable>& on,
|
---|
| 102 | const CountedPtr<SDMemTable>& off) {
|
---|
| 103 |
|
---|
| 104 | Table ton = on->table();
|
---|
| 105 | Table toff = off->table();
|
---|
| 106 | ROArrayColumn<Float> tsys(ton, "TSYS");
|
---|
| 107 |
|
---|
| 108 | ROScalarColumn<Double> mjd(ton, "TIME");
|
---|
| 109 | ROScalarColumn<String> srcn(ton, "SRCNAME");
|
---|
| 110 | MaskedArray<Float> mon(on->rowAsMaskedArray(0));
|
---|
| 111 | MaskedArray<Float> moff(off->rowAsMaskedArray(0));
|
---|
| 112 | IPosition ipon = mon.shape();
|
---|
| 113 | IPosition ipoff = moff.shape();
|
---|
| 114 | Array<Float> tsarr(tsys.shape(0));
|
---|
| 115 |
|
---|
| 116 | if (ipon != ipoff && ipon != tsarr.shape())
|
---|
| 117 | cerr << "on/off not conformant" << endl;
|
---|
| 118 |
|
---|
| 119 | //IPosition test = mon.shape()/2;
|
---|
| 120 | MaskedArray<Float> tmp = (mon-moff);
|
---|
| 121 | Array<Float> out(tmp.getArray());
|
---|
| 122 | out /= moff;
|
---|
| 123 | out *= tsarr;
|
---|
| 124 | Array<Bool> outflagsb = !(mon.getMask() && moff.getMask());
|
---|
| 125 | Array<uChar> outflags(outflagsb.shape());
|
---|
| 126 | convertArray(outflags,outflagsb);
|
---|
| 127 |
|
---|
| 128 | SDContainer sc(ipon(0),ipon(1),ipon(2),ipon(3));
|
---|
| 129 | String tstr; srcn.getScalar(0,tstr);// get sourcename of "on" scan
|
---|
| 130 | sc.sourcename = tstr;
|
---|
| 131 | Double tme; mjd.getScalar(0,tme);// get time of "on" scan
|
---|
| 132 | sc.timestamp = tme;
|
---|
| 133 | sc.putSpectrum(out);
|
---|
| 134 | sc.putFlags(outflags);
|
---|
| 135 | SDMemTable* sdmt = new SDMemTable(*on);
|
---|
| 136 | sdmt->putSDContainer(sc);
|
---|
| 137 | return CountedPtr<SDMemTable>(sdmt);
|
---|
| 138 |
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|