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#include <drain/RegExp.h>
33
34#include <drain/util/BeanLike.h>
35
36#ifndef RACK_PRECIPITATION
37#define RACK_PRECIPITATION
38
39namespace rack {
40
41class Precip : public drain::BeanLike {
42
43public:
44
45
46 Precip(const std::string & name = "", const std::string & description = "") : drain::BeanLike(name, description) { // , parameters(true, ':')
47 this->parameters.separator = ',';
48 }
49
50
51 virtual
52 inline
53 ~Precip(){};
54
56 /*
57 virtual
58 inline
59 void set Parameters(const std::string &p, char assignmentSymbol='=', char separatorSymbol=0){
60
61 drain::Logger mout(__FILE__, __FUNCTION__);
62
63 static const drain::RegExp presetKey("^[a-zA-Z]+");
64
65 if (presetKey.test(p)){
66 std::map<std::string,std::string>::const_iterator it = presets.find(p);
67 if (it != presets.end()){
68 mout.info("applying presets '" , "'" );
69 //setParameters(it->second);
70 BeanLike::setParameters(it->second, assignmentSymbol, separatorSymbol);
71 }
72 else {
73 mout.warn("no preset found for: '" , p , "'" );
74 }
75 }
76 else {
77 BeanLike::setParameters(p, assignmentSymbol, separatorSymbol);
78 }
79
80 initParameters();
81 };
82 */
83
84
85 // virtual
86 // const std::string & getDescription() const;
87
88protected:
89
90 //virtual inline
91 //void initParameters(){};
92
93 // virtual void setParameterReferences() = 0;
94
95 std::map<std::string,std::string> presets;
96
97private:
98
99 //mutable
100 //std::string descriptionExt;
101
102};
103
104class SingleParamPrecip : public Precip {
105
106public:
107
108 virtual
109 double rainRate(double p) const = 0;
110
111protected:
112
113 inline
114 SingleParamPrecip(const std::string & name = "", const std::string & description = ""):
115 Precip(name,description) {
116
117 }
118
119
120};
121
122class DoubleParamPrecip : public Precip {
123
124public:
125
126 virtual
127 double rainRate(double p1, double p2) const = 0;
128
129protected:
130
131 inline
132 DoubleParamPrecip(const std::string & name = "", const std::string & description = ""):
133 Precip(name,description) {
134 }
135
136};
137
138
139
140
142
143public:
144
145 inline
146 PrecipZ(const std::string & name=__FUNCTION__, double a=200.0, double b=1.6) :
147 SingleParamPrecip(name, "Precipitation rate from Z (reflectivity)"), a(a), b(b){
148 parameters.link("a", this->a = a);
149 parameters.link("b", this->b = b);
150 updateBean();
151 };
152
153 inline
154 PrecipZ(const PrecipZ & p) : SingleParamPrecip(p) {
155 parameters.copyStruct(p.getParameters(), p, *this);
156 updateBean();
157 }
158
159 virtual
160 inline
161 void updateBean() const override {
162 aInv = 1.0/a;
163 bInv = 1.0/b;
164 //drain::Logger mout(__FILE__, __FUNCTION__);
165 //mout.warn("coeff:", aInv, bInv);
166 };
167
168
169 inline
170 double rainRate(double dbz) const {
171 return pow(aInv * pow(10.0, dbz*0.10), bInv);// Eq.(1)
172 }
173
174
175 double a;
176 double b;
177
178
179protected:
180
181
182 mutable double aInv;
183 mutable double bInv;
184
185};
186
187class PrecipZrain : public PrecipZ {
188
189public:
190
191 PrecipZrain(double a=200.0, double b=1.6) : PrecipZ(__FUNCTION__, a ,b){
192 presets["Marshall-Palmer"] = "200,1.6";
193 }
194};
195
196class PrecipZsnow : public PrecipZ {
197
198public:
199
200 PrecipZsnow( double a=222.2, double b=1.1111) : PrecipZ(__FUNCTION__, a ,b){
201 //presets["Marshall-Palmer"] = "200,1.6";
202 }
203
204};
205
206
208
209public:
210
211 inline
212 PrecipKDP(double a=21.0, double b=0.72) : SingleParamPrecip(__FUNCTION__, "Precip rate from KDP"), a(a), b(b) {
213 //setParameterReferences();
214 parameters.link("a", a);
215 parameters.link("b", b);
216 presets["Leinonen2012"] = "21,0.72";
217 };
218
219 PrecipKDP(const PrecipKDP & p) : SingleParamPrecip(p) { // copy name?
220 parameters.copyStruct(p.getParameters(), p, *this);
221 //setParameterReferences();
222 //copy(p);
223 };
224
225
226 inline
227 double rainRate(double kdp) const {
228 double r = -1.0;
229 r = a * ::pow(kdp, b); // Eq.(3)
230 return r;
231 }
232
233 double a;
234 double b;
235
236
237};
238
240
241public:
242
243 PrecipZZDR(double a=0.0122, double b=0.820, double c=-2.28) :
244 DoubleParamPrecip(__FUNCTION__, "Precipitation rate from Z and ZDR"), a(a), b(b), c(c) {
245 parameters.link("a", this->a);
246 parameters.link("b", this->b);
247 parameters.link("c", this->c);
248 // setParameterReferences();
249 };
250
251 inline
252 PrecipZZDR(const PrecipZZDR & p) : DoubleParamPrecip(p) {
253 parameters.copyStruct(p.getParameters(), p, *this);
254 //setParameterReferences();
255 // copy(p);
256 };
257
258 //inline virtual ~PrecipZZDR(){};
259
260 inline
261 double rainRate(double dbz, double zdr) const {
262 double r = -1.0;
263 r = a * ::pow(dbz, b) * pow(zdr, c);// Eq.(2)
264 return r;
265 }
266
267 double a;
268 double b;
269 double c;
270
271
272};
273
275
276public:
277
278 inline
279 PrecipKDPZDR(double a=29.7, double b=0.890, double c=-0.927) :
280 DoubleParamPrecip(__FUNCTION__, "Precipitation rate from KDP and ZDR"), a(a), b(b), c(c) {
281 parameters.link("a", a);
282 parameters.link("b", b);
283 parameters.link("c", c);
284 };
285
286 inline
288 parameters.copyStruct(p.getParameters(), p, *this);
289 };
290
291 // inline virtual ~PrecipKDPZDR(){};
292 inline
293 double rainRate(double kdp, double zdr) const {
294 double r = -1.0;
295 r = a * ::pow(kdp, b) * ::pow(zdr, c); //Eq. (4)
296 return r;
297 }
298
299 double a;
300 double b;
301 double c;
302
303};
304
305} // rack
306
307
308
309
310#endif /* PRECIPITATION_H_ */
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:60
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:399
char separator
Default character used for splitting input and output. See setValues.
Definition SmartMap.h:85
Definition Precipitation.h:122
Definition Precipitation.h:274
Definition Precipitation.h:207
Definition Precipitation.h:239
Definition Precipitation.h:141
virtual void updateBean() const override
Called after setParameters()
Definition Precipitation.h:161
Definition Precipitation.h:187
Definition Precipitation.h:196
Definition Precipitation.h:41
std::map< std::string, std::string > presets
Redefined such that if argument is a preset, reinvoke with its arguments.
Definition Precipitation.h:95
Definition Precipitation.h:104
Definition DataSelector.cpp:44