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
155 T f(filter);
156 //Hi5Tree & dst = getHi5Full(f);
157 if (f != 0){
158 // return dst;
159 //Hi5Tree & dst = getHi5Full(f);
160 return getHi5Full(f);
161 }
162 else
163 return getHi5(filters...);
164 }
165
166
167
168 //Hi5Tree & getHi5Full(h5_role::ivalue_t & filter);
169 Hi5Tree & getHi5Full(Hi5RoleFlagger::ivalue_t filter);
170
171 inline
172 Hi5Tree & getHi5(){
173 return empty; // or current?
174 }
175
182 Composite & getComposite(Hi5RoleFlagger::ivalue_t filter);
183
184
185 // Experimental
186 // ODIMPath currentPath;
187
189 //static
190 ODIMPath findImage(const DataSelector & imageSelector);
191
192 // static
193 ODIMPath findImage();
194
196 // sstatic
197 const drain::image::Image & getCurrentGrayImage(); //RackContext & ctx);
198
200 const drain::image::Image & getCurrentImage(); //RackContext & ctx);
201
202
204
208 const drain::image::Image & updateCurrentImage(); //RackContext & ctx);
209
211 drain::image::Image & getModifiableImage(); // (RackContext & ctx); // const DataSelector & selector
212
213 void convertGrayImage(const drain::image::Image & srcImage); // RackContext & ctx,
214
215 /*
216 virtual inline
217 drain::VariableMap & getStatusMap(bool update=true){
218 if (update){
219 Context::updateStatus(); // check if this should be moved under this->updateStatus() ? So this function could be removed.
220 updateStatus();
221 }
222 return statusMap;
223 };
224 */
225
226 static
227 const VariableFormatterODIM<drain::Variable> variableFormatter;
228
229 static
230 const VariableFormatterODIM<drain::FlexibleVariable> flexVariableFormatter;
231
232//private:
233protected:
234
235 virtual
236 void updateStatus() const final;
237 // Keep this class-specific.
238 //void updateStatus();
239
240 // typedef drain::Cloner<Context,RackContext> ctx_cloner_t;
241
242 // EXPERIMENTAL
243 static inline
244 RackContext & baseCtx() {
245 //return getContextCloner().getSourceOrig();
246 return drain::Static::get<RackContext>();
247 }
248
249 /*
250 static inline
251 ctx_cloner_t & getContextCloner(){
252 return getCloner<RackContext>();
253 }
254 */
255
256};
257
259
262class RackResources : public drain::SuperContextual<RackContext> {
263
264public:
265
266 RackResources(); // : inputOk(true), dataOk(true), currentHi5(&inputHi5), currentPolarHi5(&inputHi5), currentImage(NULL), currentGrayImage(NULL) {};
267
268 // Accumulator for data in polar coordinates
270
271
272};
273
276
277
278
279
280} /* namespace rack */
281
282#endif /* RACKLET_H_ */
283
284// 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:205
A tool for expanding variables embedded in a std::string to literals.
Definition StringMapper.h:275
Adds class-specific convenience functions.
Definition Context.h:319
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:218
Definition resources-base.h:74
Definition resources-image.h:283
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
Hi5Tree & getHi5(const T &filter, const TT &... filters)
Definition resources.h:153
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
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:262
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