source: trunk/src/RowAccumulator.cpp@ 951

Last change on this file since 951 was 854, checked in by mar637, 19 years ago

comment tidy up

File size: 3.4 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>
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 timeSum_ += t;
96}
97
98Float asap::RowAccumulator::addInterval( casa::Double inter )
99{
100 Float w = 1.0;
101 intervalSum_ += inter;
102 if ( weightType_ == asap::TINT || weightType_ == asap::TINTSYS ) {
103 cout << "doing TINT" << endl;
104 w /= Float(inter);
105 }
106 return w;
107}
108
109void asap::RowAccumulator::reset( )
110{
111 initialized_ = False;
112 intervalSum_ = 0.0;
113 tsysSum_.resize();
114 timeSum_ = 0.0;
115}
116
117casa::Vector< casa::Float > RowAccumulator::getSpectrum( ) const
118{
119 return (spectrum_/weightSum_).getArray();
120}
121
122casa::Double asap::RowAccumulator::getTime( ) const
123{
124 return timeSum_/max(n_);
125}
126
127casa::Double asap::RowAccumulator::getInterval( ) const
128{
129 return intervalSum_;
130}
131
132casa::Vector< casa::Bool > RowAccumulator::getMask( ) const
133{
134 return spectrum_.getMask();
135}
136
137casa::Vector< casa::Float > asap::RowAccumulator::getTsys( ) const
138{
139 // @fixme this assummes tsys.nelements() == 1
140 return tsysSum_/max(n_);
141}
142
143void asap::RowAccumulator::setUserMask( const casa::Vector< casa::Bool > & m )
144{
145 userMask_.resize();
146 userMask_ = m;
147}
Note: See TracBrowser for help on using the repository browser.