MeteoIODoc 20260914.909d27f1
Environmental timeseries pre-processing
Loading...
Searching...
No Matches
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#include <map>
29#include <cmath>
30
31namespace mio {
32
33class MeteoData; //forward declaration
34typedef std::vector<MeteoData> METEO_SET;
35
46 public:
73 P,
75 U,
76 V,
77 W,
87
88 static const size_t nrOfParameters;
89 static size_t getParameterIndex(const std::string& parname);
90 static const std::string getParameterName(const size_t& parindex);
91 static const std::string getParameterDescription(const size_t& parindex, const bool& allow_ws=true);
92 static const std::string getParameterUnits(const size_t& parindex);
93
94 private:
95 //static methods
96 static std::vector<std::string> paramname, description, units;
97 static const bool __init;
98 static bool initStaticData();
99};
100
111 public:
113 typedef enum {
116 COMPACT
118
134
145
166
167 static Parameters toParameter(const std::string& paramStr);
168 static std::string parToString(const Parameters& param);
169
170 static const std::string& getParameterName(const size_t& parindex);
171
172 static size_t getStaticParameterIndex(const std::string& parname);
173
179 int width;
180 };
181
182 static const std::map<std::string, ParameterFormatting> parameterFormatting;
183
191 static double getRoundedValue(const std::string& parname, const double& value, int& width);
192
196 MeteoData(void);
197
202 MeteoData(const Date& in_date);
203
208 MeteoData(const StationData& meta_in);
209
215 MeteoData(const Date& date_in, const StationData& meta_in);
216
221 void setDate(const Date& in_date) {date = in_date;}
222
229 size_t addParameter(const std::string& i_paramname);
230
236 bool param_exists(const std::string& parname) const;
237
242 void reset();
243
248 bool isNodata() const;
249
250 bool isResampled() const {return resampled;}
251 void setResampled(const bool& in_resampled) {resampled = in_resampled;}
252
253 bool isFiltered(const size_t& param) const;
254 void setFiltered(const size_t& param, const bool& in_filtered = true);
255 bool isGenerated(const size_t& param) const;
256 void setGenerated(const size_t& param, const bool& in_generated = true);
257 bool isResampledParam(const size_t& param) const;
258 void setResampledParam(const size_t& param, const bool& in_resampled = true);
259
260 void standardizeNodata(const double& plugin_nodata);
261
262 double& operator()(const size_t& parindex);
263 const double& operator()(const size_t& parindex) const;
264 double& operator()(const std::string& parname);
265 const double& operator()(const std::string& parname) const;
266
267 const std::string& getNameForParameter(const size_t& parindex) const;
268 size_t getParameterIndex(const std::string& parname) const;
269 size_t getNrOfParameters() const {return nrOfAllParameters;}
270 size_t getOccurencesOfParameter(const Parameters& par, const std::set<std::string>& additional_parameters = std::set<std::string>()) const;
271 std::vector<double> getHeightsForParameter(const std::string& in_parname, bool include_default = true, const std::set<std::string>& additional_parameters = std::set<std::string>()) const;
272 size_t listUnknownParameters(const std::set<std::string>& additional_params = std::set<std::string>()) const;
273 static std::string convertHeightToString(const double& height);
274
275
276 static bool getTypeAndNo(const std::string& parname, std::string& par, double& number, const std::set<std::string>& additional_parameters = std::set<std::string>());
277 static bool sameParameterType(const std::string& par1, const std::string& par2, const std::set<std::string>& additional_parameters = std::set<std::string>());
278 static std::vector<std::string> retrieveAllHeightsForParam(const std::set<std::string>& available_parameters, const std::string& parname, const std::set<std::string>& additional_parameters = std::set<std::string>());
279 static std::vector<std::string> retrieveAllParametersAtHeight(const std::set<std::string>& available_parameters, const double& height, const std::set<std::string>& additional_parameters = std::set<std::string>());
280 static std::set<double> retrieveAllHeights(const std::set<std::string>& available_parameters, const std::set<std::string>& additional_parameters = std::set<std::string>());
281 static std::set<std::string> retriveUniqueParameters(const std::set<std::string>& available_parameters, const std::set<std::string>& additional_parameters=std::set<std::string>());
282 static std::vector<std::string> sortListByParams(const std::vector<std::string>& param_list, const std::set<std::string>& available_parameters = std::set<std::string>());
283
284
287
300 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);
301
316 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);
317
331 static void merge(std::vector<MeteoData>& vec, const MeteoData& meteo2, const bool& simple_merge=false, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
332
346 static void merge(std::vector<MeteoData>& vec, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
347
358 static MeteoData merge(MeteoData meteo1, const MeteoData& meteo2, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
359
369 bool merge(const MeteoData& meteo2, const Merge_Conflicts& conflicts_strategy=CONFLICTS_PRIORITY_FIRST);
370
378 bool hasConflicts(const MeteoData& meteo2) const;
379
385 static MeteoData::Merge_Type getMergeType(std::string merge_type);
386
392 static MeteoData::Merge_Conflicts getMergeConflicts(std::string merge_conflicts);
393
399 static std::set<std::string> listAvailableParameters(const std::vector<MeteoData>& vecMeteo);
400
401
408 static void unifyMeteoData(METEO_SET &vecMeteo);
409
415 const std::string toString(const FORMATS format=DFLT) const;
416 friend std::ostream& operator<<(std::ostream& os, const MeteoData& data);
417 friend std::istream& operator>>(std::istream& is, MeteoData& data);
418
419 //Comparison operators
420 bool operator==(const MeteoData&) const;
421 inline bool operator!=(const MeteoData& in) const {return !(*this==in);}
422 inline bool operator<(const MeteoData& in) const {return (this->date < in.date);}
423 inline bool operator>(const MeteoData& in) const {return (this->date > in.date);}
424
425 //direct access allowed
428
429 static const size_t nrOfParameters;
430
431 const std::string getStationID() const {return meta.stationID;}
432
433 private:
434
435 struct flag_field { //object to hold all data quality / datapoint meta flags
436 bool filtered : 1;
437 bool resampled : 1;
438 bool generated : 1;
439 bool created : 1; //TODO: not yet filled in the creators!
440 bool : 1; //leave one empty for future flag
441 unsigned int extra_flag : 3; //rest of byte space could be any 3-bit-value
442 float offset; //an offset that has been applied to the data at this time step
443 };
444
445 //static methods
446 static std::vector<std::string> s_default_paramname;
447 static const double epsilon;
448 static const bool __init;
449 static bool initStaticData();
450
451 //private data members, please keep the order consistent with declaration lists and logic!
452 std::vector<std::string> extra_param_name;
453 std::vector<double> data;
454
455 size_t nrOfAllParameters;
456
457 //data qa containers:
458 bool resampled;
459 std::vector<flag_field> flags;
460 static flag_field zero_flag; //TODO: is there a way to make this const?
461};
462
463} //end namespace
464
465#endif
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition Date.h:86
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition MeteoData.h:110
double & operator()(const size_t &parindex)
Definition MeteoData.cc:534
bool isNodata() const
Are all the fields set to nodata?
Definition MeteoData.cc:624
size_t getNrOfParameters() const
Definition MeteoData.h:269
bool isGenerated(const size_t &param) const
Definition MeteoData.cc:648
friend std::istream & operator>>(std::istream &is, MeteoData &data)
Definition MeteoData.cc:722
StationData meta
The meta data of the measurement.
Definition MeteoData.h:427
FORMATS
Keywords for selecting the toString formats.
Definition MeteoData.h:113
@ COMPACT
output optimized to print the content of vector<MeteoData>
Definition MeteoData.h:116
@ FULL
Shows detailed information, including nodata fields.
Definition MeteoData.h:115
@ DFLT
Shows detailed information, skipping nodata fields.
Definition MeteoData.h:114
void setGenerated(const size_t &param, const bool &in_generated=true)
Definition MeteoData.cc:643
Merge_Type
Available MeteoData merging strategies. When the two stations both have data at a given time step,...
Definition MeteoData.h:128
@ WINDOW_MERGE
Similar to a full merge but within the time range of station1.
Definition MeteoData.h:132
@ FULL_MERGE
All timestamps from station2 are brought into station1 even if the timestamps don't match.
Definition MeteoData.h:131
@ STRICT_MERGE
Station1 receives data from station2 only for common timestamps.
Definition MeteoData.h:129
@ EXPAND_MERGE
If station2 can provide some data before/after station1, this extra data is added to station1.
Definition MeteoData.h:130
static const std::string & getParameterName(const size_t &parindex)
Definition MeteoData.cc:237
static std::set< std::string > retriveUniqueParameters(const std::set< std::string > &available_parameters, const std::set< std::string > &additional_parameters=std::set< std::string >())
Definition MeteoData.cc:398
void setFiltered(const size_t &param, const bool &in_filtered=true)
Definition MeteoData.cc:633
void standardizeNodata(const double &plugin_nodata)
Standardize nodata values The plugin-specific nodata values are replaced by MeteoIO's internal nodata...
Definition MeteoData.cc:510
static MeteoGrids::Parameters findGridParam(const Parameters &mpar)
Definition MeteoData.cc:421
static bool sameParameterType(const std::string &par1, const std::string &par2, const std::set< std::string > &additional_parameters=std::set< std::string >())
Definition MeteoData.cc:300
static std::string convertHeightToString(const double &height)
Definition MeteoData.cc:313
bool operator!=(const MeteoData &in) const
Operator that tests for inequality.
Definition MeteoData.h:421
void reset()
Resets all the meteo parameters to IOUtils::nodata NOTE: member vars date and resampled are not affec...
Definition MeteoData.cc:501
int precision
Number of decimal places.
Definition MeteoData.h:178
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:893
static Parameters findMeteoParam(const MeteoGrids::Parameters &gpar)
Definition MeteoData.cc:428
bool param_exists(const std::string &parname) const
Check whether a certain parameter is a part of this MeteoData instance.
Definition MeteoData.cc:448
static const std::map< std::string, ParameterFormatting > parameterFormatting
Definition MeteoData.h:182
Date date
Timestamp of the measurement.
Definition MeteoData.h:426
static std::string parToString(const Parameters &param)
Definition MeteoData.cc:172
bool isFiltered(const size_t &param) const
Definition MeteoData.cc:638
static std::vector< std::string > sortListByParams(const std::vector< std::string > &param_list, const std::set< std::string > &available_parameters=std::set< std::string >())
Definition MeteoData.cc:337
const std::string getStationID() const
Definition MeteoData.h:431
void setResampled(const bool &in_resampled)
Definition MeteoData.h:251
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:1075
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:463
bool isResampled() const
Definition MeteoData.h:250
size_t getOccurencesOfParameter(const Parameters &par, const std::set< std::string > &additional_parameters=std::set< std::string >()) const
Definition MeteoData.cc:606
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:1052
Parameters
this enum provides indexed access to meteorological fields
Definition MeteoData.h:147
@ P
Air pressure.
Definition MeteoData.h:148
@ HS
Height of snow.
Definition MeteoData.h:155
@ ISWR
Incoming short wave radiation.
Definition MeteoData.h:160
@ TAU_CLD
Cloud transmissivity or ISWR/ISWR_clear_sky.
Definition MeteoData.h:162
@ VW
Wind velocity.
Definition MeteoData.h:156
@ VW_MAX
Maximum wind velocity.
Definition MeteoData.h:158
@ PSUM
Water equivalent of precipitations, either solid or liquid.
Definition MeteoData.h:163
@ PSUM_PH
Precipitation phase: between 0 (fully solid) and 1(fully liquid)
Definition MeteoData.h:164
@ TSNOW
Temperature within the snow.
Definition MeteoData.h:154
@ TA
Air temperature.
Definition MeteoData.h:149
@ TSS
Temperature of the snow surface.
Definition MeteoData.h:152
@ TSOIL
Temperature within the soil.
Definition MeteoData.h:153
@ ILWR
Incoming long wave radiation (downwelling)
Definition MeteoData.h:161
@ firstparam
Definition MeteoData.h:147
@ RH
Relative humidity.
Definition MeteoData.h:150
@ lastparam
Definition MeteoData.h:165
@ TSG
Temperature of the ground surface.
Definition MeteoData.h:151
@ DW
Wind direction.
Definition MeteoData.h:157
@ RSWR
Reflected short wave radiation.
Definition MeteoData.h:159
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:756
static const size_t nrOfParameters
holds the number of meteo parameters stored in MeteoData
Definition MeteoData.h:429
bool operator<(const MeteoData &in) const
so vectors can be sorted by timestamps
Definition MeteoData.h:422
const std::string toString(const FORMATS format=DFLT) const
Print the content of the current object.
Definition MeteoData.cc:663
static std::vector< std::string > retrieveAllHeightsForParam(const std::set< std::string > &available_parameters, const std::string &parname, const std::set< std::string > &additional_parameters=std::set< std::string >())
Definition MeteoData.cc:358
void setResampledParam(const size_t &param, const bool &in_resampled=true)
Definition MeteoData.cc:653
static std::vector< std::string > retrieveAllParametersAtHeight(const std::set< std::string > &available_parameters, const double &height, const std::set< std::string > &additional_parameters=std::set< std::string >())
Definition MeteoData.cc:383
static Parameters toParameter(const std::string &paramStr)
Definition MeteoData.cc:147
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:745
static void unifyMeteoData(METEO_SET &vecMeteo)
Ensure all elements in a METEO_SET have the same parameters.
Definition MeteoData.cc:1101
int width
Minimum field width.
Definition MeteoData.h:179
static size_t getStaticParameterIndex(const std::string &parname)
Definition MeteoData.cc:411
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:776
static bool getTypeAndNo(const std::string &parname, std::string &par, double &number, const std::set< std::string > &additional_parameters=std::set< std::string >())
Definition MeteoData.cc:261
static std::set< double > retrieveAllHeights(const std::set< std::string > &available_parameters, const std::set< std::string > &additional_parameters=std::set< std::string >())
Definition MeteoData.cc:369
const std::string & getNameForParameter(const size_t &parindex) const
Definition MeteoData.cc:439
Merge_Conflicts
Available MeteoData conflict resolution strategies. When two stations are merged, there is a merge co...
Definition MeteoData.h:140
@ CONFLICTS_PRIORITY_LAST
Station2 has priority over station 1.
Definition MeteoData.h:142
@ CONFLICTS_AVERAGE
The merged value is the average of station1 and station2.
Definition MeteoData.h:143
@ CONFLICTS_PRIORITY_FIRST
Station1 has priority over station 2.
Definition MeteoData.h:141
friend std::ostream & operator<<(std::ostream &os, const MeteoData &data)
Definition MeteoData.cc:702
bool isResampledParam(const size_t &param) const
Definition MeteoData.cc:658
size_t listUnknownParameters(const std::set< std::string > &additional_params=std::set< std::string >()) const
Definition MeteoData.cc:1090
void setDate(const Date &in_date)
A setter function for the measurement date.
Definition MeteoData.h:221
bool operator==(const MeteoData &) const
Operator that tests for equality.
Definition MeteoData.cc:519
static double getRoundedValue(const std::string &parname, const double &value, int &width)
Get the rounded value for a parameter according to its formatting rules.
Definition MeteoData.cc:224
bool operator>(const MeteoData &in) const
so vectors can be sorted by timestamps
Definition MeteoData.h:423
std::vector< double > getHeightsForParameter(const std::string &in_parname, bool include_default=true, const std::set< std::string > &additional_parameters=std::set< std::string >()) const
Definition MeteoData.cc:586
size_t getParameterIndex(const std::string &parname) const
Definition MeteoData.cc:570
MeteoData(void)
The default constructor initializing every double attribute to nodata and the Date to julian==0....
Definition MeteoData.cc:481
Formatting information for a parameter (precision and width)
Definition MeteoData.h:177
A class to represent the meteorological parameters that could be contained in a grid....
Definition MeteoData.h:45
static const std::string getParameterName(const size_t &parindex)
Definition MeteoData.cc:85
Parameters
this enum provides names for possible meteogrids (from an ARPS file, etc)
Definition MeteoData.h:48
@ PSUM_L
Water equivalent of liquid precipitation.
Definition MeteoData.h:67
@ OLWR
Outgoing long wave radiation.
Definition MeteoData.h:61
@ TSS
Temperature snow surface.
Definition MeteoData.h:70
@ firstparam
Definition MeteoData.h:48
@ TSG
Temperature ground surface.
Definition MeteoData.h:69
@ TA
Air temperature.
Definition MeteoData.h:49
@ VW
Wind velocity.
Definition MeteoData.h:53
@ ISWR
Incoming short wave radiation.
Definition MeteoData.h:56
@ P
Air pressure.
Definition MeteoData.h:73
@ SLOPE
DEM slope angle.
Definition MeteoData.h:84
@ V
North component of wind.
Definition MeteoData.h:76
@ DEM
Digital Elevation Model.
Definition MeteoData.h:82
@ ISWR_DIFF
Incoming short wave, diffuse.
Definition MeteoData.h:58
@ AZI
DEM slope azimuth.
Definition MeteoData.h:85
@ RSNO
Snow mean density.
Definition MeteoData.h:79
@ ISWR_DIR
Incoming short wave, direct.
Definition MeteoData.h:59
@ PSUM_S
Water equivalent of solid precipitation.
Definition MeteoData.h:68
@ TD
Dew Point temperature.
Definition MeteoData.h:52
@ W
Vertical component of wind.
Definition MeteoData.h:77
@ VW_MAX
Maximum wind velocity.
Definition MeteoData.h:55
@ CLD
Total cloud cover in oktas (see https://en.wikipedia.org/wiki/Okta)
Definition MeteoData.h:63
@ lastparam
Definition MeteoData.h:86
@ TAU_CLD
Cloud transmissivity or ISWR/ISWR_clear_sky.
Definition MeteoData.h:62
@ TSOIL
Temperature within the soil, at a given depth.
Definition MeteoData.h:71
@ PSUM
Water equivalent of precipitations, either solid or liquid.
Definition MeteoData.h:65
@ U
East component of wind.
Definition MeteoData.h:75
@ ILWR
Incoming long wave radiation.
Definition MeteoData.h:60
@ P_SEA
Sea level air pressure.
Definition MeteoData.h:74
@ RH
Relative humidity.
Definition MeteoData.h:50
@ RSWR
Reflected short wave radiation.
Definition MeteoData.h:57
@ TSNOW
Temperature within the snow, at a given depth.
Definition MeteoData.h:72
@ ROT
Total generated runoff.
Definition MeteoData.h:80
@ SHADE
Hillshade.
Definition MeteoData.h:83
@ QI
Specific humidity.
Definition MeteoData.h:51
@ ALB
Albedo.
Definition MeteoData.h:81
@ PSUM_PH
Precipitation phase, between 0 (fully solid) and 1 (fully liquid)
Definition MeteoData.h:66
@ HS
Height of snow.
Definition MeteoData.h:64
@ DW
Wind direction.
Definition MeteoData.h:54
@ SWE
Snow Water Equivalent.
Definition MeteoData.h:78
static const std::string getParameterDescription(const size_t &parindex, const bool &allow_ws=true)
Definition MeteoData.cc:93
static const size_t nrOfParameters
holds the number of meteo parameters stored in MeteoData
Definition MeteoData.h:88
static size_t getParameterIndex(const std::string &parname)
Definition MeteoData.cc:115
static const std::string getParameterUnits(const size_t &parindex)
Definition MeteoData.cc:107
A class to represent meteo stations with attributes like longitude, latitude, etc.
Definition StationData.h:40
std::string stationID
ID of the Station, typically a short string.
Definition StationData.h:131
Definition Config.cc:34
static const double plugin_nodata
Definition GRIBIO.cc:141
std::vector< MeteoData > METEO_SET
Definition MeteoData.h:34