WSL/SLF GitLab Repository

MeteoData.h 11.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/***********************************************************************************/
/*  Copyright 2009 WSL Institute for Snow and Avalanche Research    SLF-DAVOS      */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
18
19
#ifndef METEODATA_H
#define METEODATA_H
20

21
22
#include <meteoio/dataClasses/Date.h>
#include <meteoio/dataClasses/StationData.h>
23
24
25
26
27
28
#include <meteoio/IOUtils.h>

#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
29
#include <map>
30
31
32

namespace mio {

33
class MeteoData; //forward declaration
34
typedef std::vector<MeteoData> METEO_SET;
35

36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * @class MeteoGrids
 * @brief A class to represent the meteorological parameters that could be contained in a grid.
 * This should be very close to MeteoData with a few additions (like the wind u,v,w)
 * @ingroup data_str
 * @author Mathias Bavay
 * @date   2011-12-22
 */

class MeteoGrids {
	public:
		/// \anchor meteogrids this enum provides names for possible meteogrids (from an ARPS file, etc)
		enum Parameters {firstparam=0,
49
50
51
52
53
54
55
56
57
58
59
60
61
62
				TA=firstparam, ///< Air temperature
				RH, ///< Relative humidity
				QI, ///< Specific humidity
				TD, ///< Dew Point temperature
				VW, ///< Wind velocity
				DW, ///< Wind direction
				VW_MAX, ///< Maximum wind velocity
				ISWR, ///< Incoming short wave radiation
				RSWR, ///< Reflected short wave radiation
				ISWR_DIFF, ///< Incoming short wave, diffuse
				ISWR_DIR, ///< Incoming short wave, direct
				ILWR, ///< Incoming long wave radiation
				TAU_CLD, ///< Cloud transmissivity or ISWR/ISWR_clear_sky
				HS, ///< Height of snow
63
64
65
66
				PSUM, ///< Water equivalent of precipitations, either solid or liquid
				PSUM_PH, ///<  Precipitation phase, between 0 (fully solid) and 1 (fully liquid)
				PSUM_L, ///< Water equivalent of liquid precipitation
				PSUM_S, ///< Water equivalent of solid precipitation
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
				TSG, ///< Temperature ground surface
				TSS, ///< Temperature snow surface
				P, ///< Air pressure
				P_SEA, ///< Sea level air pressure
				U, ///< East component of wind
				V, ///< North component of wind
				W, ///< Vertical component of wind
				SWE, ///< Snow Water Equivalent
				ROT, ///< Total generated runoff
				ALB, ///< Albedo
				DEM, ///< Digital Elevation Model
				SHADE, ///< Hillshade
				SLOPE, ///< DEM slope angle
				AZI, ///< DEM slope azimuth
				lastparam=AZI};
82
83
84

		static const size_t nrOfParameters; ///<holds the number of meteo parameters stored in MeteoData
		static const std::string& getParameterName(const size_t& parindex);
85
		static size_t getParameterIndex(const std::string& parname);
86
87
88
89
90
91
92
93

