Skip to content

Commit

Permalink
Magics: Adding few arameters to show percentiles on plumes plots [ Mi…
Browse files Browse the repository at this point in the history
…ha Request ]
  • Loading branch information
sylvielamythepaut committed Sep 13, 2023
1 parent ba612c9 commit b0e208d
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/attributes/EpsPlumeAttributes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down Expand Up @@ -82,6 +87,11 @@ void EpsPlumeAttributes::set(const std::map<string, string>& 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);
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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\":";
Expand Down Expand Up @@ -276,6 +306,11 @@ static MagicsParameter<string> eps_plume_control("eps_plume_control", "on");
static MagicsParameter<int> eps_plume_control_line_thickness("eps_plume_control_line_thickness", 5);
static MagicsParameter<string> eps_plume_median("eps_plume_median", "off");
static MagicsParameter<int> eps_plume_median_line_thickness("eps_plume_median_line_thickness", 5);
static MagicsParameter<string> eps_plume_percentiles("eps_plume_percentiles", "off");
static MagicsParameter<doublearray> eps_plume_percentiles_list("eps_plume_percentiles_list", floatarray());
static MagicsParameter<stringarray> eps_plume_percentiles_line_colour_list("eps_plume_percentiles_line_colour_list", stringarray());
static MagicsParameter<stringarray> eps_plume_percentiles_line_style_list("eps_plume_percentiles_line_style_list", stringarray());
static MagicsParameter<intarray> eps_plume_percentiles_line_thickness_list("eps_plume_percentiles_line_thickness_list", intarray());
static MagicsParameter<string> eps_plume_shading("eps_plume_shading", "off");
static MagicsParameter<doublearray> eps_plume_shading_level_list("eps_plume_shading_level_list", floatarray());
static MagicsParameter<stringarray> eps_plume_shading_colour_list("eps_plume_shading_colour_list", stringarray());
Expand Down
5 changes: 5 additions & 0 deletions src/attributes/EpsPlumeAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
26 changes: 26 additions & 0 deletions src/attributes/EpsPlumeWrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, bool>()(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");

Expand Down
35 changes: 35 additions & 0 deletions src/params/EpsPlume.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,41 @@ does it submit to any jurisdiction.
name="eps_plume_median_line_thickness">
<documentation>Line thickness of the deterministic forecast</documentation>
</parameter>
<parameter member="percentiles"
to="bool"
default="off"
from="string"
name="eps_plume_percentiles">
<documentation>show teh precnetiles</documentation>
</parameter>
<parameter member="percentiles_list"
to="floatarray"
default="floatarray()"
from="floatarray"
name="eps_plume_percentiles_list">
<documentation>List of the precentiles to display</documentation>
</parameter>
<parameter member="percentiles_line_colour_list"
to="stringarray"
default="stringarray()"
from="stringarray"
name="eps_plume_percentiles_line_colour_list">
<documentation>List of colours to use to display the percentiles</documentation>
</parameter>
<parameter member="percentiles_line_style_list"
to="stringarray"
default="stringarray()"
from="stringarray"
name="eps_plume_percentiles_line_style_list">
<documentation>List of line-style to use to display the percentiles</documentation>
</parameter>
<parameter member="percentiles_line_thickness_list"
to="intarray"
default="intarray()"
from="intarray"
name="eps_plume_percentiles_line_thickness_list">
<documentation>List of line-thickness to use to display the percentiles</documentation>
</parameter>
<parameter member="shading"
to="bool"
default="off"
Expand Down
61 changes: 61 additions & 0 deletions src/visualisers/EpsGraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,13 @@ void EpsPlume::visit(LegendVisitor& legend) {
median->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) {
Expand Down Expand Up @@ -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<double, vector<PaperPoint>> shading;
map<double, vector<PaperPoint>> percentiles;

if (shading_) {
for (vector<double>::iterator level = shading_levels_.begin(); level != shading_levels_.end(); ++level)
shading.insert(make_pair(*level, vector<PaperPoint>()));
}
if (percentiles_) {
for (vector<double>::iterator level = percentiles_list_.begin(); level != percentiles_list_.end(); ++level) {
percentiles.insert(make_pair(*level, vector<PaperPoint>()));
}
}
for (const auto& point : points) {
double x = (*point)["step"] + (*point)["shift"];
double missing = (*point)["missing"];
Expand Down Expand Up @@ -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<double>::iterator level = shading_levels_.begin(); level != shading_levels_.end(); ++level) {
int i = *level * (members.size()/100.);
Expand All @@ -2573,7 +2595,16 @@ void EpsPlume::timeserie(Data& data, BasicGraphicsObjectContainer& visitor) {
shading[*level].push_back(PaperPoint(x, members[i]));
}
}
if (percentiles_) {
for (vector<double>::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<string>::iterator colour = shading_colours_.begin();
Expand Down Expand Up @@ -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<string, LineStyle>()(*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<PaperPoint>::iterator point = percentile->second.begin(); point != percentile->second.end(); ++point)
line->push_back(*point);

transformation(*line, visitor);
}


}
}

void EpsPlume::verticalprofile(Data& data, BasicGraphicsObjectContainer& visitor) {
Expand Down

0 comments on commit b0e208d

Please sign in to comment.