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
197 // NEW - moved from ProductBase: applyODIM
198 void configureNEW(const ODIM & defaultODIM, bool useTypeDefaults=false);
199
200 // Moved/copied from ProductBase::setODIMspecials(productODIM);
201 void setSpecials();
202
204 virtual inline
205 void setGeometry(size_t cols, size_t rows){
206 area.set(cols, rows);
207 };
208
209
210 virtual
212 setGeometry(g.getWidth(), g.getHeight());
213 };
214
215 virtual // ?
216 const drain::image::AreaGeometry & getGeometry() const {
217 return area;
218 };
219
221 virtual
222 void adjustGeometry(size_t cols, size_t rows);
223
224
225
227
230 virtual
231 void updateLenient(const ODIM & odim);
232
233 void completeEncoding(const std::string & encoding);
234
236 inline
237 bool getTime(drain::Time & t) const {
238 return getTime(t, date, time);
239 }
240
242 inline
243 bool getStartTime(drain::Time & t) const {
244 return getTime(t, startdate, starttime);
245 }
246
248 inline
249 bool getEndTime(drain::Time & t) const {
250 return getTime(t, enddate, endtime);
251 }
252
254 bool setTime(const drain::Time & t);
255
257 bool setTime(const std::string & s);
258
259
261 virtual inline
263 //using namespace drain::image;
264 static const drain::image::CoordinatePolicy policy(drain::image::EdgePolicy::LIMIT);
265 return policy;
266 //return rack::limit;
267 }
268
270
275 bool distinguishNodata(const std::string & quantityPrefix = "");
276
277
279
292 template <group_t G, class T>
293 static inline
294 void updateH5AttributeGroups(const T &odim, Hi5Tree & dst) {
295 static const T odimLimited(G);
296 static const std::list<std::string> & keys = odimLimited.getKeyList();
297 //odim.copyTo(odimLimited.getKeyList(), dst);
298 odim.copyTo(keys, dst);
299 }
300
301 template <group_t G, class T>
302 static inline
303 void updateH5AttributeGroups(const T &odim, const Hi5Tree & dst) {
304 //static T odimLimited(G);
305 //odim.copyTo(odimLimited.getKeyList(), dst);
306 }
307
308
309
310
311 // Maximum Nyquist velocity, mutable because may be updated with PolarODIM::getNyquist()
312 mutable
313 double NI;
314
315
316
317//protected:
318
319 static
321 bool getTime(drain::Time & t, const std::string &dateStr, const std::string &timeStr); // const;
322
323protected:
324
326 void copyTo(const std::list<std::string> & keys, Hi5Tree & dst) const;
327
328
329 template <class T>
330 inline
331 void initFromMap(const std::map<std::string,T> & m){
333 updateFromMap(m);
334 }
335
336 virtual inline
337 void initFromImage(const drain::image::Image & img){ // =""
339 this->quantity = img.getProperties().get("what:quantity", "");
340 copyFrom(img);
341 }
342
343 // deprec
344 virtual inline
345 void initFromImage(const drain::image::Image & img, const std::string & quantity){ // =""
346 drain::Logger mout(__FILE__, __FUNCTION__);
348 this->quantity = quantity;
349 copyFrom(img);
350 //mout.warn("guantity finally=(" , this->quantity , '<' , quantity , ")" );
351 //mout.warn(*this );
352 }
353
354private:
355
356
357 virtual // must
358 void init(group_t initialize =ODIMPathElem::ALL_LEVELS);
359
360
361
362};
363
364
365inline
366std::ostream & operator<<(std::ostream &ostr, const ODIM & odim){
367 odim.drain::SmartMap<drain::Reference>::toStream(ostr);
368 return ostr;
369}
370
371
372
373
374} // namespace rack
375
376DRAIN_ENUM_DICT(rack::ODIM::Version);
377DRAIN_ENUM_OSTREAM(rack::ODIM::Version);
378
379
380#endif
Default default value...
Definition EnumFlags.h:247
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
void updateFromMap(const std::map< std::string, T2 > &m)
Assign values from a map. Updates existing entries only.
Definition SmartMap.h:286
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:455
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:237
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:205
bool getStartTime(drain::Time &t) const
Retrieves the start time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:243
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:294
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:249
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:262
Definition DataSelector.cpp:44
Definition Point.h:48