From b0e208d0ba45ee824244379e1d7d3e58b2f18fc8 Mon Sep 17 00:00:00 2001 From: Sylvie Lamy-Thepaut Date: Wed, 13 Sep 2023 17:10:32 +0100 Subject: [PATCH] Magics: Adding few arameters to show percentiles on plumes plots [ Miha Request ] --- src/attributes/EpsPlumeAttributes.cc | 35 ++++++++++++++++ src/attributes/EpsPlumeAttributes.h | 5 +++ src/attributes/EpsPlumeWrapper.cc | 26 ++++++++++++ src/params/EpsPlume.xml | 35 ++++++++++++++++ src/visualisers/EpsGraph.cc | 61 ++++++++++++++++++++++++++++ 5 files changed, 162 insertions(+) diff --git a/src/attributes/EpsPlumeAttributes.cc b/src/attributes/EpsPlumeAttributes.cc index d7c2162a..427498ac 100644 --- a/src/attributes/EpsPlumeAttributes.cc +++ b/src/attributes/EpsPlumeAttributes.cc @@ -35,6 +35,11 @@ EpsPlumeAttributes::EpsPlumeAttributes(): control_line_thickness_(ParameterManager::getInt("eps_plume_control_line_thickness")), median_(ParameterManager::getBool("eps_plume_median")), median_line_thickness_(ParameterManager::getInt("eps_plume_median_line_thickness")), + percentiles_(ParameterManager::getBool("eps_plume_percentiles")), + percentiles_list_(ParameterManager::getDoubleArray("eps_plume_percentiles_list")), + percentiles_line_colour_list_(ParameterManager::getStringArray("eps_plume_percentiles_line_colour_list")), + percentiles_line_style_list_(ParameterManager::getStringArray("eps_plume_percentiles_line_style_list")), + percentiles_line_thickness_list_(ParameterManager::getIntArray("eps_plume_percentiles_line_thickness_list")), shading_(ParameterManager::getBool("eps_plume_shading")), shading_levels_(ParameterManager::getDoubleArray("eps_plume_shading_level_list")), shading_colours_(ParameterManager::getStringArray("eps_plume_shading_colour_list")), @@ -82,6 +87,11 @@ void EpsPlumeAttributes::set(const std::map& params) setAttribute(prefix, "eps_plume_control_line_thickness", control_line_thickness_, params); setAttribute(prefix, "eps_plume_median", median_, params); setAttribute(prefix, "eps_plume_median_line_thickness", median_line_thickness_, params); + setAttribute(prefix, "eps_plume_percentiles", percentiles_, params); + setAttribute(prefix, "eps_plume_percentiles_list", percentiles_list_, params); + setAttribute(prefix, "eps_plume_percentiles_line_colour_list", percentiles_line_colour_list_, params); + setAttribute(prefix, "eps_plume_percentiles_line_style_list", percentiles_line_style_list_, params); + setAttribute(prefix, "eps_plume_percentiles_line_thickness_list", percentiles_line_thickness_list_, params); setAttribute(prefix, "eps_plume_shading", shading_, params); setAttribute(prefix, "eps_plume_shading_level_list", shading_levels_, params); setAttribute(prefix, "eps_plume_shading_colour_list", shading_colours_, params); @@ -116,6 +126,11 @@ void EpsPlumeAttributes::copy(const EpsPlumeAttributes& other) control_line_thickness_ = other.control_line_thickness_; median_ = other.median_; median_line_thickness_ = other.median_line_thickness_; + percentiles_ = other.percentiles_; + percentiles_list_ = other.percentiles_list_; + percentiles_line_colour_list_ = other.percentiles_line_colour_list_; + percentiles_line_style_list_ = other.percentiles_line_style_list_; + percentiles_line_thickness_list_ = other.percentiles_line_thickness_list_; shading_ = other.shading_; shading_levels_ = other.shading_levels_; shading_colours_ = other.shading_colours_; @@ -182,6 +197,11 @@ void EpsPlumeAttributes::print(ostream& out) const out << " control_line_thickness = " << control_line_thickness_; out << " median = " << median_; out << " median_line_thickness = " << median_line_thickness_; + out << " percentiles = " << percentiles_; + out << " percentiles_list = " << percentiles_list_; + out << " percentiles_line_colour_list = " << percentiles_line_colour_list_; + out << " percentiles_line_style_list = " << percentiles_line_style_list_; + out << " percentiles_line_thickness_list = " << percentiles_line_thickness_list_; out << " shading = " << shading_; out << " shading_levels = " << shading_levels_; out << " shading_colours = " << shading_colours_; @@ -227,6 +247,16 @@ void EpsPlumeAttributes::toxml(ostream& out) const niceprint(out,median_); out << ", \"eps_plume_median_line_thickness\":"; niceprint(out,median_line_thickness_); + out << ", \"eps_plume_percentiles\":"; + niceprint(out,percentiles_); + out << ", \"eps_plume_percentiles_list\":"; + niceprint(out,percentiles_list_); + out << ", \"eps_plume_percentiles_line_colour_list\":"; + niceprint(out,percentiles_line_colour_list_); + out << ", \"eps_plume_percentiles_line_style_list\":"; + niceprint(out,percentiles_line_style_list_); + out << ", \"eps_plume_percentiles_line_thickness_list\":"; + niceprint(out,percentiles_line_thickness_list_); out << ", \"eps_plume_shading\":"; niceprint(out,shading_); out << ", \"eps_plume_shading_level_list\":"; @@ -276,6 +306,11 @@ static MagicsParameter eps_plume_control("eps_plume_control", "on"); static MagicsParameter eps_plume_control_line_thickness("eps_plume_control_line_thickness", 5); static MagicsParameter eps_plume_median("eps_plume_median", "off"); static MagicsParameter eps_plume_median_line_thickness("eps_plume_median_line_thickness", 5); +static MagicsParameter eps_plume_percentiles("eps_plume_percentiles", "off"); +static MagicsParameter eps_plume_percentiles_list("eps_plume_percentiles_list", floatarray()); +static MagicsParameter eps_plume_percentiles_line_colour_list("eps_plume_percentiles_line_colour_list", stringarray()); +static MagicsParameter eps_plume_percentiles_line_style_list("eps_plume_percentiles_line_style_list", stringarray()); +static MagicsParameter eps_plume_percentiles_line_thickness_list("eps_plume_percentiles_line_thickness_list", intarray()); static MagicsParameter eps_plume_shading("eps_plume_shading", "off"); static MagicsParameter eps_plume_shading_level_list("eps_plume_shading_level_list", floatarray()); static MagicsParameter eps_plume_shading_colour_list("eps_plume_shading_colour_list", stringarray()); diff --git a/src/attributes/EpsPlumeAttributes.h b/src/attributes/EpsPlumeAttributes.h index 6c9010a7..5cd62468 100644 --- a/src/attributes/EpsPlumeAttributes.h +++ b/src/attributes/EpsPlumeAttributes.h @@ -61,6 +61,11 @@ class EpsPlumeAttributes int control_line_thickness_; bool median_; int median_line_thickness_; + bool percentiles_; + doublearray percentiles_list_; + stringarray percentiles_line_colour_list_; + stringarray percentiles_line_style_list_; + intarray percentiles_line_thickness_list_; bool shading_; doublearray shading_levels_; stringarray shading_colours_; diff --git a/src/attributes/EpsPlumeWrapper.cc b/src/attributes/EpsPlumeWrapper.cc index 15ff0739..2748d262 100644 --- a/src/attributes/EpsPlumeWrapper.cc +++ b/src/attributes/EpsPlumeWrapper.cc @@ -105,6 +105,32 @@ void EpsPlumeWrapper::set(const MagRequest& request) int median_line_thickness_value = request("EPS_PLUME_MEDIAN_LINE_THICKNESS"); epsplume_->median_line_thickness_ = median_line_thickness_value; } + if (request.countValues("EPS_PLUME_PERCENTILES") ) { + string percentiles_value = request("EPS_PLUME_PERCENTILES"); + + epsplume_->percentiles_ = MagTranslator()(percentiles_value); + + } + doublearray percentiles_list_value; + for (int i = 0; i < request.countValues("EPS_PLUME_PERCENTILES_LIST"); i++) + percentiles_list_value.push_back((double)request("EPS_PLUME_PERCENTILES_LIST", i)); + if ( !percentiles_list_value.empty() ) + epsplume_->percentiles_list_ = percentiles_list_value; + stringarray percentiles_line_colour_list_value; + for (int i = 0; i < request.countValues("EPS_PLUME_PERCENTILES_LINE_COLOUR_LIST"); i++) + percentiles_line_colour_list_value.push_back((string)request("EPS_PLUME_PERCENTILES_LINE_COLOUR_LIST", i)); + if ( !percentiles_line_colour_list_value.empty() ) + epsplume_->percentiles_line_colour_list_ = percentiles_line_colour_list_value; + stringarray percentiles_line_style_list_value; + for (int i = 0; i < request.countValues("EPS_PLUME_PERCENTILES_LINE_STYLE_LIST"); i++) + percentiles_line_style_list_value.push_back((string)request("EPS_PLUME_PERCENTILES_LINE_STYLE_LIST", i)); + if ( !percentiles_line_style_list_value.empty() ) + epsplume_->percentiles_line_style_list_ = percentiles_line_style_list_value; + intarray percentiles_line_thickness_list_value; + for (int i = 0; i < request.countValues("EPS_PLUME_PERCENTILES_LINE_THICKNESS_LIST"); i++) + percentiles_line_thickness_list_value.push_back((int)request("EPS_PLUME_PERCENTILES_LINE_THICKNESS_LIST", i)); + if ( !percentiles_line_thickness_list_value.empty() ) + epsplume_->percentiles_line_thickness_list_ = percentiles_line_thickness_list_value; if (request.countValues("EPS_PLUME_SHADING") ) { string shading_value = request("EPS_PLUME_SHADING"); diff --git a/src/params/EpsPlume.xml b/src/params/EpsPlume.xml index 21946f14..26ce9811 100644 --- a/src/params/EpsPlume.xml +++ b/src/params/EpsPlume.xml @@ -143,6 +143,41 @@ does it submit to any jurisdiction. name="eps_plume_median_line_thickness"> Line thickness of the deterministic forecast + + show teh precnetiles + + + List of the precentiles to display + + + List of colours to use to display the percentiles + + + List of line-style to use to display the percentiles + + + List of line-thickness to use to display the percentiles + setLineStyle(median_line_style_); legend.add(new LineEntry("Median", median)); } + // if (percentiles_) { + // magics::Polyline* median = new magics::Polyline(); + // median->setColour(*median_line_colour_); + // median->setThickness(median_line_thickness_); + // median->setLineStyle(median_line_style_); + // legend.add(new LineEntry("Median", median)); + // } } void EpsPlume::timeserie(Data& data, BasicGraphicsObjectContainer& visitor) { @@ -2521,11 +2528,21 @@ void EpsPlume::timeserie(Data& data, BasicGraphicsObjectContainer& visitor) { median->setColour(*median_line_colour_); median->setThickness(median_line_thickness_); median->setLineStyle(median_line_style_); + + + map> shading; + map> percentiles; + if (shading_) { for (vector::iterator level = shading_levels_.begin(); level != shading_levels_.end(); ++level) shading.insert(make_pair(*level, vector())); } + if (percentiles_) { + for (vector::iterator level = percentiles_list_.begin(); level != percentiles_list_.end(); ++level) { + percentiles.insert(make_pair(*level, vector())); + } + } for (const auto& point : points) { double x = (*point)["step"] + (*point)["shift"]; double missing = (*point)["missing"]; @@ -2565,6 +2582,11 @@ void EpsPlume::timeserie(Data& data, BasicGraphicsObjectContainer& visitor) { std::sort(members.begin(), members.end()); median->push_back(PaperPoint(x, members[m])); } + if (percentiles_) { + int m = members.size()/2; + std::sort(members.begin(), members.end()); + median->push_back(PaperPoint(x, members[m])); + } if (shading_) { for (vector::iterator level = shading_levels_.begin(); level != shading_levels_.end(); ++level) { int i = *level * (members.size()/100.); @@ -2573,7 +2595,16 @@ void EpsPlume::timeserie(Data& data, BasicGraphicsObjectContainer& visitor) { shading[*level].push_back(PaperPoint(x, members[i])); } } + if (percentiles_) { + for (vector::iterator level = percentiles_list_.begin(); level != percentiles_list_.end(); ++level) { + int i = *level * (members.size()/100.); + if (i >= members.size()) + i = members.size() - 1; + percentiles[*level].push_back(PaperPoint(x, members[i])); + } + } } + vector::iterator colour = shading_colours_.begin(); @@ -2611,6 +2642,36 @@ void EpsPlume::timeserie(Data& data, BasicGraphicsObjectContainer& visitor) { transformation(*forecast, visitor); if (median_) transformation(*median, visitor); + if (percentiles_) { + if ( percentiles_line_colour_list_.empty() ) + percentiles_line_colour_list_.push_back("black"); + if ( percentiles_line_thickness_list_.empty() ) + percentiles_line_thickness_list_.push_back(2); + if ( percentiles_line_style_list_.empty() ) + percentiles_line_style_list_.push_back("solid"); + + auto percentiles_line_colour = percentiles_line_colour_list_.begin(); + auto percentiles_line_thickness = percentiles_line_thickness_list_.begin(); + auto percentiles_line_style = percentiles_line_style_list_.begin(); + + for ( auto percentile = percentiles.begin(); percentile != percentiles.end (); ++percentile ) { + magics::Polyline* line = new magics::Polyline(); + line->setColour(Colour(*percentiles_line_colour)); + line->setLineStyle(MagTranslator()(*percentiles_line_style)); + line->setThickness(*percentiles_line_thickness); + + if (++percentiles_line_colour == percentiles_line_colour_list_.end() ) --percentiles_line_colour; + if (++percentiles_line_thickness == percentiles_line_thickness_list_.end() ) --percentiles_line_thickness; + if (++percentiles_line_style == percentiles_line_style_list_.end() ) --percentiles_line_style; + + for (vector::iterator point = percentile->second.begin(); point != percentile->second.end(); ++point) + line->push_back(*point); + + transformation(*line, visitor); + } + + + } } void EpsPlume::verticalprofile(Data& data, BasicGraphicsObjectContainer& visitor) {