MeteoIODoc  2.10.0
MeteoData.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 /***********************************************************************************/
3 /* Copyright 2009 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
4 /***********************************************************************************/
5 /* This file is part of MeteoIO.
6  MeteoIO is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  MeteoIO is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef METEODATA_H
20 #define METEODATA_H
21 
24 
25 #include <string>
26 #include <vector>
27 #include <set>
28 
29 namespace mio {
30 
31 class MeteoData; //forward declaration
32 typedef std::vector<MeteoData> METEO_SET;
33 
43 class MeteoGrids {
44  public:
48  RH,
49  QI,
50  TD,
51  VW,
52  DW,
54  ISWR,
55  RSWR,
58  ILWR,
59  OLWR,
61  CLD,
62  HS,
63  PSUM,
67  TSG,
68  TSS,
70  P,
72  U,
73  V,
74  W,
75  SWE,
76  RSNO,
77  ROT,
78  ALB,
79  DEM,
82  AZI,
84 
85  static const size_t nrOfParameters;
86  static size_t getParameterIndex(const std::string& parname);
87  static const std::string getParameterName(const size_t& parindex);
88  static const std::string getParameterDescription(const size_t& parindex, const bool& allow_ws=true);
89  static const std::string getParameterUnits(const size_t& parindex);
90 
91  private:
92  //static methods
93  static std::vector<std::string> paramname, description, units;
94  static const bool __init;
95  static bool initStaticData();
96 };
97 
107 class MeteoData {
108  public:
110  typedef enum {
113  COMPACT
115 
125  typedef enum MERGE_TYPE {
129  WINDOW_MERGE=3
131 
137  typedef enum MERGE_CONFLICTS {
142 
146  TA,
147  RH,
148  TSG,
149  TSS,
150  HS,
151  VW,
152  DW,
161 
162  static const std::string& getParameterName(const size_t& parindex);
163 
164  static size_t getStaticParameterIndex(const std::string& parname);
165 
169  MeteoData(void);
170 
175  MeteoData(const Date& in_date);
176 
181  MeteoData(const StationData& meta_in);
182 
188  MeteoData(const Date& date_in, const StationData& meta_in);
189 
194  void setDate(const Date& in_date) {date = in_date;}
195 
202  size_t addParameter(const std::string& i_paramname);
203 
209  bool param_exists(const std::string& parname) const;
210 
215  void reset();
216 
221  bool isNodata() const;
222 
223  bool isResampled() const {return resampled;}
224  void setResampled(const bool& in_resampled) {resampled = in_resampled;}
225 
226  bool isFiltered(const size_t& param) const;
227  void setFiltered(const size_t& param, const bool& in_filtered = true);
228  bool isGenerated(const size_t& param) const;
229  void setGenerated(const size_t& param, const bool& in_generated = true);
230  bool isResampledParam(const size_t& param) const;
231  void setResampledParam(const size_t& param, const bool& in_resampled = true);
232 
233  void standardizeNodata(const double& plugin_nodata);
234 
235  double& operator()(const size_t& parindex);
236  const double& operator()(const size_t& parindex) const;
237  double& operator()(const std::string& parname);
238  const double& operator()(const std::string& parname) const;
239 
240  const std::string& getNameForParameter(const size_t& parindex) const;
241  size_t getParameterIndex(const std::string& parname) const;
242  size_t getNrOfParameters() const {return nrOfAllParameters;}
243 
244  static MeteoGrids::Parameters findGridParam(const Parameters& mpar);
246 
259  static size_t mergeTimeSeries(std::vector<MeteoData>& vec1, const std::vector<MeteoData>& vec2, const Merge_Type& strategy=STRICT_MERGE, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
260 
275  static void merge(std::vector<MeteoData>& vec1, const std::vector<MeteoData>& vec2, const bool& simple_merge=false, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
276 
290  static void merge(std::vector<MeteoData>& vec, const MeteoData& meteo2, const bool& simple_merge=false, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
291 
305  static void merge(std::vector<MeteoData>& vec, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
306 
317  static MeteoData merge(MeteoData meteo1, const MeteoData& meteo2, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
318 
328  bool merge(const MeteoData& meteo2, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
329 
337  bool hasConflicts(const MeteoData& meteo2) const;
338 
344  static MeteoData::Merge_Type getMergeType(std::string merge_type);
345 
351  static MeteoData::Merge_Conflicts getMergeConflicts(std::string merge_conflicts);
352 
358  static std::set<std::string> listAvailableParameters(const std::vector<MeteoData>& vecMeteo);
359 
366  static void unifyMeteoData(METEO_SET &vecMeteo);
367 
373  const std::string toString(const FORMATS format=DFLT) const;
374  friend std::ostream& operator<<(std::ostream& os, const MeteoData& data);
375  friend std::istream& operator>>(std::istream& is, MeteoData& data);
376 
377  //Comparison operators
378  bool operator==(const MeteoData&) const;
379  inline bool operator!=(const MeteoData& in) const {return !(*this==in);}
380  inline bool operator<(const MeteoData& in) const {return (this->date < in.date);}
381  inline bool operator>(const MeteoData& in) const {return (this->date > in.date);}
382 
383  //direct access allowed
386 
387  static const size_t nrOfParameters;
388 
389  const std::string getStationID() const {return meta.stationID;}
390 
391  private:
392 
393  struct flag_field { //object to hold all data quality / datapoint meta flags
394  bool filtered : 1;
395  bool resampled : 1;
396  bool generated : 1;
397  bool created : 1; //TODO: not yet filled in the creators!
398  bool : 1; //leave one empty for future flag
399  unsigned int extra_flag : 3; //rest of byte space could be any 3-bit-value
400  float offset; //an offset that has been applied to the data at this time step
401  };
402 
403  //static methods
404  static std::vector<std::string> s_default_paramname;
405  static const double epsilon;
406  static const bool __init;
407  static bool initStaticData();
408 
409  //private data members, please keep the order consistent with declaration lists and logic!
410  std::vector<std::string> extra_param_name;
411  std::vector<double> data;
412 
413  size_t nrOfAllParameters;
414 
415  //data qa containers:
416  bool resampled;
417  std::vector<flag_field> flags;
418  static flag_field zero_flag; //TODO: is there a way to make this const?
419 };
420 
421 } //end namespace
422 
423 #endif
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition: MeteoData.h:107
double & operator()(const size_t &parindex)
Definition: MeteoData.cc:292
bool isNodata() const
Are all the fields set to nodata?
Definition: MeteoData.cc:343
friend std::ostream & operator<<(std::ostream &os, const MeteoData &data)
Definition: MeteoData.cc:421
size_t getNrOfParameters() const
Definition: MeteoData.h:242
bool isGenerated(const size_t &param) const
Definition: MeteoData.cc:367
friend std::istream & operator>>(std::istream &is, MeteoData &data)
Definition: MeteoData.cc:441
StationData meta
The meta data of the measurement.
Definition: MeteoData.h:385
FORMATS
Keywords for selecting the toString formats.
Definition: MeteoData.h:110
@ COMPACT
output optimized to print the content of vector<MeteoData>
Definition: MeteoData.h:113
@ FULL
Shows detailed information, including nodata fields.
Definition: MeteoData.h:112
@ DFLT
Shows detailed information, skipping nodata fields.
Definition: MeteoData.h:111
void setGenerated(const size_t &param, const bool &in_generated=true)
Definition: MeteoData.cc:362
Merge_Type
Available MeteoData merging strategies. When the two stations both have data at a given time step,...
Definition: MeteoData.h:125
@ WINDOW_MERGE
Similar to a full merge but within the time range of station1.
Definition: MeteoData.h:129
@ FULL_MERGE
All timestamps from station2 are brought into station1 even if the timestamps don't match.
Definition: MeteoData.h:128
@ STRICT_MERGE
Station1 receives data from station2 only for common timestamps.
Definition: MeteoData.h:126
@ EXPAND_MERGE
If station2 can provide some data before/after station1, this extra data is added to station1.
Definition: MeteoData.h:127
static const std::string & getParameterName(const size_t &parindex)
Definition: MeteoData.cc:159
void setFiltered(const size_t &param, const bool &in_filtered=true)
Definition: MeteoData.cc:352
void standardizeNodata(const double &plugin_nodata)
Standardize nodata values The plugin-specific nodata values are replaced by MeteoIO's internal nodata...
Definition: MeteoData.cc:266
static MeteoGrids::Parameters findGridParam(const Parameters &mpar)
Definition: MeteoData.cc:177
bool operator!=(const MeteoData &in) const
Operator that tests for inequality.
Definition: MeteoData.h:379
void reset()
Resets all the meteo parameters to IOUtils::nodata NOTE: member vars date and resampled are not affec...
Definition: MeteoData.cc:257
static void merge(std::vector< MeteoData > &vec1, const std::vector< MeteoData > &vec2, const bool &simple_merge=false, const Merge_Conflicts &conflicts_strategy=CONFLICTS_PRIORITY_FIRST)
Simple merge strategy for vectors containing meteodata for a given timestamp. If some fields of the M...
Definition: MeteoData.cc:605
static Parameters findMeteoParam(const MeteoGrids::Parameters &gpar)
Definition: MeteoData.cc:184
bool param_exists(const std::string &parname) const
Check whether a certain parameter is a part of this MeteoData instance.
Definition: MeteoData.cc:204
Date date
Timestamp of the measurement.
Definition: MeteoData.h:384
bool isFiltered(const size_t &param) const
Definition: MeteoData.cc:357
const std::string getStationID() const
Definition: MeteoData.h:389
void setResampled(const bool &in_resampled)
Definition: MeteoData.h:224
static std::set< std::string > listAvailableParameters(const std::vector< MeteoData > &vecMeteo)
List the parameters that have a least one valid value in a vector of MeteoData.
Definition: MeteoData.cc:787
size_t addParameter(const std::string &i_paramname)
Add another variable to the MeteoData object, a double value will be added and the nrOfParameters inc...
Definition: MeteoData.cc:219
bool isResampled() const
Definition: MeteoData.h:223
bool hasConflicts(const MeteoData &meteo2) const
Check for data conflicts between two MeteoData objects Conflicts are defined as two identical data fi...
Definition: MeteoData.cc:764
Parameters
this enum provides indexed access to meteorological fields
Definition: MeteoData.h:144
@ P
Air pressure.
Definition: MeteoData.h:145
@ HS
Height of snow.
Definition: MeteoData.h:150
@ ISWR
Incoming short wave radiation.
Definition: MeteoData.h:155
@ TAU_CLD
Cloud transmissivity or ISWR/ISWR_clear_sky.
Definition: MeteoData.h:157
@ VW
Wind velocity.
Definition: MeteoData.h:151
@ VW_MAX
Maximum wind velocity.
Definition: MeteoData.h:153
@ PSUM
Water equivalent of precipitations, either solid or liquid.
Definition: MeteoData.h:158
@ PSUM_PH
Precipitation phase: between 0 (fully solid) and 1(fully liquid)
Definition: MeteoData.h:159
@ TA
Air temperature.
Definition: MeteoData.h:146
@ TSS
Temperature of the snow surface.
Definition: MeteoData.h:149
@ ILWR
Incoming long wave radiation (downwelling)
Definition: MeteoData.h:156
@ firstparam
Definition: MeteoData.h:144
@ RH
Relative humidity.
Definition: MeteoData.h:147
@ lastparam
Definition: MeteoData.h:160
@ TSG
Temperature of the ground surface.
Definition: MeteoData.h:148
@ DW
Wind direction.
Definition: MeteoData.h:152
@ RSWR
Reflected short wave radiation.
Definition: MeteoData.h:154
static MeteoData::Merge_Conflicts getMergeConflicts(std::string merge_conflicts)
Parse a string containing a merge conflcits type and return the proper enum member for it.
Definition: MeteoData.cc:475
static const size_t nrOfParameters
holds the number of meteo parameters stored in MeteoData
Definition: MeteoData.h:387
bool operator<(const MeteoData &in) const
so vectors can be sorted by timestamps
Definition: MeteoData.h:380
const std::string toString(const FORMATS format=DFLT) const
Print the content of the current object.
Definition: MeteoData.cc:382
void setResampledParam(const size_t &param, const bool &in_resampled=true)
Definition: MeteoData.cc:372
static MeteoData::Merge_Type getMergeType(std::string merge_type)
Parse a string containing a merge type and return the proper enum member for it.
Definition: MeteoData.cc:464
static void unifyMeteoData(METEO_SET &vecMeteo)
Ensure all elements in a METEO_SET have the same parameters.
Definition: MeteoData.cc:802
static size_t getStaticParameterIndex(const std::string &parname)
Definition: MeteoData.cc:167
static size_t mergeTimeSeries(std::vector< MeteoData > &vec1, const std::vector< MeteoData > &vec2, const Merge_Type &strategy=STRICT_MERGE, const Merge_Conflicts &conflicts_strategy=CONFLICTS_PRIORITY_FIRST)
Simple merge strategy for two vectors containing meteodata time series for two stations....
Definition: MeteoData.cc:495
const std::string & getNameForParameter(const size_t &parindex) const
Definition: MeteoData.cc:195
Merge_Conflicts
Available MeteoData conflict resolution strategies. When two stations are merged, there is a merge co...
Definition: MeteoData.h:137
@ CONFLICTS_PRIORITY_LAST
Station2 has priority over station 1.
Definition: MeteoData.h:139
@ CONFLICTS_AVERAGE
The merged value is the average of station1 and station2.
Definition: MeteoData.h:140
@ CONFLICTS_PRIORITY_FIRST
Station1 has priority over station 2.
Definition: MeteoData.h:138
bool isResampledParam(const size_t &param) const
Definition: MeteoData.cc:377
void setDate(const Date &in_date)
A setter function for the measurement date.
Definition: MeteoData.h:194
bool operator==(const MeteoData &) const
Operator that tests for equality.
Definition: MeteoData.cc:275
bool operator>(const MeteoData &in) const
so vectors can be sorted by timestamps
Definition: MeteoData.h:381
size_t getParameterIndex(const std::string &parname) const
Definition: MeteoData.cc:328
MeteoData(void)
The default constructor initializing every double attribute to nodata and the Date to julian==0....
Definition: MeteoData.cc:237
A class to represent the meteorological parameters that could be contained in a grid....
Definition: MeteoData.h:43
static const std::string getParameterName(const size_t &parindex)
Definition: MeteoData.cc:82
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition: MeteoData.h:46
@ PSUM_L
Water equivalent of liquid precipitation.
Definition: MeteoData.h:65
@ OLWR
Outgoing long wave radiation.
Definition: MeteoData.h:59
@ TSS
Temperature snow surface.
Definition: MeteoData.h:68
@ firstparam
Definition: MeteoData.h:46
@ TSG
Temperature ground surface.
Definition: MeteoData.h:67
@ TA
Air temperature.
Definition: MeteoData.h:47
@ VW
Wind velocity.
Definition: MeteoData.h:51
@ ISWR
Incoming short wave radiation.
Definition: MeteoData.h:54
@ P
Air pressure.
Definition: MeteoData.h:70
@ SLOPE
DEM slope angle.
Definition: MeteoData.h:81
@ V
North component of wind.
Definition: MeteoData.h:73
@ DEM
Digital Elevation Model.
Definition: MeteoData.h:79
@ ISWR_DIFF
Incoming short wave, diffuse.
Definition: MeteoData.h:56
@ AZI
DEM slope azimuth.
Definition: MeteoData.h:82
@ RSNO
Snow mean density.
Definition: MeteoData.h:76
@ ISWR_DIR
Incoming short wave, direct.
Definition: MeteoData.h:57
@ PSUM_S
Water equivalent of solid precipitation.
Definition: MeteoData.h:66
@ TD
Dew Point temperature.
Definition: MeteoData.h:50
@ W
Vertical component of wind.
Definition: MeteoData.h:74
@ VW_MAX
Maximum wind velocity.
Definition: MeteoData.h:53
@ CLD
Total cloud cover in oktas (see https://en.wikipedia.org/wiki/Okta)
Definition: MeteoData.h:61
@ lastparam
Definition: MeteoData.h:83
@ TAU_CLD
Cloud transmissivity or ISWR/ISWR_clear_sky.
Definition: MeteoData.h:60
@ TSOIL
Temperature within the soil, at a given depth.
Definition: MeteoData.h:69
@ PSUM
Water equivalent of precipitations, either solid or liquid.
Definition: MeteoData.h:63
@ U
East component of wind.
Definition: MeteoData.h:72
@ ILWR
Incoming long wave radiation.
Definition: MeteoData.h:58
@ P_SEA
Sea level air pressure.
Definition: MeteoData.h:71
@ RH
Relative humidity.
Definition: MeteoData.h:48
@ RSWR
Reflected short wave radiation.
Definition: MeteoData.h:55
@ ROT
Total generated runoff.
Definition: MeteoData.h:77
@ SHADE
Hillshade.
Definition: MeteoData.h:80
@ QI
Specific humidity.
Definition: MeteoData.h:49
@ ALB
Albedo.
Definition: MeteoData.h:78
@ PSUM_PH
Precipitation phase, between 0 (fully solid) and 1 (fully liquid)
Definition: MeteoData.h:64
@ HS
Height of snow.
Definition: MeteoData.h:62
@ DW
Wind direction.
Definition: MeteoData.h:52
@ SWE
Snow Water Equivalent.
Definition: MeteoData.h:75
static const std::string getParameterDescription(const size_t &parindex, const bool &allow_ws=true)
Definition: MeteoData.cc:90
static const size_t nrOfParameters
holds the number of meteo parameters stored in MeteoData
Definition: MeteoData.h:85
static size_t getParameterIndex(const std::string &parname)
Definition: MeteoData.cc:112
static const std::string getParameterUnits(const size_t &parindex)
Definition: MeteoData.cc:104
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition: StationData.h:41
std::string stationID
ID of the Station, typically a short string.
Definition: StationData.h:132
@ filtered
Definition: IOUtils.h:56
@ generated
Definition: IOUtils.h:58
Definition: Config.cc:30
std::vector< MeteoData > METEO_SET
Definition: MeteoData.h:31