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>
106template <
typename M = PolarODIM const>
107struct SrcType :
public DataType<Hi5Tree const, Hi5Tree::const_iterator, Image const> {
116template <
typename M = PolarODIM>
154template <
typename DT>
159 typedef typename DT::tree_t tree_t;
160 typedef typename DT::tree_iter_t tree_iter_t;
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>()");
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>
371 void setEncoding(
const T & type,
const std::string & values =
""){
373 this->odim.type = drain::Type::getTypeChar(
drain::Type(type));
374 this->odim.setTypeDefaults(type, values);
385 this->odim.copyEncoding(odim);
391 data.setType(this->odim.
type);
392 data.setScaling(this->odim.scaling);
411 void setPhysicalRange(
double min,
double max){
413 data.setPhysicalRange(min, max,
true);
415 this->odim.scaling.assignSequence(data.getScaling());
425 this->odim.setGeometry(
cols, rows);
426 data.setGeometry(
cols, rows);
432 this->odim.setGeometry(geometry.getWidth(), geometry.getHeight());
433 data.setGeometry(geometry);
442 this->odim.setGeometry(odim.area);
443 data.setGeometry(odim.area);
445 this->odim.resolution = odim.resolution;
488 template <
class ...T>
496 template <
class ...T>
504 template <
class ...T>
507 odim.area.set(geometry);
512 template <
class ...T>
515 odim.updateFromMap(encoding);
516 odim.scaling.physRange.set(encoding.scaling.
physRange);
524 odim.setRange(-odim.NI, +odim.NI);
525 data.setScaling(odim.scaling);
555 ODIM::updateH5AttributeGroups<ODIMPathElem::DATA>(this->odim, this->tree);
568template <
typename DT>
575 const bool DATA = !std::isnan(dataQuality);
576 const bool UNDETECT = !std::isnan(undetectQuality);
577 const bool NODATA = !std::isnan(nodataQuality);
580 const double dataCode = DATA ? scaling.
inv(dataQuality) : 0.0;
584 quality.
setGeometry(data.getWidth(), data.getHeight());
588 while (
it != data.end()){
592 else if (
NODATA && (*
it == this->odim.nodata))
629template <
typename DT>
632 ostr <<
d.data <<
", ODIM:\t ";
633 ostr <<
d.odim <<
'\n';
634 ostr <<
"props: " <<
d.data.properties <<
'\n';
652template <
class DT, ODIMPathElem::group_t G>
658 typedef typename DT::datatype_t datatype_t;
659 typedef std::map<std::string, DT > map_t;
727 bool has(
const std::string & quantity)
const {
728 return (this->find(quantity) != this->end());
732 const data_t & getData(
const char *quantity)
const {
733 return getData(std::string(quantity));
738 const data_t & getData(
const std::string & quantity)
const {
743 typename datagroup_t::const_iterator it = this->find(quantity);
745 if (it != this->end()){
746 mout.debug3(
'[' , quantity ,
"]\t = " , it->first );
750 mout.debug(
'[' , quantity ,
"] not found, returning empty" );
756 data_t & getData(
const char *quantity) {
757 return getData(std::string(quantity));
762 data_t & getData(
const std::string & quantity) {
768 typename datagroup_t::iterator it;
771 it = this->find(quantity);
772 if (it != this->end()){
773 mout.debug3(
"found " , it->first );
777 ODIMPathElem child(G);
779 mout.debug3(
"add: " , child ,
" [" , quantity ,
']' );
780 it = this->insert(this->begin(),
typename map_t::value_type(quantity, DT(this->getTree()[child], quantity)));
796 for (
const auto & entry: *this){
797 if (m.test(entry.first)){
798 mout.debug(
"quantity " , entry.first ,
" matches " , slct);
813 mout.note(
"no quantity matched with " , slct);
824 data_t &
d = getData(quantity);
831 data_t & getFirstData() {
833 for (
auto & entry: *
this){
834 if (!entry.second.isExcluded()){
841 return this->getData(
"");
858 const data_t & getFirstData()
const {
860 for (
const auto & entry: *this){
861 if (!entry.second.isExcluded()){
867 return this->getData(
"");
892 data_t & getLastData() {
896 if (it == this->rbegin()){
898 mout.error(
"no data" );
899 return this->getData(
"");
907 const data_t & getLastData()
const {
915 if (it != this->rbegin()){
916 mout.debug2(
"found: " , it->first );
920 mout.note(
"not found, returning empty" );
931 const data_t & getEmpty() {
932 static typename DT::tree_t t;
933 static data_t empty(t);
954 unsigned short counter = 0;
956 mout.debug3(
"collecting data items, selector='",
slct,
"'");
968 for (
auto & entry: t){
971 if (! (entry.first.is(
G))){
984 if (!
slct.test(quantity)){
988 mout.debug3(
"rejected '" , entry.first ,
"' [" , quantity ,
"] !~" ,
slct );
1005 mout.accept<
LOG_DEBUG+2>(
"accept '", entry.first,
"' [", quantity,
']' );
1014 if (quantity.empty()){
1017 mout.warn(
"undefined quantity in ", entry.first,
", using key=", entry.first );
1019 dst.insert(
typename map_t::value_type(entry.first,
DT(entry.second, entry.first)));
1023 if (dst.find(quantity) != dst.end()){
1025 mout.warn(
"quantity '" , quantity ,
"' replaced same quantity at " , entry.first );
1027 dst.insert(
typename map_t::value_type(quantity,
DT(entry.second, quantity)));
1037 mout.debug3(
"matched " , dst.size() ,
"(out of " , counter ,
") data items with selector: " ,
slct ,
'/' );
1040 mout.debug3(
"collected " , dst.size() ,
" data items" );
1048 typename DT::tree_t & adapt(
const datagroup_t & src, datagroup_t & dst){
1056 mout.debug3(
"src empty" );
1060 for (
const auto & entry: src){
1072 mout.debug3(
"adapted ", dst.size(),
" data items; ", src.begin()->first,
"...");
1081template <
class DT, ODIMPathElem::group_t G>
1082std::ostream &
operator<<(std::ostream & ostr,
const DataGroup<DT,G> & d){
1086 for (
typename DataGroup<DT,G>::const_iterator it = d.begin(); it != d.end(); ++it){
1091 g.setGeometry(it->second.data.getGeometry());
1093 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1095 ostr <<
" ("<< g <<
")";
1111template <
typename DT>
1138 return this->quality.getData(quantity);
1163 return this->quality.getData(quantity);
1168 bool hasQuality()
const {
1169 return !this->quality.empty();
1173 bool hasQuality(
const std::string & quantity)
const {
1174 return this->quality.find(quantity) != this->quality.end();
1178 const qualitygroup_t & getQuality()
const {
1179 return this->quality;
1183 qualitygroup_t & getQuality(){
1184 return this->quality;
1202 qualitygroup_t quality;
1223template <
typename DT>
1245 mout.experimental(
"Swapping...");
1246 this->tree.swap(
d.
tree);
1248 typename DT::odim_t odim;
1249 odim.updateFromMap(this->odim);
1250 this->odim.updateFromMap(
d.odim);
1251 d.odim.updateFromMap(odim);
1265template <
typename DT>
1268 ostr <<
d.data <<
", ODIM:\t ";
1271 if (
d.hasQuality()){
1273 ostr <<
"+q(" <<
d.getQuality() <<
')';
1292template <
typename DT>
1299 typedef typename datagroup_t::map_t map_t;
1318 mout.debug3(
"no data<n> groups, skipping updateTree3" );
1321 if (this->size() > 1){
1322 mout.debug(
"several Data groups, using the first: " , this->begin()->first);
1324 const typename DT::odim_t & odim = this->getFirstData().odim;
1360 plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
""){
1361 if (dataQuantity.empty())
1369 const plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
"")
const {
1370 if (dataQuantity.empty())
1379 void updateTree3(
const typename DT::odim_t & odim){
1380 ODIM::updateH5AttributeGroups<ODIMPathElem::DATASET>(odim, this->tree);
1387 void updateTree3(
const typename DT::odim_t & odim)
const {
1388 std::cout <<
"updateTree3 const \n";
1421template <
typename DT>
1427 for (
typename dataset_t::const_iterator
it =
d.begin();
it !=
d.end(); ++
it){
1432 g.setGeometry(
it->second.data.getGeometry());
1434 ostr <<
it->first <<
'[' << drain::Type::getTypeChar(
it->second.data.getType()) <<
']';
1435 if (
it->second.hasQuality())
1436 ostr <<
"+Q(" <<
it->second.getQuality() <<
')';
1438 ostr <<
" ("<<
g <<
")";
1440 ostr <<
" +quality(" <<
d.getQuality() <<
')';
1458template <
typename DT>
1464template <
typename DT>
1475template <
class T,
typename TI,
typename D>
1478 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:326
Logger & error(const TT &... args)
Echoes.
Definition Log.h:426
Definition StringBuilder.h:58
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:301
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:118
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:105
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:653
data_t & create(const std::string &quantity)
Creates (or overrides) data array for quantity and scales it.
Definition Data.h:823
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:944
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:684
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
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:1305
Data structure consisting of plain data and an optional quality data.
Definition Data.h:1224
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
DOC: Add class description.
Definition ODIMPath.h:82
const std::string & getKey() const
Debugging/logging. Returns standard name. Does not check if type is OTHER.
Definition ODIMPath.h:366
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: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:371
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:441
void initializeBest(const EncodingODIM &encoding, const T &...args)
Set encoding and other properties.
Definition Data.h:514
void setGeometry(size_t cols, size_t rows)
Sets dimensions of data array and metadata.
Definition Data.h:424
void copyGeometry(const PlainData< DT2 > &srcData)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:454
void copyEncoding(const EncodingODIM &odim)
Adjust data array and ODIM metadata to given encoding. Recommended form.
Definition Data.h:384
void initializeBest(const std::string &type, const T &...args)
Set storage type and other properties.
Definition Data.h:498
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:506
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:544
void initializeBest(const std::type_info &type, const T &...args)
Set storage type and other properties.
Definition Data.h:490
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:569
void updateTree2()
TODO: consider this to destructor.
Definition Data.h:554
void initializeBest()
Terminal step in initialisation: set actual data storage type and resize.
Definition Data.h:482
void copyEncoding(const PlainData< DT2 > &srcData)
Adjust data array and ODIM metadata to given encoding. Recommended form.
Definition Data.h:403
void setGeometry(const drain::image::AreaGeometry &geometry)
Sets dimensions of data array and metadata.
Definition Data.h:431
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:467
Base class providing quality support for Dataand DataSet
Definition Data.h:1112
const plaindata_t & getQualityData(const std::string &quantity="QIND") const
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1137
plaindata_t & getQualityData(const std::string &quantity="QIND")
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1162
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 AltitudeOp.cpp:42
SrcType< PolarODIM const > PolarSrc
Read-only data in polar coordinates.
Definition Data.h:125
DstType< VerticalProfileODIM > VprDst
Writable data in vertical coordinates, with profile metadata.
Definition Data.h:143
SrcType< CartesianODIM const > CartesianSrc
Read-only data in Cartesian coordinates.
Definition Data.h:128
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
DstType< PolarODIM > PolarDst
Writable data in polar coordinates.
Definition Data.h:134
SrcType< ODIM const > BasicSrc
Read-only data (supports top-level ODIM properties only)
Definition Data.h:122
DstType< CartesianODIM > CartesianDst
Writable data in Cartesian coordinates.
Definition Data.h:137
DstType< RhiODIM > RhiDst
Writable data in vertical coordinates, with (pseudo) RHI metadata.
Definition Data.h:140
Default implementation.
Definition TypeName.h:54
static const std::string & str()
Default implementation: name returned by std::type_info::name()
Definition TypeName.h:68
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