source: trunk/src/RowAccumulator.cpp@ 1403

Last change on this file since 1403 was 1398, checked in by Malte Marquarding, 17 years ago

made n_ unsigned integer (from float) to maybe speed things up a bit

File size: 3.6 KB
RevLine 
[814]1//
2// C++ Implementation: RowAccumulator
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <Malte.Marquarding@csiro.au>, (C) 2005
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <casa/iomanip.h>
13
14#include <casa/Arrays/MaskArrMath.h>
[1314]15#include <casa/Arrays/MaskArrLogi.h>
[814]16#include <casa/Arrays/ArrayMath.h>
[1314]17#include <casa/Arrays/ArrayLogical.h>
[814]18#include "RowAccumulator.h"
19
20
21using namespace casa;
22using namespace asap;
23
24RowAccumulator::RowAccumulator(WeightType wt) :
25 weightType_(wt),
26 initialized_(False)
27{
28 reset();
29}
30
31RowAccumulator::~RowAccumulator()
32{
33}
34
35
36void RowAccumulator::add( const Vector< Float >& v,
37 const Vector< Bool >& m,
38 const Vector< Float >& tsys,
39 Double interval,
40 Double time )
41{
42 if (!initialized_) {
43 Vector<Float> dummy(v.nelements(), 0.0);
[1314]44 Vector<Bool> dummymsk(m.nelements(), True);
45 spectrum_.setData(dummy, dummymsk);
[1398]46 n_.setData(Vector<uInt>(v.nelements(), 0), dummymsk);
[1314]47 weightSum_.setData(Vector<Float>(v.nelements(), 0.0), dummymsk);
[814]48 tsysSum_.resize(tsys.nelements()); tsysSum_=0.0;
49 }
50 // add spectrum related weights, so far it is variance only.
51 Float totalweight = 1.0;
52 totalweight *= addTsys(tsys);
[1314]53 // only add these if not everything masked
54 if ( !allEQ(m, False) ) {
55 totalweight *= addInterval(interval);
56 addTime(time);
57 }
[814]58 addSpectrum(v, m, totalweight);
59 initialized_ = True;
60}
61
62void RowAccumulator::addSpectrum( const Vector< Float >& v,
63 const Vector< Bool >& m,
64 Float weight)
65{
66 Float totalweight = weight;
67 MaskedArray<Float> data(v,m);
68 if ( weightType_ == asap::VAR ) {
69 if (m.nelements() == userMask_.nelements()) {
70 Float fac = 1.0/variance(data(userMask_));
71 totalweight *= fac;
72 } else {
73 Float fac = 1.0/variance(data);
74 totalweight *= fac;
75 }
76 }
77 data *= totalweight;
78 MaskedArray<Float> wadd(Vector<Float>(m.nelements(),totalweight), m);
79 weightSum_ += wadd;
80 spectrum_ += data;
[1398]81 const MaskedArray<uInt> inc(Vector<uInt>(m.nelements(),1), m);
[814]82 n_ += inc;
83}
84
85Float RowAccumulator::addTsys( const casa::Vector< casa::Float > & v )
86{
87 // @fixme this assume tsys is the same for all channels
88
89 Float w = 1.0;
90 tsysSum_ += v[0];
91 if ( weightType_ == asap::TSYS || weightType_ == asap::TINTSYS ) {
92 w /= (v[0]*v[0]);
93 }
94 return w;
95}
96
97void asap::RowAccumulator::addTime( casa::Double t )
98{
99 timeSum_ += t;
100}
101
102Float asap::RowAccumulator::addInterval( casa::Double inter )
103{
104 Float w = 1.0;
105 intervalSum_ += inter;
106 if ( weightType_ == asap::TINT || weightType_ == asap::TINTSYS ) {
107 w /= Float(inter);
108 }
109 return w;
110}
111
112void asap::RowAccumulator::reset( )
113{
114 initialized_ = False;
115 intervalSum_ = 0.0;
116 tsysSum_.resize();
117 timeSum_ = 0.0;
118}
119
120casa::Vector< casa::Float > RowAccumulator::getSpectrum( ) const
121{
122 return (spectrum_/weightSum_).getArray();
123}
124
125casa::Double asap::RowAccumulator::getTime( ) const
126{
[1398]127 uInt n = max(n_);
128 return timeSum_/Float(n);
[814]129}
130
131casa::Double asap::RowAccumulator::getInterval( ) const
132{
133 return intervalSum_;
134}
135
136casa::Vector< casa::Bool > RowAccumulator::getMask( ) const
137{
[1352]138 // Return the "total" mask - False where no points have been accumulated.
[1398]139 return (n_.getArray() > uInt(0));
[814]140}
141
142casa::Vector< casa::Float > asap::RowAccumulator::getTsys( ) const
143{
[1314]144 // @fixme this assumes tsys.nelements() == 1
[1398]145 return tsysSum_/Float(max(n_));
[814]146}
147
148void asap::RowAccumulator::setUserMask( const casa::Vector< casa::Bool > & m )
149{
150 userMask_.resize();
151 userMask_ = m;
152}
Note: See TracBrowser for help on using the repository browser.