nidas  v1.2-1520
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 
39 namespace nidas { namespace dynld {
40 
41 class StatisticsProcessor;
42 
43 using namespace nidas::core;
44 
48 {
49 public:
50 
54  typedef enum statsEnumType {
55  STATS_UNKNOWN,STATS_MINIMUM,STATS_MAXIMUM,STATS_MEAN,STATS_VAR,
56  STATS_COV, STATS_FLUX, STATS_RFLUX,STATS_SFLUX,
57  STATS_TRIVAR,STATS_PRUNEDTRIVAR, STATS_WINDDIR, STATS_SUM
58  } statisticsType;
59 
64  const SampleTag* stag,statisticsType type,
65  std::string countsName,bool higherMoments);
66 
68 
70 
71  SampleSource* getProcessedSampleSource() { return &_source; }
72 
73 
77  std::list<const SampleTag*> getSampleTags() const
78  {
79  return _source.getSampleTags();
80  }
81 
86  {
87  return _source.getSampleTagIterator();
88  }
89 
93  void addSampleClient(SampleClient* client) throw()
94  {
95  _source.addSampleClient(client);
96  }
97 
98  void removeSampleClient(SampleClient* client) throw()
99  {
100  _source.removeSampleClient(client);
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 
113  void removeSampleClientForTag(SampleClient* client,const SampleTag*) throw()
114  {
115  _source.removeSampleClient(client);
116  }
117 
118  int getClientCount() const throw()
119  {
120  return _source.getClientCount();
121  }
122 
126  void flush() throw();
127 
128  const SampleStats& getSampleStats() const
129  {
130  return _source.getSampleStats();
131  }
132 
133  bool receive(const Sample *s) throw();
134 
138  void connect(SampleSource* source) throw(nidas::util::InvalidParameterException);
139 
140  void disconnect(SampleSource* source) throw();
141 
145  void connect(SampleOutput* output);
146 
147  void disconnect(SampleOutput* output);
148 
149  static statisticsType getStatisticsType(const std::string& type)
151 
152  void setStartTime(const nidas::util::UTime& val);
153 
155  {
156  return _startTime;
157  }
158 
159  void setEndTime(const nidas::util::UTime& val)
160  {
161  _endTime = val;
162  }
163 
165  {
166  return _endTime;
167  }
168 
169  long long getPeriodUsecs() const
170  {
171  return _periodUsecs;
172  }
173 
181  bool getFillGaps() const
182  {
183  return _fillGaps;
184  }
185 
186  void setFillGaps(bool val)
187  {
188  _fillGaps = val;
189  }
190 
191 protected:
192 
193  void attach(SampleSource* source) throw(nidas::util::InvalidParameterException);
194 
198  void splitNames();
199 
204  std::string makeName(int i, int j=-1, int k=-1, int l=-1);
205 
210  std::string makeUnits(int i, int j=-1, int k=-1, int l=-1);
211 
212  std::string makeUnits(const std::vector<std::string>&);
213 
214  void createCombinations()
215  throw(nidas::util::InvalidParameterException);
216 
217  void setupMoments(unsigned int nvars, unsigned int moment);
218 
219  void setupMinMax(const std::string&);
220 
221  void setupWindDir()
222  throw(nidas::util::InvalidParameterException);
223 
224  void setupCovariances();
225 
226  void setupTrivariances();
227 
228  void setupPrunedTrivariances();
229 
230  void setupFluxes();
231 
232  void setupReducedFluxes();
233 
234  void setupReducedScalarFluxes();
235 
236  void initStats();
237 
238  void zeroStats();
239 
240  void computeStats();
241 
242  void
243  addVariable(const std::string& name,
244  const std::string& longname,
245  const std::string& units);
246 private:
247 
252  void addSampleTag(const SampleTag* tag) throw ()
253  {
254  _source.addSampleTag(tag);
255  }
256 
257  void removeSampleTag(const SampleTag* tag) throw ()
258  {
259  _source.removeSampleTag(tag);
260  }
261 
263 
265 
267 
268  std::vector<const Variable*> _reqVariables;
269 
273  unsigned int _ninvars;
274 
278  std::string _countsName;
279 
284 
286 
291 
293 
298 
302  std::vector<std::vector<std::string> > _splitVarNames;
303 
308  std::string _leadCommon;
309 
313  std::string _commonSuffix;
314 
316 
317  unsigned int _nOutVar;
318 
319  unsigned int _outlen;
320 
322 
323  struct sampleInfo {
324  sampleInfo(): weightsIndex(0),varIndices() {}
325  unsigned int weightsIndex;
326  std::vector<unsigned int*> varIndices;
327  };
328 
329  std::map<dsm_sample_id_t,sampleInfo > _sampleMap;
330 
331  float* _xMin;
332 
333  float* _xMax;
334 
335  // statistics sums.
336  double* _xSum;
337 
338  double** _xySum;
339  double* _xyzSum;
340  double* _x4Sum;
341 
342  unsigned int *_nSamples;
343 
344  unsigned int **_triComb;
345 
349  unsigned int _nsum;
350 
354  unsigned int _ncov;
355 
359  unsigned int _ntri;
360 
364  unsigned int _n1mom,_n2mom,_n3mom,_n4mom;
365 
369  unsigned int _ntot;
370 
372 
373  const Site* _site;
374 
375  int _station;
376 
378 
380 
381  bool _fillGaps;
382 
385 
387  StatisticsCruncher& operator=(const StatisticsCruncher&);
388 
389 };
390 
391 }} // namespace nidas namespace core
392 
393 #endif
Interface for a resampler, simply a SampleClient and a SampleSource.
Definition: Resampler.h:39
std::string _leadCommon
Portion after the first dot-separated word that is common to all variable names.
Definition: StatisticsCruncher.h:308
nidas::util::UTime _startTime
Definition: StatisticsCruncher.h:377
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition: StatisticsCruncher.h:93
StatisticsProcessor * _proc
Definition: StatisticsCruncher.h:262
const Site * _site
Definition: StatisticsCruncher.h:373
sampleInfo()
Definition: StatisticsCruncher.h:324
Definition: StatisticsCruncher.h:56
A class for parsing, formatting and doing operations on time, based on Unix time conventions, where leap seconds are ignored, so that there are always 60 seconds in a minute, 3600 seconds in an hour and 86400 seconds in a day.
Definition: UTime.h:76
bool _fillGaps
Definition: StatisticsCruncher.h:381
std::vector< const Variable * > _reqVariables
Definition: StatisticsCruncher.h:268
unsigned int weightsIndex
Definition: StatisticsCruncher.h:325
bool _numpoints
Does the user want number-of-points output?
Definition: StatisticsCruncher.h:283
Definition: StatisticsCruncher.h:55
std::list< const SampleTag * > getSampleTags() const
Get the output SampleTags.
Definition: StatisticsCruncher.h:77
std::string _countsName
Name of counts variable.
Definition: StatisticsCruncher.h:278
A measurement site.
Definition: Site.h:49
dsm_time_t _periodUsecs
Definition: StatisticsCruncher.h:285
double * _xyzSum
Definition: StatisticsCruncher.h:339
void setEndTime(const nidas::util::UTime &val)
Definition: StatisticsCruncher.h:159
Interface of an output stream of samples.
Definition: SampleOutput.h:47
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:61
Pure virtual interface for a source of Samples.
Definition: SampleSource.h:48
nidas::util::UTime _endTime
Definition: StatisticsCruncher.h:379
A source of samples.
Definition: SampleSourceSupport.h:47
bool getFillGaps() const
Whether to generate output samples over time gaps.
Definition: StatisticsCruncher.h:181
void addSampleClientForTag(SampleClient *client, const SampleTag *)
Add a Client for a given SampleTag.
Definition: StatisticsCruncher.h:107
std::string _commonSuffix
Trailing portion that is common to all variable names.
Definition: StatisticsCruncher.h:313
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition: StatisticsCruncher.h:85
unsigned int _ninvars
Number of input variables.
Definition: StatisticsCruncher.h:273
std::vector< std::vector< std::string > > _splitVarNames
Input variable names, split at dots.
Definition: StatisticsCruncher.h:302
Definition: StatisticsCruncher.h:57
nidas::util::UTime getEndTime() const
Definition: StatisticsCruncher.h:164
void removeSampleTag(const SampleTag *tag)
Definition: StatisticsCruncher.h:257
double * _x4Sum
Definition: StatisticsCruncher.h:340
float * _xMin
Definition: StatisticsCruncher.h:331
float * _xMax
Definition: StatisticsCruncher.h:333
nidas::util::UTime getStartTime() const
Definition: StatisticsCruncher.h:154
SampleSourceSupport _source
Definition: StatisticsCruncher.h:264
NearestResampler * _resampler
Definition: StatisticsCruncher.h:292
unsigned int _n4mom
Definition: StatisticsCruncher.h:364
unsigned int * _nSamples
Definition: StatisticsCruncher.h:342
unsigned int _ncov
Number of covariances to compute.
Definition: StatisticsCruncher.h:354
Definition: StatisticsCruncher.h:47
unsigned int _ntri
Number of trivariances to compute.
Definition: StatisticsCruncher.h:359
Interface to a data sample.
Definition: Sample.h:189
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition: StatisticsCruncher.h:98
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
statisticsType _statsType
Types of statistics I can generate.
Definition: StatisticsCruncher.h:297
unsigned int _outlen
Definition: StatisticsCruncher.h:319
unsigned int _nsum
Number of simple sums to maintain.
Definition: StatisticsCruncher.h:349
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
Definition: StatisticsCruncher.h:323
A source of samples.
Definition: SampleStats.h:41
dsm_time_t _tout
Definition: StatisticsCruncher.h:321
bool _crossTerms
Does this cruncher compute cross-terms?
Definition: StatisticsCruncher.h:290
unsigned int _ntot
Total number of products to compute.
Definition: StatisticsCruncher.h:369
enum nidas::dynld::StatisticsCruncher::statsEnumType statisticsType
Types of statistics I can generate.
SampleTag _outSample
Definition: StatisticsCruncher.h:315
long long getPeriodUsecs() const
Definition: StatisticsCruncher.h:169
statsEnumType
Types of statistics I can generate.
Definition: StatisticsCruncher.h:54
Interface of a processor of samples.
Definition: StatisticsProcessor.h:43
SampleTag _reqTag
Definition: StatisticsCruncher.h:266
void setFillGaps(bool val)
Definition: StatisticsCruncher.h:186
std::vector< unsigned int * > varIndices
Definition: StatisticsCruncher.h:326
double * _xSum
Definition: StatisticsCruncher.h:336
unsigned int _nOutVar
Definition: StatisticsCruncher.h:317
double ** _xySum
Definition: StatisticsCruncher.h:338
void removeSampleClientForTag(SampleClient *client, const SampleTag *)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition: StatisticsCruncher.h:113
A simple, nearest-point resampler, for generating merged samples from variables from one or more samp...
Definition: NearestResampler.h:54
bool _higherMoments
Definition: StatisticsCruncher.h:371
unsigned int ** _triComb
Definition: StatisticsCruncher.h:344
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: StatisticsCruncher.h:71
int getClientCount() const
How many SampleClients are currently in my list.
Definition: StatisticsCruncher.h:118
std::map< dsm_sample_id_t, sampleInfo > _sampleMap
Definition: StatisticsCruncher.h:329
Definition: InvalidParameterException.h:35
int _station
Definition: StatisticsCruncher.h:375
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: StatisticsCruncher.h:69