Skip to content

Commit

Permalink
Add tests for univariate missfits and boxplot representations
Browse files Browse the repository at this point in the history
- Formatting ert-style.json
  • Loading branch information
xjules committed Dec 14, 2020
1 parent 81aa449 commit e38be15
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
15 changes: 10 additions & 5 deletions ertviz/assets/ert-style.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@
"marker": null
}
},
"figure":{
"layout" : {
"hovermode":"closest",
"uirevision":true,
"margin": {"l": 5, "b": 5, "t": 5, "r": 5},
"figure": {
"layout": {
"hovermode": "closest",
"uirevision": true,
"margin": {
"l": 5,
"b": 5,
"t": 5,
"r": 5
},
"autosize": true
}
}
Expand Down
2 changes: 0 additions & 2 deletions ertviz/controllers/observation_response_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ def _create_misfits_plot(response, selected_realizations, color):
realizations,
[],
dict(
xaxis={"title": "Index"},
yaxis={"title": "Unit TODO"},
hovermode="closest",
uirevision=True,
),
Expand Down
38 changes: 37 additions & 1 deletion tests/plots/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
_get_realizations_plots,
_get_realizations_statistics_plots,
)
from ertviz.controllers.observation_response_controller import (
_get_univariate_misfits_boxplots,
)
from ertviz.controllers.ensemble_selector_controller import _construct_graph
from ertviz.data_loader import get_ensembles
from ertviz.models import EnsembleModel
from ertviz.models import HistogramPlotModel, MultiHistogramPlotModel
from ertviz.models import HistogramPlotModel, MultiHistogramPlotModel, BoxPlotModel
import ertviz.assets as assets


Expand Down Expand Up @@ -125,3 +128,36 @@ def test_multi_histogram_plot_representation():
assert plot.data[idx].autobinx == False
assert plot.data[idx].marker.color == colors_dict[ensemble_name]
assert plot.data[idx].name == ensemble_name


def test_univariate_misfits_boxplot_representation():
data = np.random.rand(200).reshape(-1, 20)
missfits_df = pd.DataFrame(data=data, index=range(10), columns=range(20))
missfits_df["x_axis"] = np.arange(10)
plots = _get_univariate_misfits_boxplots(
missfits_df.copy(), assets.ERTSTYLE["ensemble-selector"]["color_wheel"][0]
)

assert len(plots) == 10
for id_plot, plot in enumerate(plots):
np.testing.assert_equal(0.3, plot.repr.jitter)
np.testing.assert_equal("all", plot.repr.boxpoints)
x_pos = int(missfits_df["x_axis"][id_plot])
name = f"Misfits@{x_pos}"
assert name == plot.repr.name


def test_boxplot_representation():
data = np.random.rand(10)
data_df = pd.DataFrame(data=data, index=range(10))

plot = BoxPlotModel(
x_axis=[5],
y_axis=data_df.values,
name="Boxplot@Location5",
color=assets.ERTSTYLE["ensemble-selector"]["color_wheel"][0],
)
plot = plot.repr
np.testing.assert_equal(plot.y.flatten(), data)
assert plot.boxpoints == "all"
assert plot.name == "Boxplot@Location5"

0 comments on commit e38be15

Please sign in to comment.