//#--------------------------------------------------------------------------- //# SDMath.cc: A collection of single dish mathematical operations //#--------------------------------------------------------------------------- //# Copyright (C) 2004 //# Malte Marquarding, ATNF //# //# This program is free software; you can redistribute it and/or modify it //# under the terms of the GNU General Public License as published by the Free //# Software Foundation; either version 2 of the License, or (at your option) //# any later version. //# //# This program is distributed in the hope that it will be useful, but //# WITHOUT ANY WARRANTY; without even the implied warranty of //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General //# Public License for more details. //# //# You should have received a copy of the GNU General Public License along //# with this program; if not, write to the Free Software Foundation, Inc., //# 675 Massachusetts Ave, Cambridge, MA 02139, USA. //# //# Correspondence concerning this software should be addressed as follows: //# Internet email: Malte.Marquarding@csiro.au //# Postal address: Malte Marquarding, //# Australia Telescope National Facility, //# P.O. Box 76, //# Epping, NSW, 2121, //# AUSTRALIA //# //# $Id: //#--------------------------------------------------------------------------- #include #include #include #include #include #include #include #include #include #include #include #include #include "SDContainer.h" #include "SDMemTable.h" #include "SDMath.h" using namespace atnf_sd; static CountedPtr SDMath::average(const CountedPtr& in) { Table t = in->table(); ROArrayColumn tsys(t, "TSYS"); ROScalarColumn mjd(t, "TIME"); ROScalarColumn srcn(t, "SRCNAME"); ROScalarColumn integr(t, "INTERVAL"); IPosition ip = in->rowAsMaskedArray(0).shape(); Array outarr(ip); outarr =0.0; Array narr(ip);narr = 0.0; Array narrinc(ip);narrinc = 1.0; Array tsarr(tsys.shape(0)); Array outtsarr(tsys.shape(0)); Double tme = 0.0; Double inttime = 0.0; for (uInt i=0; i < t.nrow(); i++) { // data stuff MaskedArray marr(in->rowAsMaskedArray(i)); outarr += marr; MaskedArray n(narrinc,marr.getMask()); narr += n; // get tsys.get(i, tsarr);// this is probably unneccessary as tsys should outtsarr += tsarr; // be constant Double tmp; mjd.get(i,tmp); tme += tmp;// average time integr.get(i,tmp); inttime += tmp; } // averaging using mask MaskedArray nma(narr,(narr > Float(0))); outarr /= nma; Array outflagsb = !(nma.getMask()); Array outflags(outflagsb.shape()); convertArray(outflags,outflagsb); SDContainer sc(ip(0),ip(1),ip(2),ip(3)); Int n = t.nrow(); outtsarr /= Float(n/2); sc.timestamp = tme/Double(n/2); sc.interval =inttime; String tstr; srcn.getScalar(0,tstr);// get sourcename of "mid" point sc.sourcename = tstr; sc.putSpectrum(outarr); sc.putFlags(outflags); SDMemTable* sdmt = new SDMemTable(*in,True); sdmt->putSDContainer(sc); return CountedPtr(sdmt); } static CountedPtr SDMath::quotient(const CountedPtr& on, const CountedPtr& off) { Table ton = on->table(); Table toff = off->table(); ROArrayColumn tsys(toff, "TSYS"); ROScalarColumn mjd(ton, "TIME"); ROScalarColumn integr(ton, "INTERVAL"); ROScalarColumn srcn(ton, "SRCNAME"); MaskedArray mon(on->rowAsMaskedArray(0)); MaskedArray moff(off->rowAsMaskedArray(0)); IPosition ipon = mon.shape(); IPosition ipoff = moff.shape(); Array tsarr(tsys.shape(0)); if (ipon != ipoff && ipon != tsarr.shape()) cerr << "on/off not conformant" << endl; //IPosition test = mon.shape()/2; MaskedArray tmp = (mon-moff); Array out(tmp.getArray()); out /= moff; out *= tsarr; Array outflagsb = !(mon.getMask() && moff.getMask()); Array outflags(outflagsb.shape()); convertArray(outflags,outflagsb); SDContainer sc(ipon(0),ipon(1),ipon(2),ipon(3)); String tstr; srcn.getScalar(0,tstr);// get sourcename of "on" scan sc.sourcename = tstr; Double tme; mjd.getScalar(0,tme);// get time of "on" scan sc.timestamp = tme; integr.getScalar(0,tme); sc.interval = tme; sc.putSpectrum(out); sc.putFlags(outflags); SDMemTable* sdmt = new SDMemTable(*on, True); sdmt->putSDContainer(sc); return CountedPtr(sdmt); } static CountedPtr SDMath::multiply(const CountedPtr& in, Float factor) { SDMemTable* sdmt = new SDMemTable(*in); Table t = sdmt->table(); ArrayColumn spec(t,"SPECTRA"); for (uInt i=0; i < t.nrow(); i++) { // data stuff MaskedArray marr(sdmt->rowAsMaskedArray(i)); marr *= factor; spec.put(i, marr.getArray()); } return CountedPtr(sdmt); } /* static Float SDMath::rms(const SDMemTable& in, uInt whichRow) { Table t = in.table(); MaskedArray marr(in.rowAsMaskedArray(whichRow,True)); } */