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
111 inline
112 ODIM(group_t initialize = ODIMPathElem::ALL_LEVELS) : EncodingODIM(initialize){
113 init(initialize);
114 };
115
116 // TODO: CHECK: -Wdeprecated-copy fires because this copy constructor is user-declared but
117 // operator= is not. Unlike EncodingODIM's own operator= (which only copies a narrow set of
118 // scalar encoding fields via copyEncoding()), this copy constructor calls initFromMap(odim),
119 // copying the full set of registered ODIM attributes (date, time, source, product, etc.).
120 // The implicit operator= (inherited from EncodingODIM's narrower one, plus memberwise NI)
121 // would NOT replicate that - so adding a naive `=default`/inherited operator= here would be
122 // semantically incomplete, not just a warning-silencing no-op. Needs a real decision.
124 inline
125 ODIM(const ODIM & odim) : EncodingODIM(ODIMPathElem::ALL_LEVELS), NI(odim.NI){
126 initFromMap(odim);
127 };
128
130 inline
131 ODIM(const drain::image::Image & image, const std::string & quantity="") : EncodingODIM(image) {
132 initFromImage(image, quantity);
133 };
134
136 inline
137 ODIM(drain::image::Image & image, const std::string & quantity="") : EncodingODIM(image) {
138 initFromImage(image, quantity);
139 };
140
141 /*
142 inline
143 ODIM(const drain::image::Image & image, const std::string & quantity="") : EncodingODIM(image) {
144 initFromImage(image, quantity);
145 };
146 */
147
148 /*
149 inline
150 ODIM(drain::image::Image & image, const std::string & quantity="") : geometryREF(image.geometry) {
151 initFromImage(image, quantity);
152 };
153 */
154
155 inline
156 ~ODIM(){};
157
158 //const drain::image::AreaGeometry geometry;
159
161
163
168
169 //const drain::image::AreaGeometry & geometryTEST;
170
172 static
173 const std::string dateformat;
174
176 static
177 const std::string timeformat;
178
179
182 std::string object;
183 std::string version;
184
186 std::string date;
188 std::string time;
189 std::string source;
190
192 std::string quantity; // raise?
193 std::string product; // raise?
194 std::string prodpar; // raise?
195 std::string startdate;
196 std::string starttime;
197 std::string enddate;
198 std::string endtime;
199
200 // Elevation angles.
201 // In ODIM, defined for Cartesian but used more generally - for polar products - in Rack
202 std::vector<double> angles;
203 // double angles = 0.0; // FIX!
204
205
206 // Number of images used in precipitation accumulation (lenient, not linked)
207 long ACCnum = 0;
208
209 // NEW - moved from ProductBase: applyODIM
210 void configureNEW(const ODIM & defaultODIM, bool useTypeDefaults=false);
211
212 // Moved/copied from ProductBase::setODIMspecials(productODIM);
213 void setSpecials();
214
216 virtual inline
217 void setGeometry(size_t cols, size_t rows){
218 area.set(cols, rows);
219 };
220
221
222 virtual
224 setGeometry(g.getWidth(), g.getHeight());
225 };
226
227 virtual // ?
228 const drain::image::AreaGeometry & getGeometry() const {
229 return area;
230 };
231
233 virtual
234 void adjustGeometry(size_t cols, size_t rows);
235
236
237
239
242 virtual
243 void updateLenient(const ODIM & odim);
244
245 void completeEncoding(const std::string & encoding);
246
248 inline
249 bool getTime(drain::Time & t) const {
250 return getTime(t, date, time);
251 }
252
254 inline
255 bool getStartTime(drain::Time & t) const {
256 return getTime(t, startdate, starttime);
257 }
258
260 inline
261 bool getEndTime(drain::Time & t) const {
262 return getTime(t, enddate, endtime);
263 }
264
266 bool setTime(const drain::Time & t);
267
269 bool setTime(const std::string & s);
270
271
273 virtual inline
275 //using namespace drain::image;
276 static const drain::image::CoordinatePolicy policy(drain::image::EdgePolicy::LIMIT);
277 return policy;
278 //return rack::limit;
279 }
280
282
287 bool distinguishNodata(const std::string & quantityPrefix = "");
288
289
291
304 template <group_t G, class T>
305 static inline
306 void updateH5AttributeGroups(const T &odim, Hi5Tree & dst) {
307 static const T odimLimited(G);
308 static const std::list<std::string> & keys = odimLimited.getKeyList();
309 //odim.copyTo(odimLimited.getKeyList(), dst);
310 odim.copyTo(keys, dst);
311 }
312
313 template <group_t G, class T>
314 static inline
315 void updateH5AttributeGroups(const T &, const Hi5Tree &) {
316 // void updateH5AttributeGroups(const T &odim, const Hi5Tree & dst) {
317 //static T odimLimited(G);
318 //odim.copyTo(odimLimited.getKeyList(), dst);
319 }
320
321
322
323
324 // Maximum Nyquist velocity, mutable because may be updated with PolarODIM::getNyquist()
325 mutable
326 double NI;
327
328
329
330//protected:
331
332 static
334 bool getTime(drain::Time & t, const std::string &dateStr, const std::string &timeStr); // const;
335
336protected:
337
339 void copyTo(const std::list<std::string> & keys, Hi5Tree & dst) const;
340
341
342 template <class T>
343 inline
344 void initFromMap(const std::map<std::string,T> & m){
346 updateFromMap(m);
347 }
348
349 virtual inline
350 void initFromImage(const drain::image::Image & img){ // =""
352 this->quantity = img.getProperties().get("what:quantity", "");
353 copyFrom(img);
354 }
355
356 // deprec
357 virtual inline
358 void initFromImage(const drain::image::Image & img, const std::string & quantity){ // =""
359 drain::Logger mout(__FILE__, __FUNCTION__);
361 this->quantity = quantity;
362 copyFrom(img);
363 //mout.warn("guantity finally=(" , this->quantity , '<' , quantity , ")" );
364 //mout.warn(*this );
365 }
366
367private:
368
369
370 virtual // must
371 void init(group_t initialize =ODIMPathElem::ALL_LEVELS);
372
373
374
375};
376
377
378inline
379std::ostream & operator<<(std::ostream &ostr, const ODIM & odim){
380 odim.drain::SmartMap<drain::Reference>::toStream(ostr);
381 return ostr;
382}
383
384
385
386
387} // namespace rack
388
389DRAIN_ENUM_DICT(rack::ODIM::Version);
390DRAIN_ENUM_OSTREAM(rack::ODIM::Version)
391
392
393#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:326
void updateFromMap(const std::map< std::string, T2 > &m)
Assign values from a map. Updates existing entries only.
Definition SmartMap.h:282
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:128
Utility for handling time. Internally, uses tm (C time structure).
Definition Time.h:53
Policies for coordinate underflows and overflows.
Definition CoordinatePolicy.h:100
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:70
void copyFrom(const drain::image::Image &data)
Copies image attributes and type . Experimental.
Definition EncodingODIM.cpp:269
DOC: Add class description.
Definition ODIMPath.h:82
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:469
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:167
ODIM(const drain::image::Image &image, const std::string &quantity="")
Constructor initializing ODIM from image metadata.
Definition ODIM.h:131
virtual void adjustGeometry(size_t cols, size_t rows)
Change geometry and adjust spatial resolution respectively.
Definition ODIM.cpp:295
ODIM(group_t initialize=ODIMPathElem::ALL_LEVELS)
Default constructor.
Definition ODIM.h:112
bool getTime(drain::Time &t) const
Retrieves the stored time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:249
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:217
bool getStartTime(drain::Time &t) const
Retrieves the start time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:255
ODIM(drain::image::Image &image, const std::string &quantity="")
Constructor initializing ODIM from image metadata.
Definition ODIM.h:137
std::string object
Definition ODIM.h:182
ODIM(const ODIM &odim)
Copy constructor.
Definition ODIM.h:125
std::string date
Nominal time, in dateformat.
Definition ODIM.h:186
static void updateH5AttributeGroups(const T &odim, Hi5Tree &dst)
Write ODIM metadata to WHAT, WHERE and HOW groups.
Definition ODIM.h:306
bool distinguishNodata(const std::string &quantityPrefix="")
If nodata==undetect, set nodata=maxValue (hoping its not nodata...)
Definition ODIM.cpp:107
static const std::string dateformat
Applied 8-digit date format, "%Y%m%d".
Definition ODIM.h:173
std::string time
Nominal time, in timeformat.
Definition ODIM.h:188
bool getEndTime(drain::Time &t) const
Retrieves the end time. Returns true if successful. // consider: throws error if fail.
Definition ODIM.h:261
static const std::string timeformat
Applied 6-digit date format, "%H%M%S".
Definition ODIM.h:177
bool setTime(const drain::Time &t)
Sets date and time . Returns true if successful, throws error if fail.
Definition ODIM.cpp:247
std::string quantity
dataX/what (obligatory)
Definition ODIM.h:192
virtual const drain::image::CoordinatePolicy & getCoordinatePolicy() const
Returns recommended coordinate policy. Redefined in PolarODIM.
Definition ODIM.h:274
Definition AltitudeOp.cpp:42
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
Definition Point.h:48