Loading...
Searching...
No Matches
Doppler.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#ifndef RACK_ANALYSIS_DOPPLER_H
32#define RACK_ANALYSIS_DOPPLER_H
33
34#include <math.h>
35
36#include <drain/Log.h>
37#include <drain/Type.h>
38#include <drain/util/Fuzzy.h>
39#include <drain/util/Functor.h>
40#include <drain/util/FunctorBank.h>
41#include <drain/image/Window.h>
42#include <drain/image/SlidingWindow.h>
43
44#include "RadarWindows.h"
45
46
47using namespace drain::image;
48
49namespace rack {
50
51
55class DopplerWindow : public SlidingRadarWindow<RadarWindowConfig> {
56public:
57
58
59 DopplerWindow(const RadarWindowConfig & conf) :
61 sumI(0.0), sumI2(0.0), sumJ(0.0), sumJ2(0.0), count(0){}; //, countMin(0) {};
62
63 virtual
64 inline
66
67protected:
68
69
71
76
78
81
82
83 // cumulants
84 double sumI;
85 double sumI2;
86 double sumJ;
87 double sumJ2;
88 int count;
89
90 virtual inline
91 void initialize(){
92
93 drain::Logger mout("RadarWindowDopplerDev", __FUNCTION__);
94
95 this->setImageLimits();
96 this->setLoopLimits();
97 this->setRangeNorm();
98
99
100 this->NI = this->odimSrc.getNyquist(LOG_WARNING); // warn if guessed from scaling
101 if (this->NI == 0.0){
102 mout.warn(odimSrc );
103 mout.error("Could not derive Nyquist velocity (NI) from metadata." );
104 radialSpeedConv = 1.0;
105 radialSpeedConvInv = 1.0;
106 }
107 else {
108 radialSpeedConv = M_PI / this->NI;
109 radialSpeedConvInv = this->NI / M_PI; // M_1_PI * this->NI;
110 }
111
112 reset();
113
114 };
115
116
117 virtual inline
118 void clear(){
119 sumI = 0.0;
120 sumI2 = 0.0;
121 sumJ = 0.0;
122 sumJ2 = 0.0;
123 count = 0;
124 };
125
126
127 virtual
128 inline
129 void removeTrailingValue(double x){
130 x *= radialSpeedConv;
131 double t;
132 t = cos(x);
133 sumI -= t;
134 sumI2 -= t*t;
135 t = sin(x);
136 sumJ -= t;
137 sumJ2 -= t*t;
138 --count;
139 };
140
141 virtual inline
142 void addLeadingValue(double x){
143 x *= radialSpeedConv;
144 double t;
145 t = cos(x);
146 sumI += t;
147 sumI2 += t*t;
148 t = sin(x);
149 sumJ += t;
150 sumJ2 += t*t;
151 ++count;
152 //if ((this->p.x == this->p.y) && (x > -15.0))
153 // std::cerr << "handleLeadingPixel" << this->p << ':' << x << '\t' << count << ':' << sum << std::endl;
154 };
155
157 virtual inline
158 double averageR(){
159 return atan2(sumJ, sumI);
160 }
161
163
166 virtual inline
167 double stdDevR(){
168 double c = 1.0/static_cast<double>(count);
169 return ::sqrt((sumI2+sumJ2 - (sumI*sumI+sumJ*sumJ)*c)*c);
170 }
171
173
179 virtual inline
180 double eccentricity(){
181 return ::sqrt(sumI*sumI + sumJ*sumJ) / static_cast<double>(count);
182 }
183
184};
185
186
188
189public:
190
192
193 }
194
196
197protected:
198
199 virtual
200 inline
201 void write(){
202 //if ((this->location.x == this->location.y) && (this->location.x%15 == 0))
203 // std::cerr << "write" << this->location << ':' << '\t' << count << ':' << (this->conf.contributionThreshold * this->samplingArea) << std::endl;
204
205 if (count > countMin){ // TODO threshold 0.5?
206
207 if (this->conf.relativeScale)
208 this->dst.putScaled(this->location.x, this->location.y, averageR() * M_1_PI); // todo ftor?
209 else
210 this->dst.putScaled(this->location.x, this->location.y, averageR() * this->radialSpeedConvInv);
211 /*
212 if (this->debugDiag()){
213 std::cerr << "write: " << this->location.x << ":\t"
214 << atan2(sumJ, sumI) << "~\t"
215 << ((this->conf.relativeScale?M_1_PI:this->radialSpeedConvInv) * atan2(sumJ, sumI)) << ":\t"
216 << this->dst.getScaled(this->location.x, this->location.y) << '\t'
217 << this->dst.get<double>(this->location.x, this->location.y) << '\n';
218 }
219 */
220 }
221 else
222 this->dst.put(this->location, this->odimSrc.undetect); // NOTE: may be wrong (C/S), add odimDst?
223
224 };
225
226};
227
230
231public:
232
234
235 }
236
237 typedef DopplerAverageWindow2 unweighted; // ????
238
239protected:
240
241 virtual inline
242 void write(){
243
244 //if ((this->location.x == this->location.y) && (this->location.x%15 == 0))
245 // std::cerr << "write" << this->location << ':' << '\t' << count << ':' << (this->conf.contributionThreshold * this->samplingArea) << std::endl;
246
247 double confidence = this->myFunctor(this->eccentricity());
248
249 if (count > countMin){ // TODO threshold 0.5?
250
251 if (this->conf.relativeScale)
252 this->dst.putScaled(this->location.x, this->location.y, averageR() * M_1_PI); //
253 else
254 this->dst.putScaled(this->location.x, this->location.y, averageR() * this->radialSpeedConvInv);
255
256 this->dstWeight.putScaled(this->location.x, this->location.y, confidence);
257 //this->dstWeight.putScaled(this->location.x, this->location.y, this->conf.ftor(this->NI*stdDevR()));
258 //this->dstWeight.putScaled(this->location.x, this->location.y, this->eccentricity());
259
260 }
261 else {
262 this->dst.put(this->location, this->odimSrc.undetect); // NOTE: may be wrong (C/S), add odimDst?
263 this->dstWeight.put(this->location, 0.0); // NOTE: may be wrong (C/S), add odimDst?
264 }
265
266 };
267
268};
269
270
272
273public:
274
276 }
277
279
280protected:
281
282
283 virtual inline
284 void write(){
285
286 if (count > countMin){ // TODO threshold 0.5?
287
288 if (this->conf.relativeScale)
289 this->dst.putScaled(this->location.x, this->location.y, this->myFunctor(stdDevR()));
290 else
291 //this->dst.putScaled(this->location.x, this->location.y, this->conf.ftor(c));
292 // NOTE: possibly odimSrc != odimDst, (C/S), add odimDst?
293 this->dst.putScaled(this->location.x, this->location.y, this->myFunctor(NI * stdDevR()) );
294 /*
295 if (this->debugDiag()){
296 std::cerr << "write: " << this->location.x << ":\t" << (int) this->conf.relativeScale << '\t'
297 << c << ">\t"
298 << (this->conf.relativeScale ? c : c*this->odimSrc.NI ) << ":\t"
299 << this->dst.getScaled(this->location.x, this->location.y) << '\t'
300 << this->dst.get<double>(this->location.x, this->location.y) << '\n';
301 }
302 */
303
304 }
305 // else this->dst.put(this->location, 0); LEAVE undetect
306
307 };
308
309};
310
311//DRAIN_TYPENAME(DopplerDevWindow);
312
315
316public:
317
319
320 }
321
323
324protected:
325
326 virtual inline
327 void write(){
328
329 //if ((this->location.x == this->location.y) && (this->location.x%15 == 0))
330 // std::cerr << "write" << this->location << ':' << '\t' << count << ':' << (this->conf.contributionThreshold * this->samplingArea) << std::endl;
331
332 //double confidence = this->conf.ftor(this->eccentricity());
333
334 if (count > countMin){ // TODO threshold 0.5?
335 this->dst.putScaled(this->location.x, this->location.y, this->myFunctor(this->eccentricity()));
336 }
337 else {
338 this->dst.put(this->location, this->odimSrc.undetect); // NOTE: may be wrong (C/S), add odimDst?
339 }
340
341 };
342
343};
344
345
346} // rack::
347
348namespace drain {
349
350
355}
356
357
358#endif
359
360// Rack
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition ImageFrame.h:192
void putScaled(size_t i, size_t j, double x)
Put intensity using original physical value.
Definition ImageFrame.h:241
Point2D< int > location
Current location of this window.
Definition Window.h:523
void setLoopLimits()
Sets the actual traversal range inside the window. Sometimes applied dynamically by reset().
Definition Window.h:608
Smoothens Doppler field, providing quality computed as eccentricity.
Definition Doppler.h:229
virtual void write()
Write the result in the target image.
Definition Doppler.h:242
Definition Doppler.h:187
virtual void write()
Write the result in the target image.
Definition Doppler.h:201
Definition Doppler.h:271
virtual void write()
Write the result in the target image.
Definition Doppler.h:284
Computes eccentrity of Doppler speeds mapped on a Nyquist-normalized unit window.
Definition Doppler.h:314
virtual void write()
Write the result in the target image.
Definition Doppler.h:327
Definition Doppler.h:55
double radialSpeedConv
Speed scaled to radians [-M_PI, M_PI]: radialSpeedConv = M_PI/this->conf.odimSrc.NI.
Definition Doppler.h:75
virtual double stdDevR()
Returns the radial speed variance [rad] defined as the variance of the cloud of velocity points on un...
Definition Doppler.h:167
virtual void initialize()
Sets class-specific initial values. Does not change general window state (e.g. location)....
Definition Doppler.h:91
virtual void removeTrailingValue(double x)
Handles the converted (natural-scaled) value.
Definition Doppler.h:129
virtual void addLeadingValue(double x)
Handles the converted (natural-scaled) value.
Definition Doppler.h:142
virtual double averageR()
Returns direction [rad] of the dominant speed.
Definition Doppler.h:158
double radialSpeedConvInv
Inverse of radialSpeedConv.
Definition Doppler.h:80
virtual void clear()
Clears the applied statistics. Redefined in derived classes.
Definition Doppler.h:118
virtual double eccentricity()
Returns the eccentricity of the velocity points on unit circle.
Definition Doppler.h:180
Definition RadarWindows.h:84
bool relativeScale
If true, use speed up to -1.0...+1.0 instead of -Vnyq...+Vnyq.
Definition RadarWindows.h:95
void setImageLimits() const
Sets internal limits corresponding to image geometries. Typically using coordHandler.
Definition RadarWindows.h:247
virtual bool reset()
Returns false, if traversal should be ended.
Definition RadarWindows.h:280
void setRangeNorm()
To compensate polar geometry, set applicable range for pixel area scaling.
Definition RadarWindows.h:253
Definition RadarWindows.h:303
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition DataSelector.cpp:1277
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.
Definition DataSelector.cpp:44