cartesian-create.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 
32 
33 #ifndef RACK_CART_CREATE
34 #define RACK_CART_CREATE
35 
36 
37 
38 #include <drain/prog/CommandInstaller.h>
39 #include "resources.h"
40 
41 #include "composite.h"
42 
43 namespace rack {
44 
45 
46 
48 
54 class CartesianCreate : public Compositor {
55 
56 public:
57 
58 
59  CartesianCreate() : Compositor(__FUNCTION__, "Maps the current polar product to a Cartesian product."){
60  }
61 
62 
63  inline
64  void exec() const {
65 
66  RackContext & ctx = getContext<RackContext>();
67  drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
68 
69  Composite & composite = ctx.getComposite(RackContext::PRIVATE);
70 
71  mout.attention<LOG_DEBUG>("composite*: ", &composite, " accArray: ", composite.accArray);
72 
73  //composite.reset();
74  composite.accArray.reset(); // Not frame, otherwise --cSize spoiled
75  composite.dataSelector.reset();
76  composite.odim.clear();
77  composite.nodeMap.clear();
78  //composite.odim.source.clear();
79 
80  // mout.attention("Composite counter N=", composite.odim.ACCnum, ")");
81 
82  if (composite.odim.ACCnum > 0){ // .counter
83  // mout.experimental("Clearing previous composite? N=", composite.counter, ")");
84  // mout.experimental("Clearing previous composite? N=", composite.odim.ACCnum, ")");
85  mout.hint<LOG_DEBUG>("Clearing previous composite. If that was not meant, use --cAdd to add, instead.");
86  composite.accArray.clear();
87  // clear metadata?
88  }
89 
90  // mout.attention("start add: ", composite.getTargetEncoding(), " odim.quantity=", composite.odim.quantity, " sel:", composite.dataSelector);
91  composite.odim.quantity = "";
92 
93  add(composite, RackContext::POLAR|RackContext::CURRENT, true);
94 
95  if (ctx.statusFlags.value > 0){
96  mout.warn("errors (", ctx.statusFlags, "), skipping extraction");
97  return;
98  }
99 
100  const drain::StringMatcher qualityMatcher("QIND"); // coming op: other
101 
102  if (qualityMatcher.test(composite.odim.quantity)){
103  mout.note("Quality [", composite.odim.quantity, "] as input: extracting data only");
104  extract(composite, "d");
105  }
106  else {
107  extract(composite, "dw");
108  }
109  // mout.attention("extract dw");
110 
111 
112  // When are these needed? Upon one-liner DBZH, VRAD singles?
113  composite.dataSelector.setQuantities(""); // why quantity only?
114  // mout.experimental("quantity ["," clearance removed");
115  composite.odim.quantity.clear();
116 
117  // mout.attention("angles: ", drain::sprinter(composite.odim.angles, "<>"));
118 
119  // better without...
120  // ctx.cartesianHi5[ODIMPathElem::WHAT].data.attributes["source2"] = (*ctx.currentPolarHi5)["what"].data.attributes["source"];
121  }
122 
123 };
124 
125 
127 
128 public:
129 
130  inline
131  CompositeCreateTile() : Compositor(__FUNCTION__, "Maps the current polar product to a tile to be used in compositing."){
132  }
133 
134  inline
135  void exec() const {
136 
137  RackContext & ctx = getContext<RackContext>();
138  drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
139 
140  //Composite & composite = getComposite();
141  Composite & composite = ctx.composite;
142 
143  if (!composite.geometryIsSet())
144  mout.error("Composite geometry undefined, cannot create tile");
145 
146  if (! composite.bboxIsSet())
147  mout.error("Bounding box undefined, cannot create tile");
148 
149  if (! composite.projectionIsSet()) // or use first input (bbox reset)
150  mout.error("Projection undefined, cannot create tile");
151 
152  if ((composite.odim.ACCnum > 0) || (!composite.odim.quantity.empty())){
153  mout.debug("Clearing previous composite...");
154  // Consider: composite.clear() ?
155  composite.accArray.clear();
156  composite.odim.quantity.clear();
157  composite.odim.ACCnum = 0;
158  composite.odim.scaling.set(0,0);
159  composite.odim.type.clear(); // ? risky
160  mout.info("Cleared previous composite");
161  }
162 
163 
164  composite.setCropping(true);
165  //add(composite, RackContext::POLAR|RackContext::CURRENT);
166  add(composite, RackContext::POLAR|RackContext::CURRENT, true); // updateSelector
167  extract(composite, "dw");
168 
169  // "Debugging"
170  if (!composite.isCropping()){
171  mout.warn("Composite cropping switched off during op");
172  mout.error("? Programming error in parallel comp design");
173  }
174 
175  composite.setCropping(false);
176 
177  }
178 
179 private:
180 
181 
182  // const CompositeAdd & addCmd;
183  // const CompositeExtract & extractCmd;
184 };
185 
186 
187 class CartesianRange : public drain::BasicCommand { //SimpleCommand<double> {
188 
189 public:
190 
191  inline
192  CartesianRange() : drain::BasicCommand(__FUNCTION__, "Force a range for single-radar cartesian products (0=use-metadata)."){
193  getParameters().link("range", PolarODIM::defaultRange, "km");
194  };
195 
196  inline
197  CartesianRange(const CartesianRange & cmd) : drain::BasicCommand(__FUNCTION__, cmd.getDescription()) {
198  getParameters().link("range", PolarODIM::defaultRange, "km");
199  };
200 
201 };
202 
204 
211 
212 public:
213 
214 
215  CartesianCreateLookup() : drain::BasicCommand(__FUNCTION__, "Creates lookup objects"){
216  }
217 
218 
219  inline
220  void exec() const {
221 
222  RackContext & ctx = getContext<RackContext>();
223  drain::Logger mout(ctx.log, __FILE__, __FUNCTION__);
224 
225  Composite & composite = ctx.getComposite(RackContext::PRIVATE);
226 
227  mout.debug("composite*: ", &composite, "accArray: ", composite.accArray);
228 
229  if (!ctx.polarInputHi5.empty())
230  mout.warn("polar input not empty");
231 
232  composite.createBinIndex(ctx.polarInputHi5);
233 
234 
235  }
236 
237 };
238 
240 
247 
248 public:
249 
250  CartesianReset() : drain::BasicCommand(__FUNCTION__, "Clears the current Cartesian product."){
251  }
252 
253  inline
254  void exec() const {
255 
256  RackContext & ctx = getContext<RackContext>();
257 
258  ctx.composite.reset();
259  // Consider including in reset:
261  ctx.composite.odim.source.clear();
262  ctx.composite.nodeMap.clear();
263  ctx.composite.metadataMap.clear();
264  // ctx.composite.projR2M.clear() !
265  // ctx.projStr.clear();
266 
267  ctx.composite.odim.clear(); // 2022/12
268  //ctx.composite.odim.type.clear();
269  //ctx.composite.odim.scaling.scale = 0.0;
270 
271  ctx.unsetCurrentImages();
272 
273  }
274 
275 };
276 
277 } // rack::
278 
279 
280 
281 #endif
282 
283 // Rack
Simple implementation of Command: adds name , description and parameters .
Definition: Command.h:417
StatusFlags statusFlags
Optional log filename (syntax): when defined, automatically opened by CommandBank::run()
Definition: Context.h:98
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & error(const TT &... args)
Echoes.
Definition: Log.h:412
Logger & attention(const TT &... args)
Possible error, but execution can continue. Special type of Logger::warn().
Definition: Log.h:472
Logger & note(const TT &... args)
For top-level information.
Definition: Log.h:485
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Logger & hint(const TT &... args)
Like advice, but weaker.
Definition: Log.h:630
General-purpose key matcher: tests string equality, or regExp, if defined as such.
Definition: StringMatcher.h:58
bool test(const std::string &s) const
Test with direct string matching or regExp, if defined.
Definition: StringMatcher.cpp:70
void clear()
Resets the accumulation array values to undetectValue. Does not change the geometry.
Definition: AccumulationArray.cpp:63
void reset()
Collapses the accumulation geometries to zero area.
Definition: AccumulationArray.h:151
AccumulationArray accArray
Todo: export.
Definition: Accumulator.h:80
bool bboxIsSet() const
Returns true, if the bounding box (geographical extent) has been set.
Definition: GeoFrame.h:99
bool geometryIsSet() const
Return true, if array area is greater than zero.
Definition: GeoFrame.h:89
bool projectionIsSet() const
Returns true, if the geographical extent has been set.
Definition: GeoFrame.h:83
Creates a single-radar Cartesian data set (2D data of both quantity and quality).
Definition: cartesian-create.h:210
void exec() const
Run the command with current parameter values.
Definition: cartesian-create.h:220
Creates a single-radar Cartesian data set (2D data of both quantity and quality).
Definition: cartesian-create.h:54
void exec() const
Run the command with current parameter values.
Definition: cartesian-create.h:64
Definition: cartesian-create.h:187
Creates a single-radar Cartesian data set (2D data of both quantity and quality).
Definition: cartesian-create.h:246
void exec() const
Run the command with current parameter values.
Definition: cartesian-create.h:254
Definition: cartesian-create.h:126
void exec() const
Run the command with current parameter values.
Definition: cartesian-create.h:135
Cartesian composite (mosaic) of data from several radars.
Definition: Composite.h:105
void setCropping(bool cropping=true)
If cropping is set, calling addPolar() also crops the bounding box to intersection of radar area and ...
Definition: Composite.h:145
void createBinIndex(Hi5Tree &dst)
Definition: Composite.cpp:440
drain::VariableMap nodeMap
Node keys (like "fivan") associated with upper left corner pixel coordinates [int] of the "tile".
Definition: Composite.h:189
drain::VariableMap metadataMap
EXPERIMENTAL: save elangles TODO: consider rename metadataMap (for hairy details)
Definition: Composite.h:192
Definition: composite.h:58
void add(Composite &composite, drain::Flags::ivalue_t inputFilter, bool updateSelector=true) const
Definition: composite.cpp:112
void extract(Composite &composite, const std::string &channels, const std::string &crop="") const
Definition: composite.cpp:667
void setQuantities(const std::string &s)
Sets basic quantities and quality quantities. These sets are separated by '/'.
Definition: DataSelector.cpp:282
void reset()
Restore default values.
Definition: DataSelector.cpp:156
std::string type
This is non-standard (not in ODIM), but a practical means of handling storage type of datasets.
Definition: EncodingODIM.h:146
void clear()
Resets the values.
Definition: EncodingODIM.cpp:171
Hi5Tree polarInputHi5
The last input file read, typically a volume. May be concatenated ie. read in incrementally.
Definition: resources-base.h:187
std::string quantity
dataX/what (obligatory)
Definition: ODIM.h:181
Resources provided separately for each thread.
Definition: resources.h:67
Composite composite
TODO: inherit from ProductBase.
Definition: resources.h:119
Composite & getComposite(h5_role::ivalue_t filter)
Definition: resources.cpp:139
OD odim
For storing the scaling and encoding of (1st) input or user-defined values. Also for bookkeeping of d...
Definition: RadarAccumulator.h:111
DataSelector dataSelector
Input data selector.
Definition: RadarAccumulator.h:102
void setTargetEncoding(const std::string &encoding)
Not critical. If set, needed to warn if input data does not match the expected / potential targetEnco...
Definition: RadarAccumulator.h:125
Definition: DataSelector.cpp:44