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 // If returns true, also raw value should be stored.
90 inline
91 bool getValue(const data_t & data, double & value) const {
92
93 value = data.data.template get<double>(this->current_i,this->current_j);
94
95 return true;
96
97 //if ((value != data.odim.nodata) && (value != data.odim.undetect)){
98 /*
99 if (data.odim.isValue(value)){
100 value = data.odim.scaleForward(value);
101 return true;
102 }
103 else {
104 // Keep raw, maybe odd marker values of nodata/undetect!
105 // value = 0.0;
106 return false;
107 }*/
108 }
109
111 inline
112 bool handleValue(const data_t & data, double & value) const {
113 if (data.odim.isValue(value)){
114 value = data.odim.scaleForward(value);
115 return true;
116 }
117 else {
118 // Keep raw, maybe odd marker values of nodata/undetect!
119 // value = 0.0;
120 return false;
121 }
122 return true;
123 }
124
126 void toStream(std::ostream &ostr = std::cout) const {
127 // "RadarDataPicker "
128 ostr << drain::TypeName<rack::RadarDataPicker<OD> >::name;
129 ostr << this->width << "x" << this->height << "; " << "; " << odim << '\n';
130 }
131
132
133
134protected:
135
137 mutable double x;
139 mutable double y;
140
142 mutable double lon;
144 mutable double lat;
145
147 const OD & odim;
148
149
150};
151
152template <class OD>
153inline
154std::ostream & operator<<(std::ostream &ostr, const RadarDataPicker<OD> & p){
155 p.toStream(ostr);
156 return ostr;
157}
158
159}
160
161
162namespace rack {
163
164class PolarDataPicker : public RadarDataPicker<PolarODIM> {
165
166
167public:
168
170
172
174 virtual
175 void setPosition(int i, int j) const;
176
177 inline
178 const RadarProj & getProjection() const {
179 return proj;
180 };
181
182 /*
183 virtual inline
184 void writeHeader(char commentPrefix, std::ostream & ostr) const { };
185 */
186
188 bool groundCoord = false;
189
190 protected:
191
193 //RadarProj4 proj;
195
197 const double J2AZMDEG;
198
199 // Elevation angle in radians
200 const double eta;
201
203 mutable double current_sin;
205 mutable double current_cos;
207 mutable double current_azm;
208
210 mutable double current_range;
211
213 mutable double current_height;
214
215};
216
217
218class CartesianDataPicker : public RadarDataPicker<CartesianODIM> {
219
220public:
221
224
226 void setPosition(int i, int j) const;
227
230
231};
232
233
234} // rack::
235
236namespace drain {
237
240
241} // Rack
242
243
244#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:218
void setPosition(int i, int j) const
Sets image position (in 2D Cartesian space) and calculates corresponding geographical coordinates.
Definition RadarDataPicker.cpp:151
GeoFrame frame
Frame for converting coordinates.
Definition RadarDataPicker.h:229
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:1275
Essential class for storing radar data.
Definition Data.h:311
Definition RadarDataPicker.h:164
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:197
bool groundCoord
If true, i is looped as a ground coordinate.
Definition RadarDataPicker.h:188
double current_range
Distance from the radar.
Definition RadarDataPicker.h:210
double current_sin
Utility.
Definition RadarDataPicker.h:203
double current_cos
Utility.
Definition RadarDataPicker.h:205
double current_height
Altitude from the mean sea level.
Definition RadarDataPicker.h:213
double current_azm
Utility.
Definition RadarDataPicker.h:207
RadarProj proj
Converts the polar coordinates for a radar to geographical coordinates.
Definition RadarDataPicker.h:194
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:91
void toStream(std::ostream &ostr=std::cout) const
Prints images geometry, buffer size and type information.
Definition RadarDataPicker.h:126
bool handleValue(const data_t &data, double &value) const
Returns false, is value is invalid.
Definition RadarDataPicker.h:112
RadarDataPicker(drain::ReferenceMap2<> &variableMap, const OD &odim)
Default constructor.
Definition RadarDataPicker.h:63
double lat
Latitudinal coordinate (degrees)
Definition RadarDataPicker.h:144
PlainData< src_t > data_t
Input data type.
Definition RadarDataPicker.h:78
double lon
Longitudinal coordinate (degrees)
Definition RadarDataPicker.h:142
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:139
const OD & odim
Metadata for navigating and scaling grid data.
Definition RadarDataPicker.h:147
double x
Metric coordinate corresponding to longitudinal coordinate.
Definition RadarDataPicker.h:137
Definition RadarProj.h:99
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Interprets data values for Sampler.
Definition Sampler.h:58
ReferenceMap2 & variableMap
Definition Sampler.h:112
int current_i
Optional utility. Called prior to writing the actual data to output stream.
Definition Sampler.h:96
int current_j
Vertical coordinate.
Definition Sampler.h:99
Read-only data type.
Definition Data.h:107