	private:
		//static methods
		static std::vector<std::string> paramname;
		static const bool __init;    ///<helper variable to enable the init of static collection data
		static bool initStaticData();///<initialize the static map meteoparamname
};

94
95
96
97
/**
 * @class MeteoData
 * @brief A class to represent a singular measurement received from one station at a certain time (represented by the Date object)
 *
98
 * @ingroup data_str
99
100
101
102
103
104
105
 * @author Thomas Egger
 * @date   2008-12-05
 */

class MeteoData {
	public:
		/// \anchor meteoparam this enum provides indexed access to meteorological fields
106
		enum Parameters {firstparam=0,
107
108
		                 P=firstparam, ///< Air pressure
		                 TA, ///< Air temperature
109
		                 RH, ///< Relative humidity
110
111
112
		                 TSG, ///< Temperature of the ground surface
		                 TSS, ///< Temperature of the snow surface
		                 HS, ///< Height of snow
113
114
		                 VW, ///< Wind velocity
		                 DW, ///< Wind direction
Fierz's avatar
Fierz committed
115
		                 VW_MAX, ///< Maximum wind velocity
116
		                 RSWR, ///< Reflected short wave radiation
117
		                 ISWR, ///< Incoming short wave radiation
Fierz's avatar
Fierz committed
118
		                 ILWR, ///< Incoming long wave radiation (downwelling)
119
		                 TAU_CLD, ///< Cloud transmissivity or ISWR/ISWR_clear_sky
120
		                 PSUM, ///< Water equivalent of precipitations, either solid or liquid
121
122
				 PSUM_PH, ///< Precipitation phase: between 0 (fully solid) and 1(fully liquid)
		                 lastparam=PSUM_PH};
123

124
		static const std::string& getParameterName(const size_t& parindex);
125

126
127
128
129
130
131
132
		/**
		 * @brief The default constructor initializing every double attribute to nodata and the Date to julian==0.0
		 */
		MeteoData(void);

		/**
		* @brief A constructor that sets the measurment time
133
		* @param in_date A Date object representing the time of the measurement
134
		*/
135
		MeteoData(const Date& in_date);
136

137
138
		/**
		* @brief A constructor that sets the measurment time and meta data
139
		* @param date_in A Date object representing the time of the measurement
140
141
142
143
		* @param meta_in A StationData object containing the meta data
		*/
		MeteoData(const Date& date_in, const StationData& meta_in);

144
145
		/**
		* @brief A setter function for the measurement date
146
		* @param in_date A Date object representing the time of the measurement
147
		*/
148
		void setDate(const Date& in_date);
149

150
		/**
151
		* @brief Add another variable to the MeteoData object,
152
153
		*        a double value will be added and the nrOfParameters increased
		* @param i_paramname A parameter name, e.g. "VSWR"
154
		* @return A size_t denoting the index of the the parameter added
155
		*/
156
		size_t addParameter(const std::string& i_paramname);
157

158
159
		/**
		* @brief Check whether a certain parameter is a part of this MeteoData instance
160
		* @param parname A string parameter, representing a meteo parameter, e.g. "VSWR"
161
162
		* @return A boolean indicating whether the parameter is a part of the object
		*/
163
		bool param_exists(const std::string& parname) const;
164
165
166
167
168

		/**
		 * @brief Resets all the meteo parameters to IOUtils::nodata
		 *        NOTE: member vars date and resampled are not affected
		 */
169
170
		void reset();

171
		bool isResampled() const;
172
173
174
175
		void setResampled(const bool&);

		void standardizeNodata(const double& plugin_nodata);

176
177
178
179
180
		double& operator()(const size_t& parindex);
		const double& operator()(const size_t& parindex) const;
		double& operator()(const std::string& parname);
		const double& operator()(const std::string& parname) const;

181
182
		const std::string& getNameForParameter(const size_t& parindex) const;
		size_t getParameterIndex(const std::string& parname) const;
183
		size_t getNrOfParameters() const;
184

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
		/**
		 * @brief Simple merge strategy for vectors containing meteodata for a given timestamp.
		 * If some fields of the MeteoData objects given in the first vector are nodata, they will be
		 * filled by the matching field from the MeteoData objects given in the second vector (if the
		 * same location exist). Stations only occuring in the second vector will be appended to the
		 * first vector.
		 * @note two stations are considered to be identical if they fit within a 5m 3D box
		 * @note the vectors are supposed to contain data at a given time stamp. If both vectors don't match a
		 * common time stamp, nothing is done
		 * @param vec1 reference vector, highest priority
		 * @param vec2 extra vector to merge, lowest priority
		 * @param simple_merge if set to true, assume all stations are unique (ie. simply append vec2 to vec1)
		 */
		static void merge(std::vector<MeteoData>& vec1, const std::vector<MeteoData>& vec2, const bool& simple_merge=false);

