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;
460 template <
class ...T>
468 template <
class ...T>
476 template <
class ...T>
479 odim.area.set(geometry);
484 template <
class ...T>
487 odim.updateFromMap(encoding);
488 odim.scaling.physRange.set(encoding.scaling.
physRange);
494 void setNyquist(
double nyquistSpeed){
495 odim.NI = nyquistSpeed;
496 odim.setRange(-odim.NI, +odim.NI);
497 data.setScaling(odim.scaling);
519 qualityData.odim.scaling.set(qualityData.data.getScaling());
527 ODIM::updateH5AttributeGroups<ODIMPathElem::DATA>(this->odim, this->tree);
540template <
typename DT>
547 const bool DATA = !std::isnan(dataQuality);
548 const bool UNDETECT = !std::isnan(undetectQuality);
549 const bool NODATA = !std::isnan(nodataQuality);
552 const double dataCode = DATA ? scaling.
inv(dataQuality) : 0.0;
553 const double undetectCode = UNDETECT ? scaling.
inv(undetectQuality) : 0.0;
554 const double nodataCode = NODATA ? scaling.
inv(nodataQuality) : 0.0;
556 quality.
setGeometry(data.getWidth(), data.getHeight());
560 while (it != data.end()){
562 if (UNDETECT && (*it == this->odim.undetect))
564 else if (NODATA && (*it == this->odim.nodata))
601template <
typename DT>
604 ostr << d.data <<
", ODIM:\t ";
605 ostr << d.odim <<
'\n';
606 ostr <<
"props: " << d.data.properties <<
'\n';
624template <
class DT, ODIMPathElem::group_t G>
630 typedef typename DT::datatype_t datatype_t;
631 typedef std::map<std::string, DT > map_t;
696 bool has(
const std::string & quantity)
const {
697 return (this->find(quantity) != this->end());
701 const data_t & getData(
const char *quantity)
const {
702 return getData(std::string(quantity));
707 const data_t & getData(
const std::string & quantity)
const {
712 typename datagroup_t::const_iterator it = this->find(quantity);
714 if (it != this->end()){
715 mout.debug3(
'[' , quantity ,
"]\t = " , it->first );
719 mout.debug(
'[' , quantity ,
"] not found, returning empty" );
725 data_t & getData(
const char *quantity) {
726 return getData(std::string(quantity));
731 data_t & getData(
const std::string & quantity) {
737 typename datagroup_t::iterator it;
740 it = this->find(quantity);
741 if (it != this->end()){
742 mout.debug3(
"found " , it->first );
746 ODIMPathElem child(G);
748 mout.debug3(
"add: " , child ,
" [" , quantity ,
']' );
749 it = this->insert(this->begin(),
typename map_t::value_type(quantity, DT(this->getTree()[child], quantity)));
765 for (
const auto & entry: *this){
766 if (m.test(entry.first)){
767 mout.debug(
"quantity " , entry.first ,
" matches " , slct);
782 mout.note(
"no quantity matched with " , slct);
794 data_t &
create(
const std::string & quantity) {
795 data_t & d = getData(quantity);
802 data_t & getFirstData() {
804 for (
auto & entry: *this){
805 if (!entry.second.isExcluded()){
812 return this->getData(
"");
829 const data_t & getFirstData()
const {
831 for (
const auto & entry: *this){
832 if (!entry.second.isExcluded()){
838 return this->getData(
"");
863 data_t & getLastData() {
865 const typename datagroup_t::reverse_iterator it = this->rend();
867 if (it == this->rbegin()){
869 mout.error(
"no data" );
870 return this->getData(
"");
878 const data_t & getLastData()
const {
884 typename datagroup_t::const_reverse_iterator it = this->rend();
886 if (it != this->rbegin()){
887 mout.debug2(
"found: " , it->first );
891 mout.note(
"not found, returning empty" );
902 const data_t & getEmpty() {
903 static typename DT::tree_t t;
904 static data_t empty(t);
922 const bool USE_SELECTOR = slct.isSet();
925 unsigned short counter = 0;
927 mout.debug3(
"collecting data items, selector='", slct,
"'");
936 const std::string datasetQuantity = t[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
939 for (
auto & entry: t){
942 if (! (entry.first.is(G))){
949 const std::string dataQuantity = entry.second[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
951 const std::string & quantity = !dataQuantity.empty() ? dataQuantity : datasetQuantity;
955 if (!slct.
test(quantity)){
959 mout.debug3(
"rejected '" , entry.first ,
"' [" , quantity ,
"] !~" , slct );
976 mout.
accept<LOG_DEBUG+2>(
"accept '", entry.first,
"' [", quantity,
']' );
985 if (quantity.empty()){
987 mout.info(
"quantities dataset:'", datasetQuantity,
"', data:'", dataQuantity,
"'");
988 mout.
warn(
"undefined quantity in ", entry.first,
", using key=", entry.first );
990 dst.insert(
typename map_t::value_type(entry.first, DT(entry.second, entry.first)));
994 if (dst.find(quantity) != dst.end()){
996 mout.
warn(
"quantity '" , quantity ,
"' replaced same quantity at " , entry.first );
998 dst.insert(
typename map_t::value_type(quantity, DT(entry.second, quantity)));
1008 mout.debug3(
"matched " , dst.size() ,
"(out of " , counter ,
") data items with selector: " , slct ,
'/' );
1011 mout.debug3(
"collected " , dst.size() ,
" data items" );
1019 typename DT::tree_t & adapt(
const datagroup_t & src, datagroup_t & dst){
1027 mout.debug3(
"src empty" );
1031 for (
const auto & entry: src){
1043 mout.debug3(
"adapted ", dst.size(),
" data items; ", src.begin()->first,
"...");
1052template <
class DT, ODIMPathElem::group_t G>
1053std::ostream & operator<<(std::ostream & ostr,
const DataGroup<DT,G> & d){
1057 for (
typename DataGroup<DT,G>::const_iterator it = d.begin(); it != d.end(); ++it){
1062 g.setGeometry(it->second.data.getGeometry());
1064 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1066 ostr <<
" ("<< g <<
")";
1082template <
typename DT>
1109 return this->quality.getData(quantity);
1134 return this->quality.getData(quantity);
1139 bool hasQuality()
const {
1140 return !this->quality.empty();
1144 bool hasQuality(
const std::string & quantity)
const {
1145 return this->quality.find(quantity) != this->quality.end();
1149 const qualitygroup_t & getQuality()
const {
1150 return this->quality;
1154 qualitygroup_t & getQuality(){
1155 return this->quality;
1173 qualitygroup_t quality;
1194template <
typename DT>
1216 mout.experimental(
"Swapping...");
1217 this->tree.swap(d.
tree);
1219 typename DT::odim_t odim;
1220 odim.updateFromMap(this->odim);
1221 this->odim.updateFromMap(d.odim);
1222 d.odim.updateFromMap(odim);
1236template <
typename DT>
1238std::ostream & operator<<(std::ostream & ostr,
const Data<DT> & d){
1239 ostr << d.data <<
", ODIM:\t ";
1242 if (d.hasQuality()){
1244 ostr <<
"+q(" << d.getQuality() <<
')';
1263template <
typename DT>
1270 typedef typename datagroup_t::map_t map_t;
1289 switch (this->size()) {
1291 mout.debug3(
"no data<n> groups" );
1294 mout.info(
"several Data groups, using: " , this->begin()->first );
1297 mout.debug(
"updating from 1st data: " , this->begin()->first );
1300 const typename DT::odim_t & odim = this->getFirstData().odim;
1320 plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
""){
1321 if (dataQuantity.empty())
1329 const plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
"")
const {
1330 if (dataQuantity.empty())
1339 void updateTree3(
const typename DT::odim_t & odim){
1340 ODIM::updateH5AttributeGroups<ODIMPathElem::DATASET>(odim, this->tree);
1347 void updateTree3(
const typename DT::odim_t & odim)
const {
1348 std::cout <<
"updateTree3 const \n";
1381template <
typename DT>
1387 for (
typename dataset_t::const_iterator it = d.begin(); it != d.end(); ++it){
1392 g.setGeometry(it->second.data.getGeometry());
1394 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1395 if (it->second.hasQuality())
1396 ostr <<
"+Q(" << it->second.getQuality() <<
')';
1398 ostr <<
" ("<< g <<
")";
1400 ostr <<
" +quality(" << d.getQuality() <<
')';
1418template <
typename DT>
1424template <
typename DT>
1435template <
class T,
typename TI,
typename D>
1438 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:313
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
Logger & error(const TT &... args)
Echoes.
Definition Log.h:417
Logger & accept(const TT &... args)
Some input has been accepted, for example by a syntax.
Definition Log.h:583
void importMap(const std::map< std::string, S > &m)
Assign values from a map, overriding existing entries.
Definition SmartMap.h:255
Definition StringBuilder.h:58
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:253
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:50
Linear scaling and physical range for image intensities.
Definition ValueScaling.h:64
drain::Range< double > physRange
Minimum and maximum physical value of the imaged quantity (not limited to corresponding to minCodeVal...
Definition ValueScaling.h:74
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:116
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:103
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:193
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:97
A map of "data type" group_t (DATA or QUALITY) where the data can be retrieved using quantity keys (s...
Definition Data.h:625
data_t & create(const std::string &quantity)
Creates (or overrides) data array for quantity and scales it.
Definition Data.h:794
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:915
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:656
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1264
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:1276
Data structure consisting of plain data and an optional quality data.
Definition Data.h:1195
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:162
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 initializeBest(const EncodingODIM &encoding, const T &...args)
Set encoding and other properties.
Definition Data.h:486
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 initializeBest(const std::string &type, const T &...args)
Set storage type and other properties.
Definition Data.h:470
void initializeBest(const drain::image::AreaGeometry &geometry, const T &...args)
Set width and height of the data array, and set other properties.
Definition Data.h:478
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:516
void initializeBest(const std::type_info &type, const T &...args)
Set storage type and other properties.
Definition Data.h:462
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:541
void updateTree2()
TODO: consider this to destructor.
Definition Data.h:526
void initializeBest()
Terminal step in initialisation: set actual data storage type and resize.
Definition Data.h:454
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:1083
const plaindata_t & getQualityData(const std::string &quantity="QIND") const
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1108
plaindata_t & getQualityData(const std::string &quantity="QIND")
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1133
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
Default implementation.
Definition Type.h:541
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:549
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