source: branches/alma/src/RowAccumulator.cpp@ 2000

Last change on this file since 2000 was 1757, checked in by Kana Sugimoto, 14 years ago

New Development: Yes

JIRA Issue: Yes (CAS-2211)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: ASAP 3.0.0 interface changes

Test Programs:

Put in Release Notes: Yes

Module(s): all the CASA sd tools and tasks are affected.

Description: Merged ATNF-ASAP 3.0.0 developments to CASA (alma) branch.

Note you also need to update casa/code/atnf.


File size: 3.7 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);
[1603]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;
[1603]52
[1314]53 // only add these if not everything masked
54 if ( !allEQ(m, False) ) {
[1603]55 totalweight *= addTsys(tsys);
[1314]56 totalweight *= addInterval(interval);
57 addTime(time);
58 }
[814]59 addSpectrum(v, m, totalweight);
60 initialized_ = True;
61}
62
63void RowAccumulator::addSpectrum( const Vector< Float >& v,
64 const Vector< Bool >& m,
65 Float weight)
66{
67 Float totalweight = weight;
68 MaskedArray<Float> data(v,m);
[1757]69 if ( weightType_ == asap::W_VAR ) {
[814]70 if (m.nelements() == userMask_.nelements()) {
71 Float fac = 1.0/variance(data(userMask_));
72 totalweight *= fac;
73 } else {
74 Float fac = 1.0/variance(data);
75 totalweight *= fac;
76 }
77 }
78 data *= totalweight;
79 MaskedArray<Float> wadd(Vector<Float>(m.nelements(),totalweight), m);
80 weightSum_ += wadd;
81 spectrum_ += data;
[1603]82 const MaskedArray<uInt> inc(Vector<uInt>(m.nelements(),1), m);
[814]83 n_ += inc;
84}
85
86Float RowAccumulator::addTsys( const casa::Vector< casa::Float > & v )
87{
88 // @fixme this assume tsys is the same for all channels
89
90 Float w = 1.0;
91 tsysSum_ += v[0];
[1757]92 if ( weightType_ == asap::W_TSYS || weightType_ == asap::W_TINTSYS ) {
[814]93 w /= (v[0]*v[0]);
94 }
95 return w;
96}
97
98void asap::RowAccumulator::addTime( casa::Double t )
99{
100 timeSum_ += t;
101}
102
103Float asap::RowAccumulator::addInterval( casa::Double inter )
104{
105 Float w = 1.0;
106 intervalSum_ += inter;
[1757]107 if ( weightType_ == asap::W_TINT || weightType_ == asap::W_TINTSYS ) {
[814]108 w /= Float(inter);
109 }
110 return w;
111}
112
113void asap::RowAccumulator::reset( )
114{
115 initialized_ = False;
116 intervalSum_ = 0.0;
117 tsysSum_.resize();
118 timeSum_ = 0.0;
119}
120
121casa::Vector< casa::Float > RowAccumulator::getSpectrum( ) const
122{
123 return (spectrum_/weightSum_).getArray();
124}
125
126casa::Double asap::RowAccumulator::getTime( ) const
127{
[1603]128 uInt n = max(n_);
129 return timeSum_/Float(n);
[814]130}
131
132casa::Double asap::RowAccumulator::getInterval( ) const
133{
134 return intervalSum_;
135}
136
137casa::Vector< casa::Bool > RowAccumulator::getMask( ) const
138{
[1352]139 // Return the "total" mask - False where no points have been accumulated.
[1603]140 return (n_.getArray() > uInt(0));
[814]141}
142
143casa::Vector< casa::Float > asap::RowAccumulator::getTsys( ) const
144{
[1314]145 // @fixme this assumes tsys.nelements() == 1
[1603]146 return tsysSum_/Float(max(n_));
[814]147}
148
149void asap::RowAccumulator::setUserMask( const casa::Vector< casa::Bool > & m )
150{
151 userMask_.resize();
152 userMask_ = m;
153}
[1446]154
155// Added by TT check the state of RowAccumulator
156casa::Bool RowAccumulator::state() const
157{
158 return initialized_;
159}
[1603]160
Note: See TracBrowser for help on using the repository browser.