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 toStream(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.toStream(ostr);
135 return ostr;
136}
137
138}
139
140
141namespace rack {
142
143class PolarDataPicker : public RadarDataPicker<PolarODIM> {
144
145
146public:
147
149
151
153 virtual
154 void setPosition(int i, int j) const;
155
156 inline
157 const RadarProj & getProjection() const {
158 return proj;
159 };
160
161 /*
162 virtual inline
163 void writeHeader(char commentPrefix, std::ostream & ostr) const { };
164 */
165
167 bool groundCoord = false;
168
169 protected:
170
172 //RadarProj4 proj;
174
176 const double J2AZMDEG;
177
178 // Elevation angle in radians
179 const double eta;
180
182 mutable double current_sin;
184 mutable double current_cos;
186 mutable double current_azm;
187
189 mutable double current_range;
190
192 mutable double current_height;
193
194};
195
196
197class CartesianDataPicker : public RadarDataPicker<CartesianODIM> {
198
199public:
200
203
205 void setPosition(int i, int j) const;
206
209
210};
211
212
213} // rack::
214
215namespace drain {
216
219
220} // Rack
221
222
223#endif /* RADAR_DATA_PICKER_H */
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:197
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:208
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:143
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:176
bool groundCoord
If true, i is looped as a ground coordinate.
Definition RadarDataPicker.h:167
double current_range
Distance from the radar.
Definition RadarDataPicker.h:189
double current_sin
Utility.
Definition RadarDataPicker.h:182
double current_cos
Utility.
Definition RadarDataPicker.h:184
double current_height
Altitude from the mean sea level.
Definition RadarDataPicker.h:192
double current_azm
Utility.
Definition RadarDataPicker.h:186
RadarProj proj
Converts the polar coordinates for a radar to geographical coordinates.
Definition RadarDataPicker.h:173
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
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
void toStream(std::ostream &ostr=std::cout) const
Prints images geometry, buffer size and type information.
Definition RadarDataPicker.h:105
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