nidas v1.2.3
StatisticsCruncher.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2006, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26
27#ifndef NIDAS_DYNLD_STATISTICSCRUNCHER_H
28#define NIDAS_DYNLD_STATISTICSCRUNCHER_H
29
34#include <nidas/util/UTime.h>
35
36#include <vector>
37#include <algorithm>
38
39namespace nidas { namespace dynld {
40
41class StatisticsProcessor;
42
43using namespace nidas::core;
44
48{
49public:
50
59
64 const SampleTag* stag,statisticsType type,
65 std::string countsName,bool higherMoments);
66
68
70
72
73
77 std::list<const SampleTag*> getSampleTags() const
78 {
79 return _source.getSampleTags();
80 }
81
89
93 void addSampleClient(SampleClient* client) throw()
94 {
96 }
97
98 void removeSampleClient(SampleClient* client) throw()
99 {
101 }
102
107 void addSampleClientForTag(SampleClient* client,const SampleTag*) throw()
108 {
109 // I only have one tag, so just call addSampleClient()
110 _source.addSampleClient(client);
111 }
112
114 {
116 }
117
118 int getClientCount() const throw()
119 {
120 return _source.getClientCount();
121 }
122
126 void flush() throw();
127
129 {
130 return _source.getSampleStats();
131 }
132
133 bool receive(const Sample *s) throw();
134
140 void connect(SampleSource* source);
141
142 void disconnect(SampleSource* source) throw();
143
147 void connect(SampleOutput* output);
148
150
154 static statisticsType getStatisticsType(const std::string& type);
155
161 static const std::string& getStatisticsString(statisticsType stype);
162
163 void setStartTime(const nidas::util::UTime& val);
164
166 {
167 return _startTime;
168 }
169
171 {
172 _endTime = val;
173 }
174
176 {
177 return _endTime;
178 }
179
180 long long getPeriodUsecs() const
181 {
182 return _periodUsecs;
183 }
184
192 bool getFillGaps() const
193 {
194 return _fillGaps;
195 }
196
197 void setFillGaps(bool val)
198 {
199 _fillGaps = val;
200 }
201
202protected:
203
207 void attach(SampleSource* source);
208
212 void splitNames();
213
218 std::string makeName(int i, int j=-1, int k=-1, int l=-1);
219
224 std::string makeUnits(int i, int j=-1, int k=-1, int l=-1);
225
226 std::string makeUnits(const std::vector<std::string>&);
227
231 void createCombinations();
232
233 void setupMoments(unsigned int nvars, unsigned int moment);
234
235 void setupMinMax(const std::string&);
236
240 void setupWindDir();
241
242 void setupCovariances();
243
244 void setupTrivariances();
245
247
248 void setupFluxes();
249
250 void setupReducedFluxes();
251
253
254 void initStats();
255
256 void zeroStats();
257
258 void computeStats();
259
260 void
261 addVariable(const std::string& name,
262 const std::string& longname,
263 const std::string& units);
264private:
265
270 void addSampleTag(const SampleTag* tag) throw ()
271 {
273 }
274
275 void removeSampleTag(const SampleTag* tag) throw ()
276 {
278 }
279
281
283
285
286 std::vector<const Variable*> _reqVariables;
287
291 unsigned int _ninvars;
292
296 std::string _countsName;
297
302
304
309
311
316
320 std::vector<std::vector<std::string> > _splitVarNames;
321
326 std::string _leadCommon;
327
331 std::string _commonSuffix;
332
334
335 unsigned int _nOutVar;
336
337 unsigned int _outlen;
338
340
341 struct sampleInfo {
343 unsigned int weightsIndex;
344 std::vector<unsigned int*> varIndices;
345 };
346
347 std::map<dsm_sample_id_t,sampleInfo > _sampleMap;
348
349 float* _xMin;
350
351 float* _xMax;
352
353 // statistics sums.
354 double* _xSum;
355
356 double** _xySum;
357 double* _xyzSum;
358 double* _x4Sum;
359
360 unsigned int *_nSamples;
361
362 unsigned int **_triComb;
363
367 unsigned int _nsum;
368
372 unsigned int _ncov;
373
377 unsigned int _ntri;
378
383
387 unsigned int _ntot;
388
390
391 const Site* _site;
392
394
396
398
400
403
406
407};
408
409}} // namespace nidas namespace core
410
411#endif
A simple, nearest-point resampler, for generating merged samples from variables from one or more samp...
Definition NearestResampler.h:54
Interface for a resampler, simply a SampleClient and a SampleSource.
Definition Resampler.h:39
Pure virtual interface of a client of Samples.
Definition SampleClient.h:38
Interface of an output stream of samples.
Definition SampleOutput.h:49
A source of samples.
Definition SampleSourceSupport.h:47
void removeSampleClient(SampleClient *c)
Remove a SampleClient from this SampleSource This will also remove a SampleClient if it has been adde...
Definition SampleSourceSupport.cc:88
void addSampleClient(SampleClient *c)
Add a SampleClient to this SampleSource.
Definition SampleSourceSupport.cc:80
SampleTagIterator getSampleTagIterator() const
Definition SampleSourceSupport.cc:75
int getClientCount() const
How many SampleClients are currently in my list.
Definition SampleSourceSupport.cc:136
void removeSampleTag(const SampleTag *tag)
Definition SampleSourceSupport.cc:67
const SampleStats & getSampleStats() const
Definition SampleSourceSupport.h:149
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition SampleSourceSupport.cc:60
std::list< const SampleTag * > getSampleTags() const
What SampleTags am I a SampleSource for?
Definition SampleSourceSupport.cc:54
Pure virtual interface for a source of Samples.
Definition SampleSource.h:48
A source of samples.
Definition SampleStats.h:41
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition NidsIterators.h:218
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
Interface to a data sample.
Definition Sample.h:190
A measurement site.
Definition Site.h:49
Definition StatisticsCruncher.h:48
SampleSourceSupport _source
Definition StatisticsCruncher.h:282
std::string makeUnits(int i, int j=-1, int k=-1, int l=-1)
Create a derived units field from input variables i,j,k,l.
Definition StatisticsCruncher.cc:712
void computeStats()
Definition StatisticsCruncher.cc:1653
dsm_time_t _periodUsecs
Definition StatisticsCruncher.h:303
enum nidas::dynld::StatisticsCruncher::statsEnumType statisticsType
Types of statistics I can generate.
static const std::string & getStatisticsString(statisticsType stype)
Return string name for the given stype.
Definition StatisticsCruncher.cc:214
unsigned int * _nSamples
Definition StatisticsCruncher.h:360
std::string _countsName
Name of counts variable.
Definition StatisticsCruncher.h:296
void setupMoments(unsigned int nvars, unsigned int moment)
Definition StatisticsCruncher.cc:763
void disconnect(SampleOutput *output)
StatisticsCruncher(const StatisticsCruncher &)
No copy.
double * _x4Sum
Definition StatisticsCruncher.h:358
void setupFluxes()
Definition StatisticsCruncher.cc:1046
std::string makeName(int i, int j=-1, int k=-1, int l=-1)
Create a derived variable name from input variables i,j,k,l.
Definition StatisticsCruncher.cc:621
StatisticsCruncher & operator=(const StatisticsCruncher &)
No assignment.
double * _xSum
Definition StatisticsCruncher.h:354
std::string _commonSuffix
Trailing portion that is common to all variable names.
Definition StatisticsCruncher.h:331
void setupTrivariances()
Definition StatisticsCruncher.cc:876
void addVariable(const std::string &name, const std::string &longname, const std::string &units)
Definition StatisticsCruncher.cc:804
StatisticsCruncher(StatisticsProcessor *proc, const SampleTag *stag, statisticsType type, std::string countsName, bool higherMoments)
Constructor.
Definition StatisticsCruncher.cc:59
const Site * _site
Definition StatisticsCruncher.h:391
SampleTag _outSample
Definition StatisticsCruncher.h:333
unsigned int _ntri
Number of trivariances to compute.
Definition StatisticsCruncher.h:377
SampleTag _reqTag
Definition StatisticsCruncher.h:284
statsEnumType
Types of statistics I can generate.
Definition StatisticsCruncher.h:54
@ STATS_MAXIMUM
Definition StatisticsCruncher.h:55
@ STATS_SFLUX
Definition StatisticsCruncher.h:56
@ STATS_UNKNOWN
Definition StatisticsCruncher.h:55
@ STATS_MINIMUM
Definition StatisticsCruncher.h:55
@ STATS_MEAN
Definition StatisticsCruncher.h:55
@ STATS_SUM
Definition StatisticsCruncher.h:57
@ STATS_TRIVAR
Definition StatisticsCruncher.h:57
@ STATS_FLUX
Definition StatisticsCruncher.h:56
@ STATS_COV
Definition StatisticsCruncher.h:56
@ STATS_RFLUX
Definition StatisticsCruncher.h:56
@ STATS_PRUNEDTRIVAR
Definition StatisticsCruncher.h:57
@ STATS_VAR
Definition StatisticsCruncher.h:55
@ STATS_WINDDIR
Definition StatisticsCruncher.h:57
const SampleStats & getSampleStats() const
Definition StatisticsCruncher.h:128
void setupReducedFluxes()
Definition StatisticsCruncher.cc:1076
long long getPeriodUsecs() const
Definition StatisticsCruncher.h:180
void removeSampleClientForTag(SampleClient *client, const SampleTag *)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition StatisticsCruncher.h:113
std::string _leadCommon
Portion after the first dot-separated word that is common to all variable names.
Definition StatisticsCruncher.h:326
statisticsType _statsType
Types of statistics I can generate.
Definition StatisticsCruncher.h:315
std::list< const SampleTag * > getSampleTags() const
Get the output SampleTags.
Definition StatisticsCruncher.h:77
nidas::util::UTime getEndTime() const
Definition StatisticsCruncher.h:175
bool _numpoints
Does the user want number-of-points output?
Definition StatisticsCruncher.h:301
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition StatisticsCruncher.h:98
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition StatisticsCruncher.h:71
unsigned int _n3mom
Definition StatisticsCruncher.h:382
void createCombinations()
Definition StatisticsCruncher.cc:1155
unsigned int _nsum
Number of simple sums to maintain.
Definition StatisticsCruncher.h:367
dsm_time_t _tout
Definition StatisticsCruncher.h:339
static statisticsType getStatisticsType(const std::string &type)
Definition StatisticsCruncher.cc:200
void setupMinMax(const std::string &)
Definition StatisticsCruncher.cc:1128
~StatisticsCruncher()
Definition StatisticsCruncher.cc:142
unsigned int _ntot
Total number of products to compute.
Definition StatisticsCruncher.h:387
float * _xMin
Definition StatisticsCruncher.h:349
double ** _xySum
Definition StatisticsCruncher.h:356
unsigned int _n4mom
Definition StatisticsCruncher.h:382
std::vector< std::vector< std::string > > _splitVarNames
Input variable names, split at dots.
Definition StatisticsCruncher.h:320
nidas::util::UTime _startTime
Definition StatisticsCruncher.h:395
bool _fillGaps
Definition StatisticsCruncher.h:399
void zeroStats()
Definition StatisticsCruncher.cc:1350
unsigned int _ninvars
Number of input variables.
Definition StatisticsCruncher.h:291
unsigned int _n2mom
Definition StatisticsCruncher.h:382
void setEndTime(const nidas::util::UTime &val)
Definition StatisticsCruncher.h:170
void disconnect(SampleSource *source)
Definition StatisticsCruncher.cc:318
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition StatisticsCruncher.h:93
void setupWindDir()
Definition StatisticsCruncher.cc:820
void initStats()
Definition StatisticsCruncher.cc:1265
unsigned int ** _triComb
Definition StatisticsCruncher.h:362
double * _xyzSum
Definition StatisticsCruncher.h:357
std::vector< const Variable * > _reqVariables
Definition StatisticsCruncher.h:286
unsigned int _outlen
Definition StatisticsCruncher.h:337
bool _crossTerms
Does this cruncher compute cross-terms?
Definition StatisticsCruncher.h:308
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition StatisticsCruncher.h:69
void setupPrunedTrivariances()
Definition StatisticsCruncher.cc:918
unsigned int _nOutVar
Definition StatisticsCruncher.h:335
unsigned int _n1mom
Number of 1st,2nd,3rd,4th moments to compute.
Definition StatisticsCruncher.h:382
void setFillGaps(bool val)
Definition StatisticsCruncher.h:197
int getClientCount() const
How many SampleClients are currently in my list.
Definition StatisticsCruncher.h:118
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition StatisticsCruncher.h:85
NearestResampler * _resampler
Definition StatisticsCruncher.h:310
int _station
Definition StatisticsCruncher.h:393
bool getFillGaps() const
Whether to generate output samples over time gaps.
Definition StatisticsCruncher.h:192
bool receive(const Sample *s)
Method called to pass a sample to this client.
Definition StatisticsCruncher.cc:1364
nidas::util::UTime getStartTime() const
Definition StatisticsCruncher.h:165
void setStartTime(const nidas::util::UTime &val)
Definition StatisticsCruncher.cc:169
void attach(SampleSource *source)
Definition StatisticsCruncher.cc:324
float * _xMax
Definition StatisticsCruncher.h:351
unsigned int _ncov
Number of covariances to compute.
Definition StatisticsCruncher.h:372
void removeSampleTag(const SampleTag *tag)
Definition StatisticsCruncher.h:275
void addSampleClientForTag(SampleClient *client, const SampleTag *)
Add a Client for a given SampleTag.
Definition StatisticsCruncher.h:107
void splitNames()
Split input variable names at periods.
Definition StatisticsCruncher.cc:502
std::map< dsm_sample_id_t, sampleInfo > _sampleMap
Definition StatisticsCruncher.h:347
nidas::util::UTime _endTime
Definition StatisticsCruncher.h:397
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition StatisticsCruncher.h:270
void connect(SampleOutput *output)
Connect a SamplePipeline to the cruncher.
void setupCovariances()
Definition StatisticsCruncher.cc:853
bool _higherMoments
Definition StatisticsCruncher.h:389
void flush()
Implementation of Resampler::flush().
Definition StatisticsCruncher.cc:1873
void setupReducedScalarFluxes()
Definition StatisticsCruncher.cc:1107
void connect(SampleSource *source)
Connect a SamplePipeline to the cruncher.
Definition StatisticsCruncher.cc:226
StatisticsProcessor * _proc
Definition StatisticsCruncher.h:280
Interface of a processor of samples.
Definition StatisticsProcessor.h:44
A class for parsing, formatting and doing operations on time, based on Unix time conventions,...
Definition UTime.h:95
The essential core classes of nidas.
Definition A2DConverter.h:31
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC.
Definition Sample.h:62
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
Definition StatisticsCruncher.h:341
std::vector< unsigned int * > varIndices
Definition StatisticsCruncher.h:344
sampleInfo()
Definition StatisticsCruncher.h:342
unsigned int weightsIndex
Definition StatisticsCruncher.h:343