Loading...
Searching...
No Matches
Precipitation.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31
32
33#include <drain/util/BeanLike.h>
34
35#ifndef RACK_PRECIPITATION
36#define RACK_PRECIPITATION
37
38namespace rack {
39
40class Precip : public drain::BeanLike {
41
42public:
43
44
45 Precip(const std::string & name = "", const std::string & description = "") : drain::BeanLike(name, description) { // , parameters(true, ':')
46 this->parameters.separator = ',';
47 }
48
49
50 virtual
51 inline
52 ~Precip(){};
53
55 /*
56 virtual
57 inline
58 void set Parameters(const std::string &p, char assignmentSymbol='=', char separatorSymbol=0){
59
60 drain::Logger mout(__FILE__, __FUNCTION__);
61
62 static const drain::RegExp presetKey("^[a-zA-Z]+");
63
64 if (presetKey.test(p)){
65 std::map<std::string,std::string>::const_iterator it = presets.find(p);
66 if (it != presets.end()){
67 mout.info("applying presets '" , "'" );
68 //setParameters(it->second);
69 BeanLike::setParameters(it->second, assignmentSymbol, separatorSymbol);
70 }
71 else {
72 mout.warn("no preset found for: '" , p , "'" );
73 }
74 }
75 else {
76 BeanLike::setParameters(p, assignmentSymbol, separatorSymbol);
77 }
78
79 initParameters();
80 };
81 */
82
83
84 // virtual
85 // const std::string & getDescription() const;
86
87protected:
88
89 //virtual inline
90 //void initParameters(){};
91
92 // virtual void setParameterReferences() = 0;
93
94 std::map<std::string,std::string> presets;
95
96private:
97
98 //mutable
99 //std::string descriptionExt;
100
101};
102
103class SingleParamPrecip : public Precip {
104
105public:
106
107 virtual
108 double rainRate(double p) const = 0;
109
110protected:
111
112 inline
113 SingleParamPrecip(const std::string & name = "", const std::string & description = ""):
114 Precip(name,description) {
115
116 }
117
118
119};
120
121class DoubleParamPrecip : public Precip {
122
123public:
124
125 virtual
126 double rainRate(double p1, double p2) const = 0;
127
128protected:
129
130 inline
131 DoubleParamPrecip(const std::string & name = "", const std::string & description = ""):
132 Precip(name,description) {
133 }
134
135};
136
137
138
139
141
142public:
143
144 inline
145 PrecipZ(const std::string & name=__FUNCTION__, double a=200.0, double b=1.6) :
146 SingleParamPrecip(name, "Precipitation rate from Z (reflectivity)"), a(a), b(b){
147 parameters.link("a", this->a = a);
148 parameters.link("b", this->b = b);
149 updateBean();
150 };
151
152 inline
153 PrecipZ(const PrecipZ & p) : SingleParamPrecip(p) {
154 parameters.copyStruct(p.getParameters(), p, *this);
155 updateBean();
156 }
157
158 virtual
159 inline
160 void updateBean() const override {
161 aInv = 1.0/a;
162 bInv = 1.0/b;
163 //drain::Logger mout(__FILE__, __FUNCTION__);
164 //mout.warn("coeff:", aInv, bInv);
165 };
166
167
168 inline
169 double rainRate(double dbz) const {
170 return pow(aInv * pow(10.0, dbz*0.10), bInv);// Eq.(1)
171 }
172
173
174 double a;
175 double b;
176
177
178protected:
179
180
181 mutable double aInv;
182 mutable double bInv;
183
184};
185
186class PrecipZrain : public PrecipZ {
187
188public:
189
190 PrecipZrain(double a=200.0, double b=1.6) : PrecipZ(__FUNCTION__, a ,b){
191 presets["Marshall-Palmer"] = "200,1.6";
192 }
193};
194
195class PrecipZsnow : public PrecipZ {
196
197public:
198
199 PrecipZsnow( double a=222.2, double b=1.1111) : PrecipZ(__FUNCTION__, a ,b){
200 //presets["Marshall-Palmer"] = "200,1.6";
201 }
202
203};
204
205
207
208public:
209
210 inline
211 PrecipKDP(double a=21.0, double b=0.72) : SingleParamPrecip(__FUNCTION__, "Precip rate from KDP"), a(a), b(b) {
212 //setParameterReferences();
213 parameters.link("a", a);
214 parameters.link("b", b);
215 presets["Leinonen2012"] = "21,0.72";
216 };
217
218 PrecipKDP(const PrecipKDP & p) : SingleParamPrecip(p) { // copy name?
219 parameters.copyStruct(p.getParameters(), p, *this);
220 //setParameterReferences();
221 //copy(p);
222 };
223
224
225 inline
226 double rainRate(double kdp) const {
227 double r = -1.0;
228 r = a * ::pow(kdp, b); // Eq.(3)
229 return r;
230 }
231
232 double a;
233 double b;
234
235
236};
237
239
240public:
241
242 PrecipZZDR(double a=0.0122, double b=0.820, double c=-2.28) :
243 DoubleParamPrecip(__FUNCTION__, "Precipitation rate from Z and ZDR"), a(a), b(b), c(c) {
244 parameters.link("a", this->a);
245 parameters.link("b", this->b);
246 parameters.link("c", this->c);
247 // setParameterReferences();
248 };
249
250 inline
251 PrecipZZDR(const PrecipZZDR & p) : DoubleParamPrecip(p) {
252 parameters.copyStruct(p.getParameters(), p, *this);
253 //setParameterReferences();
254 // copy(p);
255 };
256
257 //inline virtual ~PrecipZZDR(){};
258
259 inline
260 double rainRate(double dbz, double zdr) const {
261 double r = -1.0;
262 r = a * ::pow(dbz, b) * pow(zdr, c);// Eq.(2)
263 return r;
264 }
265
266 double a;
267 double b;
268 double c;
269
270
271};
272
274
275public:
276
277 inline
278 PrecipKDPZDR(double a=29.7, double b=0.890, double c=-0.927) :
279 DoubleParamPrecip(__FUNCTION__, "Precipitation rate from KDP and ZDR"), a(a), b(b), c(c) {
280 parameters.link("a", a);
281 parameters.link("b", b);
282 parameters.link("c", c);
283 };
284
285 inline
287 parameters.copyStruct(p.getParameters(), p, *this);
288 };
289
290 // inline virtual ~PrecipKDPZDR(){};
291 inline
292 double rainRate(double kdp, double zdr) const {
293 double r = -1.0;
294 r = a * ::pow(kdp, b) * ::pow(zdr, c); //Eq. (4)
295 return r;
296 }
297
298 double a;
299 double b;
300 double c;
301
302};
303
304} // rack
305
306
307
308
309#endif /* PRECIPITATION_H_ */
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:58
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:415
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:81
Definition Precipitation.h:121
Definition Precipitation.h:273
Definition Precipitation.h:206
Definition Precipitation.h:238
Definition Precipitation.h:140
virtual void updateBean() const override
Called after setParameters()
Definition Precipitation.h:160
Definition Precipitation.h:186
Definition Precipitation.h:195
Definition Precipitation.h:40
std::map< std::string, std::string > presets
Redefined such that if argument is a preset, reinvoke with its arguments.
Definition Precipitation.h:94
Definition Precipitation.h:103
Definition DataSelector.cpp:44