Loading...
Searching...
No Matches
RadarDataPicker.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 RADAR_DATA_PICKER_H
32#define RADAR_DATA_PICKER_H
33
34
35#include <drain/TypeUtils.h>
36#include <sstream>
37
38
39#include <drain/image/Sampler.h>
40#include <drain/image/AccumulatorGeo.h>
41#include "data/Data.h"
42
43// ##include "Geometry.h"
44#include "RadarProj.h"
45
46// // using namespace std;
47
48namespace rack {
49
51
57template <class OD>
59
60public:
61
64
65 variableMap.link("i", current_i = 0);
66 variableMap.link("j", current_j = 0);
67 variableMap.link("LON", lon = 0.0);
68 variableMap.link("LAT", lat = 0.0);
69 variableMap.link("X", x = 0.0);
70 variableMap.link("Y", y = 0.0);
71
72 }
73
76
79
82
84 typedef std::map<std::string, const data_t &> map_t;
85
86 // setPosition(i,j) in derived classes.
87
89 inline
90 bool getValue(const data_t & data, double & value) const {
91
92 value = data.data.template get<double>(this->current_i,this->current_j);
93 if ((value != data.odim.nodata) && (value != data.odim.undetect)){
94 value = data.odim.scaleForward(value);
95 return true;
96 }
97 else {
98 // Keep raw, maybe odd marker values of nodata/undetect!
99 // value = 0.0;
100 return false;
101 }
102 }
103
105 void toOStr(std::ostream &ostr = std::cout) const {
106 // "RadarDataPicker "
107 ostr << drain::TypeName<rack::RadarDataPicker<OD> >::name;
108 ostr << this->width << "x" << this->height << "; " << this->ref << "; " << odim << '\n';
109 }
110
111
112
113protected:
114
116 mutable double x;
118 mutable double y;
119
121 mutable double lon;
123 mutable double lat;
124
126 const OD & odim;
127
128
129};
130
131template <class OD>
132inline
133std::ostream & operator<<(std::ostream &ostr, const RadarDataPicker<OD> & p){
134 p.toOStr(ostr);
135 return ostr;
136}
137
138}
139
140namespace drain {
141
142//template <class OD>
143//const std::string TypeName<rack::RadarDataPicker<OD> >::name("RadarDataPicker");
144
145}
146
147namespace rack {
148
149class PolarDataPicker : public RadarDataPicker<PolarODIM> {
150
151
152public:
153
155
157
159 virtual
160 void setPosition(int i, int j) const;
161
162 inline
163 const RadarProj & getProjection() const {
164 return proj;
165 };
166
167 /*
168 virtual inline
169 void writeHeader(char commentPrefix, std::ostream & ostr) const { };
170 */
171
173 bool groundCoord = false;
174
175 protected:
176
178 //RadarProj4 proj;
180
182 const double J2AZMDEG;
183
184 // Elevation angle in radians
185 const double eta;
186
188 mutable double current_sin;
190 mutable double current_cos;
192 mutable double current_azm;
193
195 mutable double current_range;
196
198 mutable double current_height;
199
200};
201
202
203class CartesianDataPicker : public RadarDataPicker<CartesianODIM> {
204
205public:
206
209
211 void setPosition(int i, int j) const;
212
215
216};
217
218
219} // rack::
220
221namespace drain {
222
225
226
227/*
228template <>
229const std::string TypeName<rack::RadarDataPicker<rack::PolarODIM> >:: name;
230
231template <>
232const std::string TypeName<rack::RadarDataPicker<rack::CartesianODIM> >:: name;
233
234template <>
235const std::string TypeName<rack::PolarDataPicker>:: name;
236
237template <>
238const std::string TypeName<rack::CartesianDataPicker>:: name;
239*/
240
241}
242
243
244#endif /* RADAR_DATA_PICKER_H */
245
246// Rack
A map of references to base type scalars, arrays or std::string; changing values in either are equiva...
Definition ReferenceMap.h:69
ref_t & link(const std::string &key, F &x)
Associates a map entry with a variable.
Definition ReferenceMap.h:84
Array with georeferencing support.
Definition GeoFrame.h:58
Definition RadarDataPicker.h:203
void setPosition(int i, int j) const
Sets image position (in 2D Cartesian space) and calculates corresponding geographical coordinates.
Definition RadarDataPicker.cpp:150
GeoFrame frame
Frame for converting coordinates.
Definition RadarDataPicker.h:214
Metadata structure for Cartesian radar data products (single-radar or composites).
Definition CartesianODIM.h:47
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1215
Essential class for storing radar data.
Definition Data.h:300
Definition RadarDataPicker.h:149
virtual void setPosition(int i, int j) const
Sets image position and calculates corresponding geographical coordinates.
Definition RadarDataPicker.cpp:72
const double J2AZMDEG
Conversion from.
Definition RadarDataPicker.h:182
bool groundCoord
If true, i is looped as a ground coordinate.
Definition RadarDataPicker.h:173
double current_range
Distance from the radar.
Definition RadarDataPicker.h:195
double current_sin
Utility.
Definition RadarDataPicker.h:188
double current_cos
Utility.
Definition RadarDataPicker.h:190
double current_height
Altitude from the mean sea level.
Definition RadarDataPicker.h:198
double current_azm
Utility.
Definition RadarDataPicker.h:192
RadarProj proj
Converts the polar coordinates for a radar to geographical coordinates.
Definition RadarDataPicker.h:179
Metadata structure for single-radar data (polar scans, volumes and products).
Definition PolarODIM.h:45
Base class for utilities traversing radar data with Sampler.
Definition RadarDataPicker.h:58
void toOStr(std::ostream &ostr=std::cout) const
Prints images geometry, buffer size and type information.
Definition RadarDataPicker.h:105
DataSet< src_t > dataset_t
Input dataSet type.
Definition RadarDataPicker.h:81
SrcType< OD const > src_t
Input source type.
Definition RadarDataPicker.h:75
bool getValue(const data_t &data, double &value) const
Reads a value, and scales it unless nodata or undetect.
Definition RadarDataPicker.h:90
RadarDataPicker(drain::ReferenceMap2<> &variableMap, const OD &odim)
Default constructor.
Definition RadarDataPicker.h:63
double lat
Latitudinal coordinate (degrees)
Definition RadarDataPicker.h:123
PlainData< src_t > data_t
Input data type.
Definition RadarDataPicker.h:78
double lon
Longitudinal coordinate (degrees)
Definition RadarDataPicker.h:121
std::map< std::string, const data_t & > map_t
Map type compatible with Sampler.
Definition RadarDataPicker.h:84
double y
Metric coordinate corresponding to latitudinal coordinate.
Definition RadarDataPicker.h:118
const OD & odim
Metadata for navigating and scaling grid data.
Definition RadarDataPicker.h:126
double x
Metric coordinate corresponding to longitudinal coordinate.
Definition RadarDataPicker.h:116
Definition RadarProj.h:99
Definition DataSelector.cpp:1277
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.
Definition DataSelector.cpp:44
Interprets data values for Sampler.
Definition Sampler.h:61
ReferenceMap2 & variableMap
Definition Sampler.h:115
int current_i
Optional utility. Called prior to writing the actual data to output stream.
Definition Sampler.h:99
int current_j
Vertical coordinate.
Definition Sampler.h:102
Read-only data type.
Definition Data.h:110