36#include <data/QuantitySelector.h>
40#include <drain/util/ReferenceMap.h>
42#include "DataSelector.h"
45#include "CartesianODIM.h"
46#include "VerticalODIM.h"
82template <
typename T,
typename TI,
typename D>
85 typedef TI tree_iter_t;
106template <
typename M = PolarODIM const>
107struct SrcType :
public DataType<Hi5Tree const, Hi5Tree::const_iterator, Image const> {
116template <
typename M = PolarODIM>
154template <
typename DT>
158 typedef DT datatype_t;
159 typedef typename DT::tree_t tree_t;
160 typedef typename DT::tree_iter_t tree_iter_t;
164 return getAttr<ODIMPathElem::WHAT>();
169 return getAttr<ODIMPathElem::WHAT>();
174 return getAttr<ODIMPathElem::WHERE>();
179 return getAttr<ODIMPathElem::WHERE>();
185 return getAttr<ODIMPathElem::HOW>();
190 return getAttr<ODIMPathElem::HOW>();
195 void setExcluded(
bool exclude =
true){
196 this->
tree.data.exclude = exclude;
201 bool isExcluded()
const {
202 return this->
tree.data.exclude;
208 const tree_t & getTree()
const {
return this->
tree; };
212 tree_t & getTree(){
return this->
tree; } ;
238 template <ODIMPathElem::group_t G>
240 return this->tree[ODIMPathElem(G)].data.attributes;
243 template <ODIMPathElem::group_t G>
245 return this->tree[ODIMPathElem(G)].data.attributes;
260template <
typename DT>
288 mout.experimental<LOG_DEBUG>(
"invoking ODIM::updateH5AttributeGroups<ODIMPathElem::ROOT>()");
289 mout.experimental<LOG_DEBUG+1>(
"root odim: ", this->odim);
291 ODIM::updateH5AttributeGroups<ODIMPathElem::ROOT>(this->odim, this->tree);
296 typename DT::odim_t odim;
310template <
typename DT>
314 typedef typename DT::tree_t tree_t;
315 typedef typename DT::image_t image_t;
316 typedef typename DT::odim_t odim_t;
323 odim(data, data.properties.get(
"what:quantity",
""))
347 template <
typename DT2>
368 void setEncoding(
const T & type,
const std::string & values =
""){
370 this->odim.type = drain::Type::getTypeChar(
drain::Type(type));
371 this->odim.setTypeDefaults(type, values);
380 data.setType(this->odim.
type);
381 data.setScaling(this->odim.scaling);
388 this->odim.importMap(srcData.odim);
389 data.setType(this->odim.type);
390 data.setScaling(this->odim.scaling);
394 void setPhysicalRange(
double min,
double max){
396 data.setPhysicalRange(min, max,
true);
398 this->odim.scaling.assignSequence(data.getScaling());
408 this->odim.setGeometry(cols, rows);
409 data.setGeometry(cols, rows);
415 this->odim.setGeometry(geometry.getWidth(), geometry.getHeight());
416 data.setGeometry(geometry);
425 this->odim.setGeometry(odim.area);
426 data.setGeometry(odim.area);
428 this->odim.resolution = odim.resolution;
471 template <
class ...T>
479 template <
class ...T>
487 template <
class ...T>
490 odim.area.set(geometry);
495 template <
class ...T>
498 odim.updateFromMap(encoding);
499 odim.scaling.physRange.set(encoding.scaling.
physRange);
505 void setNyquist(
double nyquistSpeed){
506 odim.NI = nyquistSpeed;
507 odim.setRange(-odim.NI, +odim.NI);
508 data.setScaling(odim.scaling);
530 qualityData.odim.scaling.set(qualityData.data.getScaling());
538 ODIM::updateH5AttributeGroups<ODIMPathElem::DATA>(this->odim, this->tree);
551template <
typename DT>
558 const bool DATA = !std::isnan(dataQuality);
559 const bool UNDETECT = !std::isnan(undetectQuality);
560 const bool NODATA = !std::isnan(nodataQuality);
563 const double dataCode = DATA ? scaling.
inv(dataQuality) : 0.0;
564 const double undetectCode = UNDETECT ? scaling.
inv(undetectQuality) : 0.0;
565 const double nodataCode = NODATA ? scaling.
inv(nodataQuality) : 0.0;
567 quality.
setGeometry(data.getWidth(), data.getHeight());
571 while (it != data.end()){
573 if (UNDETECT && (*it == this->odim.undetect))
575 else if (NODATA && (*it == this->odim.nodata))
612template <
typename DT>
615 ostr << d.data <<
", ODIM:\t ";
616 ostr << d.odim <<
'\n';
617 ostr <<
"props: " << d.data.properties <<
'\n';
635template <
class DT, ODIMPathElem::group_t G>
641 typedef typename DT::datatype_t datatype_t;
642 typedef std::map<std::string, DT > map_t;
707 bool has(
const std::string & quantity)
const {
708 return (this->find(quantity) != this->end());
712 const data_t & getData(
const char *quantity)
const {
713 return getData(std::string(quantity));
718 const data_t & getData(
const std::string & quantity)
const {
723 typename datagroup_t::const_iterator it = this->find(quantity);
725 if (it != this->end()){
726 mout.debug3(
'[' , quantity ,
"]\t = " , it->first );
730 mout.debug(
'[' , quantity ,
"] not found, returning empty" );
736 data_t & getData(
const char *quantity) {
737 return getData(std::string(quantity));
742 data_t & getData(
const std::string & quantity) {
748 typename datagroup_t::iterator it;
751 it = this->find(quantity);
752 if (it != this->end()){
753 mout.debug3(
"found " , it->first );
757 ODIMPathElem child(G);
759 mout.debug3(
"add: " , child ,
" [" , quantity ,
']' );
760 it = this->insert(this->begin(),
typename map_t::value_type(quantity, DT(this->getTree()[child], quantity)));
776 for (
const auto & entry: *this){
777 if (m.test(entry.first)){
778 mout.debug(
"quantity " , entry.first ,
" matches " , slct);
793 mout.note(
"no quantity matched with " , slct);
805 data_t &
create(
const std::string & quantity) {
806 data_t & d = getData(quantity);
813 data_t & getFirstData() {
815 for (
auto & entry: *this){
816 if (!entry.second.isExcluded()){
823 return this->getData(
"");
840 const data_t & getFirstData()
const {
842 for (
const auto & entry: *this){
843 if (!entry.second.isExcluded()){
849 return this->getData(
"");
874 data_t & getLastData() {
876 const typename datagroup_t::reverse_iterator it = this->rend();
878 if (it == this->rbegin()){
880 mout.error(
"no data" );
881 return this->getData(
"");
889 const data_t & getLastData()
const {
895 typename datagroup_t::const_reverse_iterator it = this->rend();
897 if (it != this->rbegin()){
898 mout.debug2(
"found: " , it->first );
902 mout.note(
"not found, returning empty" );
913 const data_t & getEmpty() {
914 static typename DT::tree_t t;
915 static data_t empty(t);
933 const bool USE_SELECTOR = slct.isSet();
936 unsigned short counter = 0;
938 mout.debug3(
"collecting data items, selector='", slct,
"'");
947 const std::string datasetQuantity = t[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
950 for (
auto & entry: t){
953 if (! (entry.first.is(G))){
960 const std::string dataQuantity = entry.second[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
962 const std::string & quantity = !dataQuantity.empty() ? dataQuantity : datasetQuantity;
966 if (!slct.
test(quantity)){
970 mout.debug3(
"rejected '" , entry.first ,
"' [" , quantity ,
"] !~" , slct );
987 mout.
accept<LOG_DEBUG+2>(
"accept '", entry.first,
"' [", quantity,
']' );
996 if (quantity.empty()){
998 mout.info(
"quantities dataset:'", datasetQuantity,
"', data:'", dataQuantity,
"'");
999 mout.
warn(
"undefined quantity in ", entry.first,
", using key=", entry.first );
1001 dst.insert(
typename map_t::value_type(entry.first, DT(entry.second, entry.first)));
1005 if (dst.find(quantity) != dst.end()){
1007 mout.
warn(
"quantity '" , quantity ,
"' replaced same quantity at " , entry.first );
1009 dst.insert(
typename map_t::value_type(quantity, DT(entry.second, quantity)));
1019 mout.debug3(
"matched " , dst.size() ,
"(out of " , counter ,
") data items with selector: " , slct ,
'/' );
1022 mout.debug3(
"collected " , dst.size() ,
" data items" );
1030 typename DT::tree_t & adapt(
const datagroup_t & src, datagroup_t & dst){
1038 mout.debug3(
"src empty" );
1042 for (
const auto & entry: src){
1054 mout.debug3(
"adapted ", dst.size(),
" data items; ", src.begin()->first,
"...");
1063template <
class DT, ODIMPathElem::group_t G>
1064std::ostream & operator<<(std::ostream & ostr,
const DataGroup<DT,G> & d){
1068 for (
typename DataGroup<DT,G>::const_iterator it = d.begin(); it != d.end(); ++it){
1073 g.setGeometry(it->second.data.getGeometry());
1075 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1077 ostr <<
" ("<< g <<
")";
1093template <
typename DT>
1120 return this->quality.getData(quantity);
1145 return this->quality.getData(quantity);
1150 bool hasQuality()
const {
1151 return !this->quality.empty();
1155 bool hasQuality(
const std::string & quantity)
const {
1156 return this->quality.find(quantity) != this->quality.end();
1160 const qualitygroup_t & getQuality()
const {
1161 return this->quality;
1165 qualitygroup_t & getQuality(){
1166 return this->quality;
1184 qualitygroup_t quality;
1205template <
typename DT>
1227 mout.experimental(
"Swapping...");
1228 this->tree.swap(d.
tree);
1230 typename DT::odim_t odim;
1231 odim.updateFromMap(this->odim);
1232 this->odim.updateFromMap(d.odim);
1233 d.odim.updateFromMap(odim);
1247template <
typename DT>
1249std::ostream & operator<<(std::ostream & ostr,
const Data<DT> & d){
1250 ostr << d.data <<
", ODIM:\t ";
1253 if (d.hasQuality()){
1255 ostr <<
"+q(" << d.getQuality() <<
')';
1274template <
typename DT>
1281 typedef typename datagroup_t::map_t map_t;
1300 switch (this->size()) {
1302 mout.debug3(
"no data<n> groups" );
1305 mout.info(
"several Data groups, using: " , this->begin()->first );
1308 mout.debug2(
"updating from 1st data: " , this->begin()->first );
1311 const typename DT::odim_t & odim = this->getFirstData().odim;
1331 plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
""){
1332 if (dataQuantity.empty())
1340 const plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
"")
const {
1341 if (dataQuantity.empty())
1350 void updateTree3(
const typename DT::odim_t & odim){
1351 ODIM::updateH5AttributeGroups<ODIMPathElem::DATASET>(odim, this->tree);
1358 void updateTree3(
const typename DT::odim_t & odim)
const {
1359 std::cout <<
"updateTree3 const \n";
1392template <
typename DT>
1398 for (
typename dataset_t::const_iterator it = d.begin(); it != d.end(); ++it){
1403 g.setGeometry(it->second.data.getGeometry());
1405 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1406 if (it->second.hasQuality())
1407 ostr <<
"+Q(" << it->second.getQuality() <<
')';
1409 ostr <<
" ("<< g <<
")";
1411 ostr <<
" +quality(" << d.getQuality() <<
')';
1429template <
typename DT>
1435template <
typename DT>
1446template <
class T,
typename TI,
typename D>
1449 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:251
Definition StringBuilder.h:58
bool test(const std::string &key, bool defaultResult=true) const
Check if key is accepted.
Definition StringMatcherList.h:249
General-purpose key matcher: tests string equality, or regExp, if defined as such.
Definition StringMatcher.h:54
Utilities related to std::type_info.
Definition Type.h:48
Linear scaling and physical range for image intensities.
Definition ValueScaling.h:63
drain::Range< double > physRange
Minimum and maximum physical value of the imaged quantity (not limited to corresponding to minCodeVal...
Definition ValueScaling.h:73
double inv(double y) const
Inverse scaling: given physically meaningful value y, returns the corresponding code value.
Definition ValueScaling.h:300
A map of Variables.
Definition VariableMap.h:61
Definition Geometry.h:143
const iterator & begin()
Returns iterator pointing to the first image element.
Definition ImageFrame.h:114
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:101
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
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:87
A map of "data type" group_t (DATA or QUALITY) where the data can be retrieved using quantity keys (s...
Definition Data.h:636
data_t & create(const std::string &quantity)
Creates (or overrides) data array for quantity and scales it.
Definition Data.h:805
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:926
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:667
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1275
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:1287
Data structure consisting of plain data and an optional quality data.
Definition Data.h:1206
Structure for data storage type, scaling and marker codes. Does not contain quantity.
Definition EncodingODIM.h:70
std::string type
This is non-standard (not in ODIM), but a practical means of handling storage type of datasets.
Definition EncodingODIM.h:157
const std::string & getKey() const
Debugging/logging. Returns standard name. Does not check if type is OTHER.
Definition ODIMPath.h:356
static const group_t WHAT
Metadata group /what , at any depth.
Definition ODIMPath.h:126
static const group_t ARRAY
Data group "data", at deepest level, like /dataset4/data2/quality1/data.
Definition ODIMPath.h:111
Essential class for storing radar data.
Definition Data.h:311
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:368
PlainData(const PlainData< DT2 > &d)
Copy constructor, also for referencing non-const as const.
Definition Data.h:348
void setGeometry(const odim_t &odim)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:424
void initializeBest(const EncodingODIM &encoding, const T &...args)
Set encoding and other properties.
Definition Data.h:497
void setGeometry(size_t cols, size_t rows)
Sets dimensions of data array and metadata.
Definition Data.h:407
void copyGeometry(const PlainData< DT2 > &srcData)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:437
void copyEncoding(const EncodingODIM &odim)
New, experimental.
Definition Data.h:378
void initializeBest(const std::string &type, const T &...args)
Set storage type and other properties.
Definition Data.h:481
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:489
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:527
void initializeBest(const std::type_info &type, const T &...args)
Set storage type and other properties.
Definition Data.h:473
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:552
void updateTree2()
TODO: consider this to destructor.
Definition Data.h:537
void initializeBest()
Terminal step in initialisation: set actual data storage type and resize.
Definition Data.h:465
void setGeometry(const drain::image::AreaGeometry &geometry)
Sets dimensions of data array and metadata.
Definition Data.h:414
PlainData(typename DT::tree_t &tree, const std::string &quantity)
Constructor referring to HDF5 structure.
Definition Data.h:329
void initialize(const T &type, size_t cols, size_t rows)
Calls setEncoding() and setGeometry().
Definition Data.h:450
Base class providing quality support for Dataand DataSet
Definition Data.h:1094
const plaindata_t & getQualityData(const std::string &quantity="QIND") const
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1119
plaindata_t & getQualityData(const std::string &quantity="QIND")
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1144
Experimental structure, designed only for accessing root level metadata.
Definition Data.h:261
Base class for all kinds of radar data.
Definition Data.h:155
tree_t & tree
General HDF5 data structure.
Definition Data.h:218
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44
Default implementation.
Definition TypeName.h:54
Container that couples together a tree structure and a data array (drain::image::Image),...
Definition Data.h:83
Writable data type.
Definition Data.h:117
Read-only data type.
Definition Data.h:107