Loading...
Searching...
No Matches
PolarODIM.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 POLAR_ODIM_STRUCT
32#define POLAR_ODIM_STRUCT
33
34//#include <drain/TypeName.h>
35#include <drain/util/Units.h>
36
37#include "ODIM.h"
38
39namespace rack {
40
42
45class PolarODIM : public ODIM {
46
47
48public:
49
51 PolarODIM(group_t initialize = ODIMPathElem::ALL_LEVELS) : ODIM(initialize), rscale(resolution.x){
52 init(initialize);
53 };
54
56 PolarODIM(const PolarODIM & odim) : ODIM(ODIMPathElem::ALL_LEVELS), rscale(resolution.x), highprf(0.0) {
57 initFromMap(odim);
58 getNyquist();
59 }
60
62 template <class T>
63 PolarODIM(const std::map<std::string,T> & m) : ODIM(ODIMPathElem::ALL_LEVELS), rscale(resolution.x), highprf(0.0) {
64 initFromMap(m);
65 getNyquist();
66 }
67
69 PolarODIM(const drain::image::Image & img, const std::string & quantity="") : ODIM(ODIMPathElem::ALL_LEVELS), rscale(resolution.x), highprf(0.0) {
70 initFromImage(img, quantity);
71 }
72
73 inline
74 rack::PolarODIM & operator=(const rack::PolarODIM & odim){
75 updateFromMap(odim);
76 // updateFromCastableMap(odim);
77 return *this;
78 }
79
81 double & rscale;
82
84 double lon = 0.0;
86 double lat = 0.0;
88 double height = 0.0;
89
91 double elangle = 0.0;
93 double rstart = 0.0;
95 long a1gate = 0.0;
96
97
98 double startaz = 0.0;
99 double stopaz = 0.0;
100
101 //double NI; // Maximum Nyquist
102 double highprf = 0.0; //
103 double lowprf = 0.0; //
104 double wavelength = 0.0;
105
107 double freeze = 0.0;
108
109
111 virtual inline
113 using namespace drain::image;
114 static const CoordinatePolicy polarLeft(EdgePolicy::POLAR, EdgePolicy::WRAP, EdgePolicy::LIMIT, EdgePolicy::WRAP);
115 return polarLeft;
116 }
117
119 /*
120 inline
121 void setGeometry(size_t cols, size_t rows){
122 nbins = cols;
123 nrays = rows;
124 }
125 */
126
128
131 virtual
132 void updateLenient(const PolarODIM & odim);
133
134
136
139 inline
141 if (quantity.find("VRAD") == 0){
142 getNyquist();
143 setRange(-NI, NI);
144 return true;
145 }
146 else
147 return false;
148 }
149
150 // Sets how:NI from lowprf if needed. If that fails, tries to derive it from scaling (gain, offset).
154 double getNyquist(int errorThreshold = LOG_NOTICE) const;
155
156
158 inline
159 double getBeamWidth() const {
160 return 2.0*M_PI/static_cast<double>(area.height);
161 };
162
163 bool deriveDifference(double v1, double v2, double & dOmega) const;
164
166
173 signed char checkAliasing(double v1, double v2, double NI_threshold) const;
174
176 inline
177 double getElangleR() const {
178 return elangle * drain::DEG2RAD;
179 }
180
182 // CF ? Returns the distance in metres to the start of the measurement volume (i.e. the end nearer to radar).
183 inline
184 double getBinDistance(size_t i) const {
185 return rstart + (static_cast<double>(i)+0.5)*rscale;
186 }
187
189 inline
190 double getBinSpan(size_t i) const {
191 return (static_cast<double>(i))*rscale;
192 }
193
195 inline
196 int getBinIndex(double d) const {
197 return static_cast<int>((d - rstart) / rscale) ;
198 }
199
201 inline
202 int getRayIndex(double d) const {
203 return static_cast<int>(d * static_cast<double>(area.height)/(2.0 * M_PI)) ;
204 }
205
207 inline
208 int getDRayIndex(double d) const {
209 return static_cast<int>(d * static_cast<double>(area.height) / 360.0) ;
210 }
211
213 template <class T>
214 inline
215 double getAzimuth(T j) const {
216 return static_cast<double>(j)*2.0*M_PI / static_cast<double>(area.height);
217 }
218
220
223 inline
224 int getAzimuthalBins(double degree) const {
225 return static_cast<int>(degree * static_cast<double>(area.height)/360.0 + 0.5) ;
226 }
227
229 /*
230 * Returns the number of bins corresponding to a given distance range (in meters).
231 * \see getAzimuthalBins()
232 */
233 inline
234 int getBeamBins(double spanM) const {
235 return static_cast<int>(spanM/rscale + 0.5) ;
236 }
237
239 //inline
240 double getMaxRange(bool warn = false) const;
241
242 double getGroundAngle(size_t i) const {
243 return (static_cast<double>(i)+0.5) * rscale / EARTH_RADIUS_43;
244 }
245
247 inline
248 void mapDopplerSpeed(double d, double &x, double &y) const {
249 d = scaleForward(d) * M_PI/NI;
250 //std::cerr << d << '\n';
251 x = cos(d);
252 y = sin(d);
253 }
254
255
256 static double defaultRange;
257
258private:
259
260 virtual // must
261 void init(group_t initialize =ODIMPathElem::ALL_LEVELS);
262
263
264};
265
266
267
268
269
270} // namespace rack
271
272namespace drain {
273 DRAIN_TYPENAME(rack::PolarODIM);
274}
275
276
277#endif
278
279// Rack
void updateFromMap(const std::map< std::string, T2 > &m)
Assign values from a map. Updates existing entries only.
Definition SmartMap.h:282
Policies for coordinate underflows and overflows.
Definition CoordinatePolicy.h:100
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
double scaleForward(double x) const
Converts a quantity from storage scale: y = offset + gain*y .
Definition EncodingODIM.h:241
DOC: Add class description.
Definition ODIMPath.h:82
static const group_t ALL_LEVELS
Abbreviation for linking (referencing) attributes at different levels (tree depths).
Definition ODIMPath.h:121
ODIM metadata (quantity, gain, offset, undetect, nodata, date, time)
Definition ODIM.h:79
drain::Point2D< double > resolution
Spatial resolution in metres.
Definition ODIM.h:167
std::string quantity
dataX/what (obligatory)
Definition ODIM.h:192
Metadata structure for single-radar data (polar scans, volumes and products).
Definition PolarODIM.h:45
virtual void updateLenient(const PolarODIM &odim)
Sets number of bins (geometry.width) and number of rays (geometry.height)
Definition PolarODIM.cpp:75
PolarODIM(group_t initialize=ODIMPathElem::ALL_LEVELS)
Default constructor.
Definition PolarODIM.h:51
double freeze
Freezing level.
Definition PolarODIM.h:107
signed char checkAliasing(double v1, double v2, double NI_threshold) const
Detect Doppler speed aliasing (wrapping)
Definition PolarODIM.cpp:213
int getBinIndex(double d) const
Returns the index of bin at given (bin center) distance along the beam.
Definition PolarODIM.h:196
double getMaxRange(bool warn=false) const
Returns the range in metres (i.e. distance to the end of the last measurement volume).
Definition PolarODIM.cpp:104
int getAzimuthalBins(double degree) const
Returns the span of bins for the given azimuthal span.
Definition PolarODIM.h:224
long a1gate
Index of the first azimuth gate radiated in the scan.
Definition PolarODIM.h:95
double getAzimuth(T j) const
Returns the azimuth in radians of the bin with vertical index j.
Definition PolarODIM.h:215
PolarODIM(const PolarODIM &odim)
Copy constructor.
Definition PolarODIM.h:56
double getBinSpan(size_t i) const
Returns the radial distance covered by i consecutive bins.
Definition PolarODIM.h:190
double lat
Latitude position of the radar antenna (degrees), normalized to the WGS-84 reference ellipsoid and da...
Definition PolarODIM.h:86
double & rscale
Beam-directional bin length [m].
Definition PolarODIM.h:81
void mapDopplerSpeed(double d, double &x, double &y) const
Converts Doppler speed [-NI,NI] to unit circle.
Definition PolarODIM.h:248
double getBeamWidth() const
Azimuthal resolution in radians.
Definition PolarODIM.h:159
double height
Height of the centre of the antenna in meters above sea level.
Definition PolarODIM.h:88
PolarODIM(const drain::image::Image &img, const std::string &quantity="")
Constructor.
Definition PolarODIM.h:69
PolarODIM(const std::map< std::string, T > &m)
Constructor.
Definition PolarODIM.h:63
double getNyquist(int errorThreshold=LOG_NOTICE) const
Definition PolarODIM.cpp:135
double lon
Longitude position of the radar antenna (degrees), normalized to the WGS-84 reference ellipsoid and d...
Definition PolarODIM.h:84
double getBinDistance(size_t i) const
Returns the distance along the beam to the center of the i'th bin.
Definition PolarODIM.h:184
double getElangleR() const
Returns elevation angle in radians.
Definition PolarODIM.h:177
int getDRayIndex(double d) const
Returns the index of a ray at a given azimuth [degrees].
Definition PolarODIM.h:208
double elangle
Antenna elevation angle (degrees) above the horizon.
Definition PolarODIM.h:91
bool deriveDifference(double v1, double v2, double &dOmega) const
Given two Doppler speeds (m/s), computes their difference (m/s).
Definition PolarODIM.cpp:190
int getBeamBins(double spanM) const
Returns the span of bins for the given distance range in meters.
Definition PolarODIM.h:234
bool optimiseVRAD()
For VRAD, set encoding range to cover [-NI,NI].
Definition PolarODIM.h:140
int getRayIndex(double d) const
Returns the index of a ray at a given azimuth [radians].
Definition PolarODIM.h:202
virtual const drain::image::CoordinatePolicy & getCoordinatePolicy() const
Returns recommended coordinate policy (Polar coords, origin at left)
Definition PolarODIM.h:112
double rstart
The range (km) of the start of the first range bin.
Definition PolarODIM.h:93
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition Data.h:1473
Definition AltitudeOp.cpp:42
const double EARTH_RADIUS_43
The standard 4/3 radius applied in radar to compensate the decreasing density of the atmosphere.
Definition Constants.h:53