source: trunk/src/RowAccumulator.cpp@ 829

Last change on this file since 829 was 814, checked in by mar637, 19 years ago

Acuumulator for Scantable averaging. Initial revision.

File size: 3.5 KB
Line 
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>
15#include <casa/Arrays/ArrayMath.h>
16#include "RowAccumulator.h"
17
18
19using namespace casa;
20using namespace asap;
21
22RowAccumulator::RowAccumulator(WeightType wt) :
23 weightType_(wt),
24 initialized_(False)
25{
26 reset();
27}
28
29RowAccumulator::~RowAccumulator()
30{
31}
32
33
34void RowAccumulator::add( const Vector< Float >& v,
35 const Vector< Bool >& m,
36 const Vector< Float >& tsys,
37 Double interval,
38 Double time )
39{
40 if (!initialized_) {
41 Vector<Float> dummy(v.nelements(), 0.0);
42 spectrum_.setData(dummy, Vector<Bool>(m.nelements(), True));
43 n_.setData(Vector<Float>(v.nelements(), 0.0), m);
44 weightSum_.setData(Vector<Float>(v.nelements(), 0.0), m);
45 tsysSum_.resize(tsys.nelements()); tsysSum_=0.0;
46 }
47 // add spectrum related weights, so far it is variance only.
48 Float totalweight = 1.0;
49 totalweight *= addTsys(tsys);
50 totalweight *= addInterval(interval);
51 addTime(time);
52 addSpectrum(v, m, totalweight);
53 initialized_ = True;
54}
55
56void RowAccumulator::addSpectrum( const Vector< Float >& v,
57 const Vector< Bool >& m,
58 Float weight)
59{
60 Float totalweight = weight;
61 MaskedArray<Float> data(v,m);
62 if ( weightType_ == asap::VAR ) {
63 cout << "doing VAR" << endl;
64 if (m.nelements() == userMask_.nelements()) {
65 Float fac = 1.0/variance(data(userMask_));
66 totalweight *= fac;
67 } else {
68 Float fac = 1.0/variance(data);
69 totalweight *= fac;
70 }
71 }
72 data *= totalweight;
73 MaskedArray<Float> wadd(Vector<Float>(m.nelements(),totalweight), m);
74 weightSum_ += wadd;
75 spectrum_ += data;
76 const MaskedArray<Float> inc(Vector<Float>(m.nelements(),1.0), m);
77 n_ += inc;
78}
79
80Float RowAccumulator::addTsys( const casa::Vector< casa::Float > & v )
81{
82 // @fixme this assume tsys is the same for all channels
83
84 Float w = 1.0;
85 tsysSum_ += v[0];
86 if ( weightType_ == asap::TSYS || weightType_ == asap::TINTSYS ) {
87 cout << "doing TSYS" << endl;
88 w /= (v[0]*v[0]);
89 }
90 return w;
91}
92
93void asap::RowAccumulator::addTime( casa::Double t )
94{
95 //cout << setw(11) << setprecision(10) << timeSum_ << " + " << t << endl;
96 timeSum_ += t;
97}
98
99Float asap::RowAccumulator::addInterval( casa::Double inter )
100{
101 Float w = 1.0;
102 intervalSum_ += inter;
103 if ( weightType_ == asap::TINT || weightType_ == asap::TINTSYS ) {
104 cout << "doing TINT" << endl;
105 w /= Float(inter);
106 }
107 return w;
108}
109
110void asap::RowAccumulator::reset( )
111{
112 initialized_ = False;
113 intervalSum_ = 0.0;
114 tsysSum_.resize();
115 timeSum_ = 0.0;
116}
117
118casa::Vector< casa::Float > RowAccumulator::getSpectrum( ) const
119{
120 return (spectrum_/weightSum_).getArray();
121}
122
123casa::Double asap::RowAccumulator::getTime( ) const
124{
125 //cout << setw(11) << setprecision(10) << timeSum_ << " / " << max(n_) << endl;
126 return timeSum_/max(n_);
127}
128
129casa::Double asap::RowAccumulator::getInterval( ) const
130{
131 return intervalSum_;
132}
133
134casa::Vector< casa::Bool > RowAccumulator::getMask( ) const
135{
136 return spectrum_.getMask();
137}
138
139casa::Vector< casa::Float > asap::RowAccumulator::getTsys( ) const
140{
141 // @fixme this assummes tsys.nelements() == 1
142 return tsysSum_/max(n_);
143}
144
145void asap::RowAccumulator::setUserMask( const casa::Vector< casa::Bool > & m )
146{
147 userMask_.resize();
148 userMask_ = m;
149}
Note: See TracBrowser for help on using the repository browser.