JammingOp.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 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 Jamming2_OP_H_
33 #define Jamming2_OP_H_
34 
35 #include <limits>
36 
37 //#include "drain/util/FunctorPack.h"
38 //#include "drain/util/Math.h"
39 
40 /*
41 #include "drain/image/File.h"
42 #include "drain/imageops/RunLengthOp.h"
43 #include "drain/imageops/DistanceTransformOp.h"
44 */
45 
46 
47 #include "DetectorOp.h"
48 
49 
50 //using namespace drain::image;
51 
52 using namespace drain::image;
53 
54 namespace rack {
55 
57 
64 class JammingOp: public DetectorOp {
65 
66 public:
67 
80  // \param derivativeDifferenceMax - maximum difference between modelled and detected dBZ(range) slopes.
81  // \param windowWidth - windowWidth [kilometres]
82  // JammingOp(int windowWidth=5000, float windowHeight=10.0, float sensitivity = 0.5, float eWidth = 1.0f, float eHeight = 0.0f) :
83  // JammingOp(double smoothnessThreshold = 5.0, double sampleContent=0.5, double weightLower = 0.1, double maxCurvature = 0.001, double distanceMin = 40.0, int debugRow=-1) :
84  JammingOp(double smoothnessThreshold = 5.0, double distanceMin = 80.0, double refit=true, int debugRow=-1) : // , double derivativeDifferenceMax = 0.0001
85  DetectorOp(__FUNCTION__, "Detects broad lines caused by electromagnetic interference. Intensities should be smooth, increasing by distance.",
86  "jamming")
87  {
88  parameters.link("smoothnessThreshold", this->smoothnessThreshold = smoothnessThreshold, "dBZ");
89  parameters.link("distanceMin", this->distanceMin = distanceMin, "km");
90  parameters.link("refit", this->refit = refit, "true|false"); // [0.0...1.0]
91  // parameters.link("weightLower", this->weightLower = weightLower, "[0.0...1.0]");
92  // parameters.link("debugRow", this->debugRow = debugRow, "index");
93 
94  UNIVERSAL = true;
95  REQUIRE_STANDARD_DATA = true;
96  }
97 
98 
99  double smoothnessThreshold;
100  double distanceMin;
101  //double sampleContent;
102  //double weightLower;
103  bool refit;
104  //double derivativeDifferenceMax;
105 
132  //double maxCurvature;
133 
134 
135  int debugRow;
136 
138 
142  static inline
143  double modelledEmitter(double dBZ0, double distance){
144  return dBZ0 + distance*(0.016/1000.0) + 20.0*log10(distance);
145  };
146 
147 protected:
148 
149  virtual
150  void runDetector(const PlainData<PolarSrc> & srcData, PlainData<PolarDst> & dstProb) const;
151  //void filterImage(const PolarODIM &odimIn, const Image &src, Image &dst) const;
152 
153  /*
154  static
155  void fitCurve(const std::vector<double> &src, const std::vector<double> &weight, std::vector<double> &coeff);
156 
157  virtual
158  void filterImageOLD(const PolarODIM &odimIn, const Image &src, Image &dst) const;
159  */
160 
162  inline
163  static
164  double derivativeDBZ(const PolarODIM &odimIn, const Image &src, int i, int j, int span = 10){
165  int iLower = std::max(i-span, 0);
166  double zLower = src.get<double>(iLower,j);
167  if (odimIn.isValue(zLower)){
168  int iUpper = std::min(i+span, static_cast<int>(src.getWidth())-1);
169  double zUpper = src.get<double>(iUpper,j);
170  if (odimIn.isValue(zUpper)){
171  return (zUpper - zLower)/(odimIn.rscale*static_cast<double>(iUpper-iLower));
172  }
173  }
174  return std::numeric_limits<double>::max();
175  }
176 
179  inline
180  static
181  double derivativeDBZ_Modelled(double yModelBase, double range, double rangeDifference){
182  return (modelledEmitter(yModelBase, range+rangeDifference) - modelledEmitter(yModelBase, range-rangeDifference)) / (2.0*rangeDifference);
183  }
184 
185 
186 };
187 
188 }
189 
190 #endif // Jamming2_OP_H_
191 
192 // Rack
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
Base class for anomaly detectors.
Definition: DetectorOp.h:49
bool isValue(double x) const
Returns true for a valid measurement value, false for undetect and nodata marker values.
Definition: EncodingODIM.h:219
A detector for widespread electromagnetic interference.
Definition: JammingOp.h:64
static double modelledEmitter(double dBZ0, double distance)
Model for radar amplification of an external emitter.
Definition: JammingOp.h:143
static double derivativeDBZ(const PolarODIM &odimIn, const Image &src, int i, int j, int span=10)
Returns the beam-oriented derivative of the dBZ field. In case of no-data, returns std::numeric_limit...
Definition: JammingOp.h:164
int debugRow
Definition: JammingOp.h:135
JammingOp(double smoothnessThreshold=5.0, double distanceMin=80.0, double refit=true, int debugRow=-1)
Definition: JammingOp.h:84
Essential class for storing radar data.
Definition: Data.h:302
Metadata structure for single-radar data (polar scans, volumes and products).
Definition: PolarODIM.h:45
double & rscale
Beam-directional bin length [m].
Definition: PolarODIM.h:77
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:44