//#--------------------------------------------------------------------------- //# 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"); 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; 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 } // averaging using mask MaskedArray nma (narr,(narr > Float(0))); outarr /= nma; SDContainer sc(ip(0),ip(1),ip(2),ip(3)); Int n = t.nrow(); outtsarr /= Float(n/2); sc.timestamp = tme/Double(n/2); String tstr; srcn.getScalar(n,tstr);// get sourcename of "mid" point sc.sourcename = tstr; sc.putSpectrum(outarr); //sc.putFlags(outflags); SDMemTable* sdmt = new SDMemTable(*in); sdmt->putSDContainer(sc); return CountedPtr(sdmt); }