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 // double angles = 0.0; // FIX!
193
194
195 // Number of images used in precipitation accumulation (lenient, not linked)
196 long ACCnum = 0;
197
198 // NEW - moved from ProductBase: applyODIM
199 void configureNEW(const ODIM & defaultODIM, bool useTypeDefaults=false);
200
201 // Moved/copied from ProductBase::setODIMspecials(productODIM);
202 void setSpecials();
203
205 virtual inline
206 void setGeometry(size_t cols, size_t rows){
207 area.set(cols, rows);
208 };
209
210
211 virtual
213 setGeometry(g.getWidth(), g.getHeight());
214 };
215
216 virtual // ?
217 const drain::image::AreaGeometry & getGeometry() const {
218 return area;
219 };
220
222 virtual
223 void adjustGeometry(size_t cols, size_t rows);
224
225
226
228
231 virtual
232 void updateLenient(const ODIM & odim);
233
234 void completeEncoding(const std::string & encoding);
235
237 inline
238 bool getTime(drain::Time & t) const {
239 return getTime(t, date, time);
240 }
241
243 inline
244 bool getStartTime(drain::Time & t) const {
245 return getTime(t, startdate, starttime);
246 }
247
249 inline
250 bool getEndTime(drain::Time & t) const {
251 return getTime(t, enddate, endtime);
252 }
253
255 bool setTime(const drain::Time & t);
256
258 bool setTime(const std::string & s);
259
260
262 virtual inline
264 //using namespace drain::image;
265 static const drain::image::CoordinatePolicy policy(drain::image::EdgePolicy::LIMIT);
266 return policy;
267 //return rack::limit;
268 }
269
271
276 bool distinguishNodata(const std::string & quantityPrefix = "");
277
278
280
293 template <group_t G, class T>
294 static inline
295 void updateH5AttributeGroups(const T &odim, Hi5Tree & dst) {
296 static const T odimLimited(G);
297 static const std::list<std::string> & keys = odimLimited.getKeyList();
298 //odim.copyTo(odimLimited.getKeyList(), dst);
299 odim.copyTo(keys, dst);
300 }
301
302 template <group_t G, class T>
303 static inline
304 void updateH5AttributeGroups(const T &odim, const Hi5Tree & dst) {
305 //static T odimLimited(G);
306 //odim.copyTo(odimLimited.getKeyList(), dst);
307 }
308
309
310
311
312 // Maximum Nyquist velocity, mutable because may be updated with PolarODIM::getNyquist()
313 mutable
314 double NI;
315
316
317
318//protected:
319
320 static
322 bool getTime(drain::Time & t, const std::string &dateStr, const std::string &timeStr); // const;
323
324protected:
325
327 void copyTo(const std::list<std::string> & keys, Hi5Tree & dst) const;
328
329
330 template <class T>
331 inline
332 void initFromMap(const std::map<std::string,T> & m){
334 updateFromMap(m);
335 }
336
337 virtual inline
338 void initFromImage(const drain::image::Image & img){ // =""
340 this->quantity = img.getProperties().get("what:quantity", "");
341 copyFrom(img);
342 }
343
344 // deprec
345 virtual inline
346 void initFromImage(const drain::image::Image & img, const std::string & quantity){ // =""
347 drain::Logger mout(__FILE__, __FUNCTION__);
349 this->quantity = quantity;
350 copyFrom(img);
351 //mout.warn("guantity finally=(" , this->quantity , '<' , quantity , ")" );
352 //mout.warn(*this );
353 }
354
355private:
356
357
358 virtual // must
359 void init(group_t initialize =ODIMPathElem::ALL_LEVELS);
360
361
362
363};
364
365
366inline
367std::ostream & operator<<(std::ostream &ostr, const ODIM & odim){
368 odim.drain::SmartMap<drain::Reference>::toStream(ostr);
369 return ostr;
370}
371
372
373
374
375} // namespace rack
376
377DRAIN_ENUM_DICT(rack::ODIM::Version);
378DRAIN_ENUM_OSTREAM(rack::ODIM::Version);
379
380
381#endif
Flagger accepting values of enum type E.
Definition EnumFlagger.h:56
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:238
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:206
bool getStartTime(drain::Time &t) const
Retrieves the start time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:244
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:295
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:250
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:263
Definition DataSelector.cpp:44
Definition Point.h:48