36#include <data/QuantitySelector.h>
41#include <drain/RegExp.h>
42#include <drain/util/ReferenceMap.h>
43#include <drain/util/StringMatcherList.h>
45#include "DataSelector.h"
48#include "CartesianODIM.h"
49#include "VerticalODIM.h"
85template <
typename T,
typename TI,
typename D>
88 typedef TI tree_iter_t;
109template <
typename M = PolarODIM const>
110struct SrcType :
public DataType<Hi5Tree const, Hi5Tree::const_iterator, Image const> {
119template <
typename M = PolarODIM>
157template <
typename DT>
161 typedef DT datatype_t;
162 typedef typename DT::tree_t tree_t;
163 typedef typename DT::tree_iter_t tree_iter_t;
167 return getAttr<ODIMPathElem::WHAT>();
172 return getAttr<ODIMPathElem::WHAT>();
177 return getAttr<ODIMPathElem::WHERE>();
182 return getAttr<ODIMPathElem::WHERE>();
188 return getAttr<ODIMPathElem::HOW>();
193 return getAttr<ODIMPathElem::HOW>();
198 void setExcluded(
bool exclude =
true){
199 this->
tree.data.exclude = exclude;
204 bool isExcluded()
const {
205 return this->
tree.data.exclude;
211 const tree_t & getTree()
const {
return this->
tree; };
215 tree_t & getTree(){
return this->
tree; } ;
241 template <ODIMPathElem::group_t G>
243 return this->tree[ODIMPathElem(G)].data.attributes;
246 template <ODIMPathElem::group_t G>
248 return this->tree[ODIMPathElem(G)].data.attributes;
263template <
typename DT>
270 this->odim.copyFrom(
tree.data.image);
277 mout.experimental<LOG_DEBUG>(
"invoking ODIM::updateH5AttributeGroups<ODIMPathElem::ROOT>()");
278 mout.experimental<LOG_DEBUG+1>(
"root odim: ", this->odim);
280 ODIM::updateH5AttributeGroups<ODIMPathElem::ROOT>(this->odim, this->tree);
285 typename DT::odim_t odim;
299template <
typename DT>
303 typedef typename DT::tree_t tree_t;
304 typedef typename DT::image_t image_t;
305 typedef typename DT::odim_t odim_t;
312 odim(data, data.properties.get(
"what:quantity",
""))
336 template <
typename DT2>
357 void setEncoding(
const T & type,
const std::string & values =
""){
359 this->odim.type = drain::Type::getTypeChar(
drain::Type(type));
360 this->odim.setTypeDefaults(type, values);
369 data.setType(this->odim.
type);
370 data.setScaling(this->odim.scaling);
377 this->odim.importMap(srcData.odim);
378 data.setType(this->odim.type);
379 data.setScaling(this->odim.scaling);
383 void setPhysicalRange(
double min,
double max){
385 data.setPhysicalRange(min, max,
true);
387 this->odim.scaling.assignSequence(data.getScaling());
397 this->odim.setGeometry(cols, rows);
398 data.setGeometry(cols, rows);
404 this->odim.setGeometry(geometry.getWidth(), geometry.getHeight());
405 data.setGeometry(geometry);
414 this->odim.setGeometry(odim.area);
415 data.setGeometry(odim.area);
417 this->odim.resolution = odim.resolution;
470 qualityData.odim.scaling.set(qualityData.data.getScaling());
478 ODIM::updateH5AttributeGroups<ODIMPathElem::DATA>(this->odim, this->tree);
491template <
typename DT>
498 const bool DATA = !std::isnan(dataQuality);
499 const bool UNDETECT = !std::isnan(undetectQuality);
500 const bool NODATA = !std::isnan(nodataQuality);
503 const double dataCode = DATA ? scaling.
inv(dataQuality) : 0.0;
504 const double undetectCode = UNDETECT ? scaling.
inv(undetectQuality) : 0.0;
505 const double nodataCode = NODATA ? scaling.
inv(nodataQuality) : 0.0;
507 quality.
setGeometry(data.getWidth(), data.getHeight());
511 while (it != data.end()){
513 if (UNDETECT && (*it == this->odim.undetect))
515 else if (NODATA && (*it == this->odim.nodata))
552template <
typename DT>
555 ostr << d.data <<
", ODIM:\t ";
556 ostr << d.odim <<
'\n';
557 ostr <<
"props: " << d.data.properties <<
'\n';
575template <
class DT, ODIMPathElem::group_t G>
581 typedef typename DT::datatype_t datatype_t;
582 typedef std::map<std::string, DT > map_t;
647 bool has(
const std::string & quantity)
const {
648 return (this->find(quantity) != this->end());
652 const data_t & getData(
const char *quantity)
const {
653 return getData(std::string(quantity));
658 const data_t & getData(
const std::string & quantity)
const {
663 typename datagroup_t::const_iterator it = this->find(quantity);
665 if (it != this->end()){
666 mout.debug3(
'[' , quantity ,
"]\t = " , it->first );
670 mout.debug(
'[' , quantity ,
"] not found, returning empty" );
676 data_t & getData(
const char *quantity) {
677 return getData(std::string(quantity));
682 data_t & getData(
const std::string & quantity) {
688 typename datagroup_t::iterator it;
691 it = this->find(quantity);
692 if (it != this->end()){
693 mout.debug3(
"found " , it->first );
697 ODIMPathElem child(G);
699 mout.debug3(
"add: " , child ,
" [" , quantity ,
']' );
700 it = this->insert(this->begin(),
typename map_t::value_type(quantity, DT(this->getTree()[child], quantity)));
716 for (
const auto & entry: *this){
717 if (m.test(entry.first)){
718 mout.debug(
"quantity " , entry.first ,
" matches " , slct);
733 mout.note(
"no quantity matched with " , slct);
745 data_t &
create(
const std::string & quantity) {
746 data_t & d = getData(quantity);
753 data_t & getFirstData() {
755 for (
auto & entry: *this){
756 if (!entry.second.isExcluded()){
763 return this->getData(
"");
780 const data_t & getFirstData()
const {
782 for (
const auto & entry: *this){
783 if (!entry.second.isExcluded()){
789 return this->getData(
"");
814 data_t & getLastData() {
816 const typename datagroup_t::reverse_iterator it = this->rend();
818 if (it == this->rbegin()){
820 mout.error(
"no data" );
821 return this->getData(
"");
829 const data_t & getLastData()
const {
835 typename datagroup_t::const_reverse_iterator it = this->rend();
837 if (it != this->rbegin()){
838 mout.debug2(
"found: " , it->first );
842 mout.note(
"not found, returning empty" );
853 const data_t & getEmpty() {
854 static typename DT::tree_t t;
855 static data_t empty(t);
873 const bool USE_SELECTOR = slct.isSet();
876 unsigned short counter = 0;
878 mout.debug3(
"collecting data items, selector='", slct,
"'");
887 const std::string datasetQuantity = t[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
890 for (
auto & entry: t){
893 if (! (entry.first.is(G))){
900 const std::string dataQuantity = entry.second[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
902 const std::string & quantity = !dataQuantity.empty() ? dataQuantity : datasetQuantity;
906 if (!slct.
test(quantity)){
910 mout.debug3(
"rejected '" , entry.first ,
"' [" , quantity ,
"] !~" , slct );
927 mout.
accept<LOG_DEBUG+2>(
"accept '", entry.first,
"' [", quantity,
']' );
936 if (quantity.empty()){
938 mout.info(
"quantities dataset:'", datasetQuantity,
"', data:'", dataQuantity,
"'");
939 mout.
warn(
"undefined quantity in ", entry.first,
", using key=", entry.first );
941 dst.insert(
typename map_t::value_type(entry.first, DT(entry.second, entry.first)));
945 if (dst.find(quantity) != dst.end()){
947 mout.
warn(
"quantity '" , quantity ,
"' replaced same quantity at " , entry.first );
949 dst.insert(
typename map_t::value_type(quantity, DT(entry.second, quantity)));
959 mout.debug3(
"matched " , dst.size() ,
"(out of " , counter ,
") data items with selector: " , slct ,
'/' );
962 mout.debug3(
"collected " , dst.size() ,
" data items" );
970 typename DT::tree_t & adapt(
const datagroup_t & src, datagroup_t & dst){
978 mout.debug3(
"src empty" );
982 for (
const auto & entry: src){
994 mout.debug3(
"adapted ", dst.size(),
" data items; ", src.begin()->first,
"...");
1003template <
class DT, ODIMPathElem::group_t G>
1004std::ostream & operator<<(std::ostream & ostr,
const DataGroup<DT,G> & d){
1008 for (
typename DataGroup<DT,G>::const_iterator it = d.begin(); it != d.end(); ++it){
1013 g.setGeometry(it->second.data.getGeometry());
1015 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1017 ostr <<
" ("<< g <<
")";
1033template <
typename DT>
1060 return this->quality.getData(quantity);
1085 return this->quality.getData(quantity);
1090 bool hasQuality()
const {
1091 return !this->quality.empty();
1095 bool hasQuality(
const std::string & quantity)
const {
1096 return this->quality.find(quantity) != this->quality.end();
1100 const qualitygroup_t & getQuality()
const {
1101 return this->quality;
1105 qualitygroup_t & getQuality(){
1106 return this->quality;
1124 qualitygroup_t quality;
1145template <
typename DT>
1167 mout.experimental(
"Swapping...");
1168 this->tree.swap(d.
tree);
1170 typename DT::odim_t odim;
1171 odim.updateFromMap(this->odim);
1172 this->odim.updateFromMap(d.odim);
1173 d.odim.updateFromMap(odim);
1187template <
typename DT>
1189std::ostream & operator<<(std::ostream & ostr,
const Data<DT> & d){
1190 ostr << d.data <<
", ODIM:\t ";
1193 if (d.hasQuality()){
1195 ostr <<
"+q(" << d.getQuality() <<
')';
1214template <
typename DT>
1221 typedef typename datagroup_t::map_t map_t;
1240 switch (this->size()) {
1242 mout.debug3(
"no data<n> groups" );
1245 mout.info(
"several Data groups, using: " , this->begin()->first );
1248 mout.debug(
"updating from 1st data: " , this->begin()->first );
1251 const typename DT::odim_t & odim = this->getFirstData().odim;
1271 plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
""){
1272 if (dataQuantity.empty())
1280 const plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
"")
const {
1281 if (dataQuantity.empty())
1290 void updateTree3(
const typename DT::odim_t & odim){
1291 ODIM::updateH5AttributeGroups<ODIMPathElem::DATASET>(odim, this->tree);
1298 void updateTree3(
const typename DT::odim_t & odim)
const {
1299 std::cout <<
"updateTree3 const \n";
1332template <
typename DT>
1338 for (
typename dataset_t::const_iterator it = d.begin(); it != d.end(); ++it){
1343 g.setGeometry(it->second.data.getGeometry());
1345 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1346 if (it->second.hasQuality())
1347 ostr <<
"+Q(" << it->second.getQuality() <<
')';
1349 ostr <<
" ("<< g <<
")";
1351 ostr <<
" +quality(" << d.getQuality() <<
')';
1369template <
typename DT>
1375template <
typename DT>
1386template <
class T,
typename TI,
typename D>
1389 static const std::string & str(){
Definition CastableIterator.h:57
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition Log.h:582
void importMap(const std::map< std::string, S > &m)
Assign values from a map, overriding existing entries.
Definition SmartMap.h:252
Definition StringBuilder.h:58
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:273
General-purpose key matcher: tests string equality, or regExp, if defined as such.
Definition StringMatcher.h:58
Utilities related to std::type_info.
Definition Type.h:51
Linear scaling and physical range for image intensities.
Definition ValueScaling.h:64
double inv(double y) const
Inverse scaling: given physically meaningful value y, returns the corresponding code value.
Definition ValueScaling.h:301
A map of Variables.
Definition VariableMap.h:61
Definition Geometry.h:145
const iterator & begin()
Returns iterator pointing to the first image element.
Definition ImageFrame.h:119
void setPhysicalRange(const Range< double > &range, bool rescale=false)
Sets the supported range for physical values and optionally adjusts the scaling for maximal resolutio...
Definition ImageFrame.h:106
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:184
virtual void setGeometry(size_t width, size_t height, size_t imageChannels=1, size_t alphaChannels=0)
Resizes the image, keeps the current type.
Definition Image.h:95
A map of "data type" group_t (DATA or QUALITY) where the data can be retrieved using quantity keys (s...
Definition Data.h:576
data_t & create(const std::string &quantity)
Creates (or overrides) data array for quantity and scales it.
Definition Data.h:745
static DT::tree_t & init(typename DT::tree_t &t, datagroup_t &dst, const QuantitySelector &slct=QuantitySelector())
Given a dataset h5 subtree, like tree["dataset3"], collects all (or desired) quantities to a data obj...
Definition Data.h:866
DataGroup(typename DT::tree_t &tree, const QuantitySelector &slct=QuantitySelector())
Given a dataset subtree, like tree["dataset3"], constructs a data map of desired quantities.
Definition Data.h:607
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1215
DataSet(typename data_t::tree_t &tree, const QuantitySelector &slct=QuantitySelector())
Given a dataset subtree, like tree["dataset3"], constructs a data map of desired quantities.
Definition Data.h:1227
Data structure consisting of plain data and an optional quality data.
Definition Data.h:1146
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:75
std::string type
This is non-standard (not in ODIM), but a practical means of handling storage type of datasets.
Definition EncodingODIM.h:152
const std::string & getKey() const
Debugging/logging. Returns standard name. Does not check if type is OTHER.
Definition ODIMPath.h:357
static const group_t WHAT
Metadata group /what , at any depth.
Definition ODIMPath.h:127
static const group_t ARRAY
Data group "data", at deepest level, like /dataset4/data2/quality1/data.
Definition ODIMPath.h:112
Essential class for storing radar data.
Definition Data.h:300
void setEncoding(const T &type, const std::string &values="")
Saves type and sets the type of the actual data array as well.
Definition Data.h:357
PlainData(const PlainData< DT2 > &d)
Copy constructor, also for referencing non-const as const.
Definition Data.h:337
void setGeometry(const odim_t &odim)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:413
void setGeometry(size_t cols, size_t rows)
Sets dimensions of data array and metadata.
Definition Data.h:396
void copyGeometry(const PlainData< DT2 > &srcData)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:426
void copyEncoding(const EncodingODIM &odim)
New, experimental.
Definition Data.h:367
void createSimpleQualityData(PlainData< DT > &qualityData, double dataQuality=1.0, double undetectQuality=0.5, double nodataQuality=0.0) const
For this data, creates an on-off quality data.
Definition Data.h:467
void createSimpleQualityData(drain::image::Image &qualityImage, double dataQuality=1.0, double undetectQuality=0.5, double nodataQuality=0.0) const
For this data, creates an on-off quality data.
Definition Data.h:492
void updateTree2()
TODO: consider this to destructor.
Definition Data.h:477
void setGeometry(const drain::image::AreaGeometry &geometry)
Sets dimensions of data array and metadata.
Definition Data.h:403
PlainData(typename DT::tree_t &tree, const std::string &quantity)
Constructor referring to HDF5 structure.
Definition Data.h:318
void initialize(const T &type, size_t cols, size_t rows)
Calls setEncoding() and setGeometry().
Definition Data.h:439
Base class providing quality support for Dataand DataSet
Definition Data.h:1034
const plaindata_t & getQualityData(const std::string &quantity="QIND") const
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1059
plaindata_t & getQualityData(const std::string &quantity="QIND")
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1084
Experimental structure, designed only for accessing root level metadata.
Definition Data.h:264
Base class for all kinds of radar data.
Definition Data.h:158
tree_t & tree
General HDF5 data structure.
Definition Data.h:221
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:558
Container that couples together a tree structure and a data array (drain::image::Image),...
Definition Data.h:86
Writable data type.
Definition Data.h:120
Read-only data type.
Definition Data.h:110