Loading...
Searching...
No Matches
resources.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
32// # pragma once
33#ifndef RACK_RESOURCES_H_
34#define RACK_RESOURCES_H_
35
36#include <string>
37
38#include <drain/RegExp.h>
39#include <drain/image/Image.h>
40#include <drain/imageops/ImageModifierPack.h>
41#include <drain/imageops/PaletteOp.h>
42#include <drain/prog/CommandBankUtils.h>
43#include <drain/util/Rectangle.h>
44#include <drain/util/StatusFlags.h>
45#include <drain/util/TreeOrdered.h>
46//#include <drain/util/Variable.h>
47
48#include "hi5/Hi5.h"
49#include "hi5/Hi5Read.h"
50#include "data/DataSelector.h"
51#include "data/PolarODIM.h"
52#include "data/ProductConf.h"
53#include "data/VariableFormatterODIM.h"
54#include "radar/Composite.h"
55#include "radar/RadarAccumulator.h"
56
57#include "resources-base.h"
58
59namespace rack {
60
62
63 inline
64 PolarAreaSelector() : BeanLike(__FUNCTION__, ""){
65 };
66
67
68 drain::Range<double> distance = {0.0, 250.0};
69 drain::Range<double> azimuth = {0.0, 360.0};
70
71};
72
74
77class RackContext : public ProductConf, public drain::SmartContext, public GraphicsContext, public ImageContext, public AndreContext, public Hdf5Context {
78
79public:
80
81
82
85
87 RackContext(const RackContext & ctx);
88
89 virtual
90 ~RackContext(){};
91
92
93 static
94 RackContext & getSharedContext(){
96 }
97
98 // Consider validVariableRE as general init parameter?
99 static
101
102 std::string getFormattedStatus(const std::string & s) const;
103
104 // DataSelector superSelector;
105
106 //static
107 //const drain::RegExp variableMapperSyntax;inputFilter
108 //drain::SingleFlagger<Reader::Mode>
109 // drain::SingleFlagger<hi5::Reader::Mode>
110 hi5::Reader::ModeFlagger inputFilter;
111
113 std::string inputPrefix;
114
116 std::string outputPrefix;
117
119 void resolveFilePath(const std::string & prefix, const std::string & filePath, std::string & finalFilePath);
120
121 PolarAreaSelector polarAreaSelector;
122
123
124 // Accumulator for data in Cartesian coordinates
125 Composite composite;
126
127 // Experimental
128 bool guessDatasetGroup(const Hi5Tree & src, ODIMPathElem & pathElem) const;
129
130 bool guessDatasetGroup(ODIMPathElem & pathElem){
131 Hi5Tree & src = getHi5(CURRENT);
132 return guessDatasetGroup(src, pathElem);
133 }
134
135
136
141 //inline
142 //Hi5Tree & getHi5(h5_role::value_t filter);
143 // return getHi5Full(filter);
144 // }
145
147
152 // template <typename T, typename ...TT>
153 // Hi5Tree & getHi5(const T &filter, const TT &... filters){
154 template <typename ...TT>
155 Hi5Tree & getHi5(const Hi5RoleFlagger::ivalue_t &filter, const TT &... filters){
156
157 Hi5RoleFlagger::ivalue_t f(filter);
158 // Hi5Tree & dst = getHi5Full(f);
159 if (f != 0){
160 // return dst;
161 // Hi5Tree & dst = getHi5Full(f);
162 return getHi5Full(f);
163 }
164 else
165 return getHi5(filters...);
166 }
167
168
169
170 //Hi5Tree & getHi5Full(h5_role::ivalue_t & filter);
171 Hi5Tree & getHi5Full(Hi5RoleFlagger::ivalue_t filter);
172
173 inline
174 Hi5Tree & getHi5(){
175 return empty; // or current?
176 }
177
184 Composite & getComposite(Hi5RoleFlagger::ivalue_t filter);
185
186
187 // Experimental
188 // ODIMPath currentPath;
189
191 //static
192 ODIMPath findImage(const DataSelector & imageSelector);
193
194 // static
195 ODIMPath findImage();
196
198 // sstatic
199 const drain::image::Image & getCurrentGrayImage(); //RackContext & ctx);
200
202 const drain::image::Image & getCurrentImage(); //RackContext & ctx);
203
204
206
210 const drain::image::Image & updateCurrentImage(); //RackContext & ctx);
211
213 drain::image::Image & getModifiableImage(); // (RackContext & ctx); // const DataSelector & selector
214
215 void convertGrayImage(const drain::image::Image & srcImage); // RackContext & ctx,
216
217 /*
218 virtual inline
219 drain::VariableMap & getStatusMap(bool update=true){
220 if (update){
221 Context::updateStatus(); // check if this should be moved under this->updateStatus() ? So this function could be removed.
222 updateStatus();
223 }
224 return statusMap;
225 };
226 */
227
228 static
229 const VariableFormatterODIM<drain::Variable> variableFormatter;
230
231 static
232 const VariableFormatterODIM<drain::FlexibleVariable> flexVariableFormatter;
233
234//private:
235protected:
236
237 virtual
238 void updateStatus() const final;
239 // Keep this class-specific.
240 //void updateStatus();
241
242 // typedef drain::Cloner<Context,RackContext> ctx_cloner_t;
243
244 // EXPERIMENTAL
245 static inline
246 RackContext & baseCtx() {
247 //return getContextCloner().getSourceOrig();
248 return drain::Static::get<RackContext>();
249 }
250
251 /*
252 static inline
253 ctx_cloner_t & getContextCloner(){
254 return getCloner<RackContext>();
255 }
256 */
257
258};
259
261
264class RackResources : public drain::SuperContextual<RackContext> {
265
266public:
267
268 RackResources(); // : inputOk(true), dataOk(true), currentHi5(&inputHi5), currentPolarHi5(&inputHi5), currentImage(NULL), currentGrayImage(NULL) {};
269
270 // Accumulator for data in polar coordinates
272
273
274};
275
278
279
280
281
282} /* namespace rack */
283
284#endif /* RACKLET_H_ */
285
286// Rack
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:60
Definition Range.h:52
Definition Context.h:208
A tool for expanding variables embedded in a std::string to literals.
Definition StringMapper.h:275
Adds class-specific convenience functions.
Definition Context.h:322
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
Definition resources-base.h:54
Cartesian composite (mosaic) of data from several radars.
Definition Composite.h:102
Definition resources-image.h:221
Definition resources-base.h:74
Definition resources-image.h:289
Definition ODIMPath.h:82
Shared properties for meteorological products and Cartesian products (composites and single-radar ima...
Definition ProductConf.h:64
Resources provided separately for each thread.
Definition resources.h:77
static const drain::StringMapper variableMapper
Definition resources.h:100
Composite & getComposite(Hi5RoleFlagger::ivalue_t filter)
Definition resources.cpp:196
drain::image::Image & getModifiableImage()
Return current image, if modifiable. Else, copy (convert).
Definition resources.cpp:469
const drain::image::Image & getCurrentGrayImage()
Light and lazy.
Definition resources.cpp:235
RackContext()
Initializes data and image pointers to default targets or NULL.
Definition resources.cpp:42
const drain::image::Image & getCurrentImage()
Light and lazy.
Definition resources.cpp:253
Hi5RoleFlagger inputFlags
Definition resources.h:146
std::string inputPrefix
Path prefix for input files. Move to resources?
Definition resources.h:113
virtual void updateStatus() const final
Definition resources.cpp:551
void convertGrayImage(const drain::image::Image &srcImage)
Definition resources.cpp:433
Hi5Tree & getHi5(const Hi5RoleFlagger::ivalue_t &filter, const TT &... filters)
Definition resources.h:155
const drain::image::Image & updateCurrentImage()
Ensures current image.
Definition resources.cpp:373
void resolveFilePath(const std::string &prefix, const std::string &filePath, std::string &finalFilePath)
Add prefix, unless filePath starts with a slash '/'.
Definition resources.cpp:63
std::string outputPrefix
Path prefix for output files. Move to resources?
Definition resources.h:116
A container for shared resources applied by RackLets.
Definition resources.h:264
Data array for creating composites and accumulated polar products (Surface rain fall or cluttermaps)
Definition RadarAccumulator.h:122
Definition DataSelector.cpp:44
RackResources & getResources()
Default instance.
Definition resources.cpp:604
Definition resources.h:61