		/**
		 * @brief Simple merge strategy for vectors containing meteodata for a given timestamp.
		 * If some fields of the MeteoData objects given in the first vector are nodata, they will be
		 * filled by the matching field from the MeteoData object given in the second argument (if the
		 * same location exist). If meteo2 does not describe a station already in vec, it will simply be appended.
		 * @note two stations are considered to be identical if they fit within a 5m 3D box
		 * @note the datasets are supposed to contain data at a given time stamp. If vec1 and meteo2 don't match a
		 * common time stamp, nothing is done
		 * @param vec reference vector, highest priority
		 * @param meteo2 extra MeteoData object to merge, lowest priority
		 * @param simple_merge if set to true, assume all stations are unique (ie.simply append meteo2 to vec)
		 */
		static void merge(std::vector<MeteoData>& vec, const MeteoData& meteo2, const bool& simple_merge=false);

214
215
216
217
218
219
220
221
222
223
224
225
226
		/**
		 * @brief Simple merge strategy within a vector of MeteoData.
		 * All stations that can be considerd as identical (see note) will be merged in case of fields set to nodata. 
		 * The priority goes to the stations at the begining of the vector. For example, if vec[0] has TA but no HS and 
		 * vec[3] has TA and HS, then vec[0] will <i>keep</i> its TA and get HS from vec[3]. If vec[2] is further away than
		 * 5m from vec[0], then it can not contribute to vec[0].
		 * @note two stations are considered to be identical if they fit within a 5m 3D box
		 * @note the datasets are supposed to contain data at a given time stamp. If the stations don't match a
		 * common time stamp, nothing is done
		 * @param vec vector of stations
		 */
		static void merge(std::vector<MeteoData>& vec);
		
227
228
229
230
231
232
233
234
		/**
		 * @brief Simple merge strategy.
		 * If some fields of the object given as first argument are nodata, they will be filled by the matching field from the
		 * provided argument.
		 * @note no check on the location is performed, ie. it can merge data from stations kilometers away...
		 * @param meteo1 reference MeteoData, highest priority
		 * @param meteo2 extra MeteoData to merge, lowest priority
		 */
235
		static MeteoData merge(MeteoData meteo1, const MeteoData& meteo2);
236
237
238
239
240
241
242
243
244
245

		/**
		 * @brief Simple merge strategy.
		 * If some fields of the current object are nodata, they will be filled by the matching field from the
		 * provided argument.
		 * @note no check on the location is performed, ie. it can merge data from stations kilometers away...
		 * @param meteo2 extra MeteoData to merge, lowest priority
		 */
		void merge(const MeteoData& meteo2);

246
247
248
		const std::string toString() const;
		friend std::iostream& operator<<(std::iostream& os, const MeteoData& data);
		friend std::iostream& operator>>(std::iostream& is, MeteoData& data);
249
250
251
252
253
254
255

		//Comparison operators
		bool operator==(const MeteoData&) const; ///<Operator that tests for equality
		bool operator!=(const MeteoData&) const; ///<Operator that tests for inequality

		//direct access allowed
		Date date; ///<Timestamp of the measurement
256
		StationData meta; ///<The meta data of the measurement
257

258
259
		static const size_t nrOfParameters; ///<holds the number of meteo parameters stored in MeteoData

260
	private:
261
		//static methods
262
		static std::vector<std::string> s_default_paramname; ///<Associate a name with meteo parameters in Parameters
263
		static const double epsilon; ///<for comparing fields
264
		static const bool __init;    ///<helper variable to enable the init of static collection data
265
		static bool initStaticData();///<initialize the static map meteoparamname
266

267
		//private data members, please keep the order consistent with declaration lists and logic!
268
		std::vector<std::string> extra_param_name;
269
		std::vector<double> data;
270
		size_t nrOfAllParameters;
271
		bool resampled; ///<set this to true if MeteoData is result of resampling
272
273
274
275
276
};

} //end namespace

#endif