Loading...
Searching...
No Matches
ODIM.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 ODIM_STRUCT
32#define ODIM_STRUCT
33
34#include <ostream>
35#include <cmath>
36#include <string>
37#include <set>
38#include <algorithm>
39//
40#include <drain/util/VariableFormatter.h> // for VariableHandler
41#include <drain/util/ReferenceMap.h>
42#include <drain/util/Rectangle.h>
43#include <drain/util/Time.h>
44#include <drain/image/Geometry.h>
45
46#include "hi5/Hi5.h"
47#include "radar/Constants.h"
48
49#include "EncodingODIM.h"
50
51namespace rack {
52
53
79class ODIM : public EncodingODIM { //, public {
80
81public:
82
83 typedef enum {
84 KILOMETRES = 1,
85 RACK_EXTENSIONS = 8, // like where:BBOX
86 ODIM_2_2 = 16 | KILOMETRES,
87 ODIM_2_3 = 32 | KILOMETRES,
88 // ODIM_2_3_6 = 64
89 ODIM_2_4 = 64
91
92 //typedef drain::EnumFlagger<drain::SingleFlagger<Version> > VersionFlagger;
93 typedef drain::EnumFlagger<drain::MultiFlagger<Version> > VersionFlagger; // Multi, for KM's
94
95 static VersionFlagger versionFlagger;
96
97 typedef std::set<std::string> nameSet;
98
99 static
100 const nameSet timeKeys; // = {"time", "starttime", "endtime"};
101
102 static
103 const nameSet dateKeys; // = {"date", "startdate", "enddate"};
104
105 static
106 const nameSet locationKeys; // = {"site", "src", "lat", "lon", "PLC", "NOD", "WMO"};
107
108
109
110 inline
111 ODIM(group_t initialize = ODIMPathElem::ALL_LEVELS) : EncodingODIM(initialize){
112 init(initialize);
113 };
114
115 inline
116 ODIM(const ODIM & odim) : NI(odim.NI){
117 initFromMap(odim);
118 };
119
120 inline
121 ODIM(const drain::image::Image & image, const std::string & quantity="") : EncodingODIM(image) {
122 initFromImage(image, quantity);
123 };
124
125 inline
126 ODIM(drain::image::Image & image, const std::string & quantity="") : EncodingODIM(image) {
127 initFromImage(image, quantity);
128 };
129
130 /*
131 inline
132 ODIM(const drain::image::Image & image, const std::string & quantity="") : EncodingODIM(image) {
133 initFromImage(image, quantity);
134 };
135 */
136
137 /*
138 inline
139 ODIM(drain::image::Image & image, const std::string & quantity="") : geometryREF(image.geometry) {
140 initFromImage(image, quantity);
141 };
142 */
143
144 inline
145 ~ODIM(){};
146
147 //const drain::image::AreaGeometry geometry;
148
150
152
157
158 //const drain::image::AreaGeometry & geometryTEST;
159
161 static
162 const std::string dateformat;
163
165 static
166 const std::string timeformat;
167
168
171 std::string object;
172 std::string version;
173
175 std::string date;
177 std::string time;
178 std::string source;
179
181 std::string quantity; // raise?
182 std::string product; // raise?
183 std::string prodpar; // raise?
184 std::string startdate;
185 std::string starttime;
186 std::string enddate;
187 std::string endtime;
188
189 // Elevation angles.
190 // In ODIM, defined for Cartesian but used more generally - for polar products - in Rack
191 std::vector<double> angles;
192
193
194 // Number of images used in precipitation accumulation (lenient, not linked)
195 long ACCnum = 0;
196
198 virtual inline
199 void setGeometry(size_t cols, size_t rows){
200 area.set(cols, rows);
201 };
202
203
204 virtual
206 setGeometry(g.getWidth(), g.getHeight());
207 };
208
209 virtual // ?
210 const drain::image::AreaGeometry & getGeometry() const {
211 return area;
212 };
213
215 virtual
216 void adjustGeometry(size_t cols, size_t rows);
217
218
219
221
224 virtual
225 void updateLenient(const ODIM & odim);
226
227 void completeEncoding(const std::string & encoding);
228
230 inline
231 bool getTime(drain::Time & t) const {
232 return getTime(t, date, time);
233 }
234
236 inline
237 bool getStartTime(drain::Time & t) const {
238 return getTime(t, startdate, starttime);
239 }
240
242 inline
243 bool getEndTime(drain::Time & t) const {
244 return getTime(t, enddate, endtime);
245 }
246
248 bool setTime(const drain::Time & t);
249
251 bool setTime(const std::string & s);
252
253
255 virtual inline
257 //using namespace drain::image;
258 static const drain::image::CoordinatePolicy policy(drain::image::EdgePolicy::LIMIT);
259 return policy;
260 //return rack::limit;
261 }
262
264
269 bool distinguishNodata(const std::string & quantityPrefix = "");
270
271
273
286 template <group_t G, class T>
287 static inline
288 void updateH5AttributeGroups(const T &odim, Hi5Tree & dst) {
289 static const T odimLimited(G);
290 static const std::list<std::string> & keys = odimLimited.getKeyList();
291 //odim.copyTo(odimLimited.getKeyList(), dst);
292 odim.copyTo(keys, dst);
293 }
294
295 template <group_t G, class T>
296 static inline
297 void updateH5AttributeGroups(const T &odim, const Hi5Tree & dst) {
298 //static T odimLimited(G);
299 //odim.copyTo(odimLimited.getKeyList(), dst);
300 }
301
302
303
304
305 // Maximum Nyquist velocity, mutable because may be updated with PolarODIM::getNyquist()
306 mutable
307 double NI;
308
309
310
311//protected:
312
313 static
315 bool getTime(drain::Time & t, const std::string &dateStr, const std::string &timeStr); // const;
316
317protected:
318
320 void copyTo(const std::list<std::string> & keys, Hi5Tree & dst) const;
321
322
323 template <class T>
324 inline
325 void initFromMap(const std::map<std::string,T> & m){
327 updateFromMap(m);
328 }
329
330 virtual inline
331 void initFromImage(const drain::image::Image & img){ // =""
333 this->quantity = img.getProperties().get("what:quantity", "");
334 copyFrom(img);
335 }
336
337 // deprec
338 virtual inline
339 void initFromImage(const drain::image::Image & img, const std::string & quantity){ // =""
340 drain::Logger mout(__FILE__, __FUNCTION__);
342 this->quantity = quantity;
343 copyFrom(img);
344 //mout.warn("guantity finally=(" , this->quantity , '<' , quantity , ")" );
345 //mout.warn(*this );
346 }
347
348private:
349
350
351 virtual // must
352 void init(group_t initialize =ODIMPathElem::ALL_LEVELS);
353
354
355
356};
357
358
359inline
360std::ostream & operator<<(std::ostream &ostr, const ODIM & odim){
361 odim.drain::SmartMap<drain::Reference>::toStream(ostr);
362 return ostr;
363}
364
365
366
367
368} // namespace rack
369
370
371#endif
Flagger accepting values of enum type E.
Definition EnumFlags.h:190
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
void updateFromMap(const std::map< std::string, T2 > &m)
Assign values from a map. Updates existing entries only.
Definition SmartMap.h:294
std::string get(const std::string &key, const std::string &defaultValue) const
Retrieves a value, or default value if value is unset.
Definition SmartMap.h:127
Utility for handling time. Internally, uses tm (C time structure).
Definition Time.h:54
Policies for coordinate underflows and overflows.
Definition CoordinatePolicy.h:106
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:75
EncodingODIM(group_t initialize=ODIMPathElem::ALL_LEVELS)
Default constructor.
Definition EncodingODIM.h:99
void copyFrom(const drain::image::Image &data)
Copies image attributes and type . Experimental.
Definition EncodingODIM.cpp:269
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
virtual void updateLenient(const ODIM &odim)
Updates object, quantity, product and time information.
Definition ODIM.cpp:374
Version
Definition ODIM.h:83
@ ODIM_2_3
Definition ODIM.h:87
@ ODIM_2_4
Definition ODIM.h:89
drain::Point2D< double > resolution
Spatial resolution in metres.
Definition ODIM.h:156
virtual void adjustGeometry(size_t cols, size_t rows)
Change geometry and adjust spatial resolution respectively.
Definition ODIM.cpp:289
bool getTime(drain::Time &t) const
Retrieves the stored time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:231
virtual void setGeometry(size_t cols, size_t rows)
Sets number of columns (nbins) and number of rows (nrays). Does not change resolution.
Definition ODIM.h:199
bool getStartTime(drain::Time &t) const
Retrieves the start time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:237
std::string object
Definition ODIM.h:171
std::string date
Nominal time, in dateformat.
Definition ODIM.h:175
static void updateH5AttributeGroups(const T &odim, Hi5Tree &dst)
Write ODIM metadata to WHAT, WHERE and HOW groups.
Definition ODIM.h:288
bool distinguishNodata(const std::string &quantityPrefix="")
If nodata==undetect, set nodata=maxValue (hoping its not nodata...)
Definition ODIM.cpp:101
static const std::string dateformat
Applied 8-digit date format, "%Y%m%d".
Definition ODIM.h:162
std::string time
Nominal time, in timeformat.
Definition ODIM.h:177
bool getEndTime(drain::Time &t) const
Retrieves the end time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:243
static const std::string timeformat
Applied 6-digit date format, "%H%M%S".
Definition ODIM.h:166
bool setTime(const drain::Time &t)
Sets date and time . Returns true if successful, throws error if fail.
Definition ODIM.cpp:241
std::string quantity
dataX/what (obligatory)
Definition ODIM.h:181
virtual const drain::image::CoordinatePolicy & getCoordinatePolicy() const
Returns recommended coordinate policy. Redefined in PolarODIM.
Definition ODIM.h:256
Definition DataSelector.cpp:44
Definition Point.h:48