EchoTopOp.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2024 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 
32 #ifndef ECHO_TOP2_OP
33 #define ECHO_TOP2_OP
34 
35 
36 #include "radar/RadarWindows.h"
37 
38 #include "PolarProductOp.h"
39 
40 using namespace drain::image;
41 
42 namespace rack {
43 
45 
48 struct Measurement : public drain::UniTuple<double,2> {
49 
50  double & reflectivity;
51  double & height;
52 
53  Measurement(double reflectivity=NAN, double height=0.0) : reflectivity(this->next()), height(this->next()){
54  this->set(reflectivity, height);
55  };
56 
57  Measurement(const Measurement & p): reflectivity(this->next()), height(this->next()){
58  this->set(p);
59  };
60 };
61 
62 /*
63 struct Measurement {
64 
66  const Data<src_t> * dataPtr = nullptr;
67 
69  size_t binIndex = 0;
70 
72  double height = 0;
73 
75  double reflectivity = NAN;
76 
78  // double quality = 0.0;
79 };
80 */
81 
85 template <class T>
86 struct MethodWeights : public drain::UniTuple<T,5> {
87 
88  typedef T value_t;
89 
92  T & interpolation_dry; // beam over Z < Z_thr
93  T & extrapolation_up; // truncated strong echo underShooting highest beam Z > Z_thr
94  T & extrapolation_down;
95  T & clear; // same as undetect, but needs a quality index value
96  T error = 0; // needs a quality index value (0)
97 
98  MethodWeights() : interpolation(this->next()), interpolation_dry(this->next()), extrapolation_up(this->next()), extrapolation_down(this->next()), clear(this->next()){
99  };
100 
101  template<typename ... TT>
102  MethodWeights(const TT &... args) : interpolation(this->next()), interpolation_dry(this->next()), extrapolation_up(this->next()), extrapolation_down(this->next()), clear(this->next()){
103  this->set(args...);
104  };
105 
106  MethodWeights(const MethodWeights & p): drain::UniTuple<double,5>(p),
107  interpolation(this->next()), interpolation_dry(this->next()), extrapolation_up(this->next()), extrapolation_down(this->next()), clear(this->next()) {
108  };
109 
110  /*
111  inline
112  bool useInterpolation() const {
113  return (interpolation > overShooting);
114  }
115  */
116 
117 
118 };
119 
120 
121 
123 
126 class EchoTopOp: public PolarProductOp {
127 
128 public:
129 
130  EchoTopOp(double threshold = 20.0);
131 
132  virtual inline
133  ~EchoTopOp(){};
134 
135  // TEST
136  void computeSingleProduct(const DataSetMap<src_t> & srcSweeps, DataSet<dst_t> & dstProduct) const;
137 
139 
143  static inline
144  double getSlope(const Measurement & m1, const Measurement & m2){
145  return (m1.height - m2.height) / (m1.reflectivity - m2.reflectivity);
146  }
147 
148  /*
149  static inline
150  double getSlope(double heightStronger, double heightWeaker, double reflectivityStronger, double reflectivityWeaker){
151  return (heightStronger - heightWeaker) / (reflectivityStronger - reflectivityWeaker);
152  }
153  */
154 
155 
156 protected:
157 
158  // Main parameter: dBZ threshold.
159  double threshold = 0.0;
160 
162  double undetectReflectivity = NAN;
163 
165  Measurement reference = {-50.0, 15000.0};
166 
168  MethodWeights<double> weights = {1.0, 0.8, 0.6, 0.4, 0.2};
169 
171  double weightDecay = 20.0;
172 
174  RadarWindowGeom avgWindow; // = {0.0,0.0}; // check tuple init, + assignment
175 
177  bool EXTENDED_OUTPUT = true;
178 
180 
181 };
182 
183 } // rack::
184 
186 /*
187 typedef enum {
188  / ** Unset (not processsed) * /
189  UNDEFINED=0,
190  / ** Internal error in the computation * /
191  ERROR=16,
192  / ** No echo found * /
193  CLEAR=64,
194  / ** The highest bin exceeds the threshold -> use reference point * /
195  UNDERSHOOTING=96,
196  / ** The bin exceeding the Z threshold has an \c undetect ("dry") bin above -> replace \c undetect with low Z (dB) * /
197  OVERSHOOTING=128,
198  WEAK=192, /// Echoes only below threshold detected
199  / ** The threshold value was passed between adjacent beams, hence can be interpolated * /
200  INTERPOLATION=250
201 } Reliability;
202 
203 typedef drain::EnumFlagger<drain::SingleFlagger<Reliability> > reliabilityFlagger;
204 */
205 
206 
207 #endif
Tuple of N elements of type T.
Definition: UniTuple.h:65
Definition: Data.h:1368
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition: Data.h:1213
Definition: EchoTopOp.h:126
RadarWindowGeom avgWindow
Optional smoothin window. Width (metres) and height (degrees) (also used for reference)
Definition: EchoTopOp.h:174
static double getSlope(const Measurement &m1, const Measurement &m2)
Definition: EchoTopOp.h:144
Base class for flat (2D) products computed in the polar coordinate system. Volume is used as input.
Definition: PolarProductOp.h:61
Like pixel window, but width is metres and height is degrees.
Definition: RadarWindows.h:93
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:1277
Definition: DataSelector.cpp:44
A single measurement (bin), with height coordinate and measurement value (reflectivity).
Definition: EchoTopOp.h:48
Definition: EchoTopOp.h:86
T & interpolation
Highest to lowest certainty.
Definition: EchoTopOp.h:91