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>
291 mout.experimental<LOG_DEBUG>(
"invoking ODIM::updateH5AttributeGroups<ODIMPathElem::ROOT>()");
292 mout.experimental<LOG_DEBUG+1>(
"root odim: ", this->odim);
294 ODIM::updateH5AttributeGroups<ODIMPathElem::ROOT>(this->odim, this->tree);
299 typename DT::odim_t odim;
313template <
typename DT>
317 typedef typename DT::tree_t tree_t;
318 typedef typename DT::image_t image_t;
319 typedef typename DT::odim_t odim_t;
326 odim(data, data.properties.get(
"what:quantity",
""))
350 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);
383 data.setType(this->odim.
type);
384 data.setScaling(this->odim.scaling);
391 this->odim.importMap(srcData.odim);
392 data.setType(this->odim.type);
393 data.setScaling(this->odim.scaling);
397 void setPhysicalRange(
double min,
double max){
399 data.setPhysicalRange(min, max,
true);
401 this->odim.scaling.assignSequence(data.getScaling());
411 this->odim.setGeometry(cols, rows);
412 data.setGeometry(cols, rows);
418 this->odim.setGeometry(geometry.getWidth(), geometry.getHeight());
419 data.setGeometry(geometry);
428 this->odim.setGeometry(odim.area);
429 data.setGeometry(odim.area);
431 this->odim.resolution = odim.resolution;
474 template <
class ...T>
482 template <
class ...T>
490 template <
class ...T>
493 odim.area.set(geometry);
498 template <
class ...T>
501 odim.updateFromMap(encoding);
502 odim.scaling.physRange.set(encoding.scaling.
physRange);
508 void setNyquist(
double nyquistSpeed){
509 odim.NI = nyquistSpeed;
510 odim.setRange(-odim.NI, +odim.NI);
511 data.setScaling(odim.scaling);
533 qualityData.odim.scaling.set(qualityData.data.getScaling());
541 ODIM::updateH5AttributeGroups<ODIMPathElem::DATA>(this->odim, this->tree);
554template <
typename DT>
561 const bool DATA = !std::isnan(dataQuality);
562 const bool UNDETECT = !std::isnan(undetectQuality);
563 const bool NODATA = !std::isnan(nodataQuality);
566 const double dataCode = DATA ? scaling.
inv(dataQuality) : 0.0;
567 const double undetectCode = UNDETECT ? scaling.
inv(undetectQuality) : 0.0;
568 const double nodataCode = NODATA ? scaling.
inv(nodataQuality) : 0.0;
570 quality.
setGeometry(data.getWidth(), data.getHeight());
574 while (it != data.end()){
576 if (UNDETECT && (*it == this->odim.undetect))
578 else if (NODATA && (*it == this->odim.nodata))
615template <
typename DT>
618 ostr << d.data <<
", ODIM:\t ";
619 ostr << d.odim <<
'\n';
620 ostr <<
"props: " << d.data.properties <<
'\n';
638template <
class DT, ODIMPathElem::group_t G>
644 typedef typename DT::datatype_t datatype_t;
645 typedef std::map<std::string, DT > map_t;
710 bool has(
const std::string & quantity)
const {
711 return (this->find(quantity) != this->end());
715 const data_t & getData(
const char *quantity)
const {
716 return getData(std::string(quantity));
721 const data_t & getData(
const std::string & quantity)
const {
726 typename datagroup_t::const_iterator it = this->find(quantity);
728 if (it != this->end()){
729 mout.debug3(
'[' , quantity ,
"]\t = " , it->first );
733 mout.debug(
'[' , quantity ,
"] not found, returning empty" );
739 data_t & getData(
const char *quantity) {
740 return getData(std::string(quantity));
745 data_t & getData(
const std::string & quantity) {
751 typename datagroup_t::iterator it;
754 it = this->find(quantity);
755 if (it != this->end()){
756 mout.debug3(
"found " , it->first );
760 ODIMPathElem child(G);
762 mout.debug3(
"add: " , child ,
" [" , quantity ,
']' );
763 it = this->insert(this->begin(),
typename map_t::value_type(quantity, DT(this->getTree()[child], quantity)));
779 for (
const auto & entry: *this){
780 if (m.test(entry.first)){
781 mout.debug(
"quantity " , entry.first ,
" matches " , slct);
796 mout.note(
"no quantity matched with " , slct);
808 data_t &
create(
const std::string & quantity) {
809 data_t & d = getData(quantity);
816 data_t & getFirstData() {
818 for (
auto & entry: *this){
819 if (!entry.second.isExcluded()){
826 return this->getData(
"");
843 const data_t & getFirstData()
const {
845 for (
const auto & entry: *this){
846 if (!entry.second.isExcluded()){
852 return this->getData(
"");
877 data_t & getLastData() {
879 const typename datagroup_t::reverse_iterator it = this->rend();
881 if (it == this->rbegin()){
883 mout.error(
"no data" );
884 return this->getData(
"");
892 const data_t & getLastData()
const {
898 typename datagroup_t::const_reverse_iterator it = this->rend();
900 if (it != this->rbegin()){
901 mout.debug2(
"found: " , it->first );
905 mout.note(
"not found, returning empty" );
916 const data_t & getEmpty() {
917 static typename DT::tree_t t;
918 static data_t empty(t);
936 const bool USE_SELECTOR = slct.isSet();
939 unsigned short counter = 0;
941 mout.debug3(
"collecting data items, selector='", slct,
"'");
950 const std::string datasetQuantity = t[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
953 for (
auto & entry: t){
956 if (! (entry.first.is(G))){
963 const std::string dataQuantity = entry.second[
ODIMPathElem::WHAT].data.attributes.get(
"quantity",
"");
965 const std::string & quantity = !dataQuantity.empty() ? dataQuantity : datasetQuantity;
969 if (!slct.
test(quantity)){
973 mout.debug3(
"rejected '" , entry.first ,
"' [" , quantity ,
"] !~" , slct );
990 mout.
accept<LOG_DEBUG+2>(
"accept '", entry.first,
"' [", quantity,
']' );
999 if (quantity.empty()){
1001 mout.info(
"quantities dataset:'", datasetQuantity,
"', data:'", dataQuantity,
"'");
1002 mout.
warn(
"undefined quantity in ", entry.first,
", using key=", entry.first );
1004 dst.insert(
typename map_t::value_type(entry.first, DT(entry.second, entry.first)));
1008 if (dst.find(quantity) != dst.end()){
1010 mout.
warn(
"quantity '" , quantity ,
"' replaced same quantity at " , entry.first );
1012 dst.insert(
typename map_t::value_type(quantity, DT(entry.second, quantity)));
1022 mout.debug3(
"matched " , dst.size() ,
"(out of " , counter ,
") data items with selector: " , slct ,
'/' );
1025 mout.debug3(
"collected " , dst.size() ,
" data items" );
1033 typename DT::tree_t & adapt(
const datagroup_t & src, datagroup_t & dst){
1041 mout.debug3(
"src empty" );
1045 for (
const auto & entry: src){
1057 mout.debug3(
"adapted ", dst.size(),
" data items; ", src.begin()->first,
"...");
1066template <
class DT, ODIMPathElem::group_t G>
1067std::ostream & operator<<(std::ostream & ostr,
const DataGroup<DT,G> & d){
1071 for (
typename DataGroup<DT,G>::const_iterator it = d.begin(); it != d.end(); ++it){
1076 g.setGeometry(it->second.data.getGeometry());
1078 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1080 ostr <<
" ("<< g <<
")";
1096template <
typename DT>
1123 return this->quality.getData(quantity);
1148 return this->quality.getData(quantity);
1153 bool hasQuality()
const {
1154 return !this->quality.empty();
1158 bool hasQuality(
const std::string & quantity)
const {
1159 return this->quality.find(quantity) != this->quality.end();
1163 const qualitygroup_t & getQuality()
const {
1164 return this->quality;
1168 qualitygroup_t & getQuality(){
1169 return this->quality;
1187 qualitygroup_t quality;
1208template <
typename DT>
1230 mout.experimental(
"Swapping...");
1231 this->tree.swap(d.
tree);
1233 typename DT::odim_t odim;
1234 odim.updateFromMap(this->odim);
1235 this->odim.updateFromMap(d.odim);
1236 d.odim.updateFromMap(odim);
1250template <
typename DT>
1252std::ostream & operator<<(std::ostream & ostr,
const Data<DT> & d){
1253 ostr << d.data <<
", ODIM:\t ";
1256 if (d.hasQuality()){
1258 ostr <<
"+q(" << d.getQuality() <<
')';
1277template <
typename DT>
1284 typedef typename datagroup_t::map_t map_t;
1303 switch (this->size()) {
1305 mout.debug3(
"no data<n> groups" );
1308 mout.info(
"several Data groups, using: " , this->begin()->first );
1311 mout.debug(
"updating from 1st data: " , this->begin()->first );
1314 const typename DT::odim_t & odim = this->getFirstData().odim;
1334 plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
""){
1335 if (dataQuantity.empty())
1343 const plaindata_t & getQualityData2(
const std::string & quantity =
"QIND",
const std::string & dataQuantity =
"")
const {
1344 if (dataQuantity.empty())
1353 void updateTree3(
const typename DT::odim_t & odim){
1354 ODIM::updateH5AttributeGroups<ODIMPathElem::DATASET>(odim, this->tree);
1361 void updateTree3(
const typename DT::odim_t & odim)
const {
1362 std::cout <<
"updateTree3 const \n";
1395template <
typename DT>
1401 for (
typename dataset_t::const_iterator it = d.begin(); it != d.end(); ++it){
1406 g.setGeometry(it->second.data.getGeometry());
1408 ostr << it->first <<
'[' << drain::Type::getTypeChar(it->second.data.getType()) <<
']';
1409 if (it->second.hasQuality())
1410 ostr <<
"+Q(" << it->second.getQuality() <<
')';
1412 ostr <<
" ("<< g <<
")";
1414 ostr <<
" +quality(" << d.getQuality() <<
')';
1432template <
typename DT>
1438template <
typename DT>
1449template <
class T,
typename TI,
typename D>
1452 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:52
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:639
data_t & create(const std::string &quantity)
Creates (or overrides) data array for quantity and scales it.
Definition Data.h:808
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:929
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:670
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1278
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:1290
Data structure consisting of plain data and an optional quality data.
Definition Data.h:1209
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:314
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:351
void setGeometry(const odim_t &odim)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:427
void initializeBest(const EncodingODIM &encoding, const T &...args)
Set encoding and other properties.
Definition Data.h:500
void setGeometry(size_t cols, size_t rows)
Sets dimensions of data array and metadata.
Definition Data.h:410
void copyGeometry(const PlainData< DT2 > &srcData)
Copy dimensions of data array and resolution (rscale or xscale,yscale)
Definition Data.h:440
void copyEncoding(const EncodingODIM &odim)
New, experimental.
Definition Data.h:381
void initializeBest(const std::string &type, const T &...args)
Set storage type and other properties.
Definition Data.h:484
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:492
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:530
void initializeBest(const std::type_info &type, const T &...args)
Set storage type and other properties.
Definition Data.h:476
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:555
void updateTree2()
TODO: consider this to destructor.
Definition Data.h:540
void initializeBest()
Terminal step in initialisation: set actual data storage type and resize.
Definition Data.h:468
void setGeometry(const drain::image::AreaGeometry &geometry)
Sets dimensions of data array and metadata.
Definition Data.h:417
PlainData(typename DT::tree_t &tree, const std::string &quantity)
Constructor referring to HDF5 structure.
Definition Data.h:332
void initialize(const T &type, size_t cols, size_t rows)
Calls setEncoding() and setGeometry().
Definition Data.h:453
Base class providing quality support for Dataand DataSet
Definition Data.h:1097
const plaindata_t & getQualityData(const std::string &quantity="QIND") const
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1122
plaindata_t & getQualityData(const std::string &quantity="QIND")
Finds associated quality data - maybe empty and unscaled.
Definition Data.h:1147
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 TypeName.h:57
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