Skip to content

Commit

Permalink
Color observations black when inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
oysteoh committed Mar 12, 2021
1 parent 28589cc commit e4904df
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
8 changes: 6 additions & 2 deletions ertviz/controllers/multi_response_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def _get_observation_plots(observation_df, x_axis):
stds = observation_df["std"]
x_axis = observation_df["x_axis"]
attributes = observation_df["attributes"]
active_mask = observation_df["active"]

style = assets.ERTSTYLE["response-plot"]["observation"]
color = [style["color"] if active else "rgb(0, 0, 0)" for active in active_mask]
style["marker"]["color"] = color

observation_data = PlotModel(
x_axis=x_axis,
Expand All @@ -63,9 +68,8 @@ def _get_observation_plots(observation_df, x_axis):
array=stds.values,
visible=True,
),
**assets.ERTSTYLE["response-plot"]["observation"],
**style,
)

return [observation_data]


Expand Down
3 changes: 3 additions & 0 deletions ertviz/models/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ def __init__(self, observation_schema):
self._std = []
self._values = []
self._attributes = ""
self._active = []

if "data" in observation_schema:
data = observation_schema["data"]
self._x_axis = data["x_axis"]["data"]
self._std = data["std"]["data"]
self._values = data["values"]["data"]
self._active = data["active"]["data"]

if "attributes" in observation_schema:
for k, v in observation_schema["attributes"].items():
Expand All @@ -27,5 +29,6 @@ def data_df(self):
"std": self._std,
"x_axis": indexes_to_axis(self._x_axis),
"attributes": self._attributes,
"active": self._active,
}
)
2 changes: 1 addition & 1 deletion ertviz/models/plot_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def repr(self):
repr_dict = dict(
x=self._x_axis,
y=self._y_axis,
name=self.display_name,
text=self._text,
name=self.display_name,
mode=self._mode,
error_y=self._error_y,
)
Expand Down
42 changes: 42 additions & 0 deletions tests/data/snake_oil_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ def content(self):
"x_axis": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"std": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"values": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"active": {
"data": [
True,
True,
False,
False,
True,
True,
True,
True,
True,
False,
]
},
},
"name": "FOPR",
}
Expand Down Expand Up @@ -310,6 +324,20 @@ def content(self):
"x_axis": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"std": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"values": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"active": {
"data": [
True,
True,
False,
False,
True,
True,
True,
True,
True,
False,
]
},
},
"name": "WOPR:OP1",
}
Expand All @@ -334,6 +362,20 @@ def content(self):
"x_axis": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"std": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"values": {"data": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]},
"active": {
"data": [
True,
True,
False,
False,
True,
True,
True,
True,
True,
False,
]
},
},
"name": "FOPR",
}
Expand Down
11 changes: 11 additions & 0 deletions tests/plots/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_observation_plot_representation():
"std": [0.1, 1.1, 4.1, 9.1, 16.1],
"x_axis": [0, 2, 4, 6, 8],
"attributes": "Key1 Value1<br>Key2 Value2<br>",
"active": [True, False, True, False, False],
}
)
x_axis = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Expand All @@ -42,6 +43,16 @@ def test_observation_plot_representation():
np.testing.assert_equal(plots[0].repr.y, observation_df["values"].values)
np.testing.assert_equal(plots[0].repr.error_y.array, observation_df["std"].values)
np.testing.assert_equal(plots[0].repr.text, observation_df["attributes"].values)
np.testing.assert_equal(
plots[0].repr.marker.color,
(
"rgb(176, 28, 52)",
"rgb(0, 0, 0)",
"rgb(176, 28, 52)",
"rgb(0, 0, 0)",
"rgb(0, 0, 0)",
),
)


def test_realizations_plot_representation():
Expand Down

0 comments on commit e4904df

Please sign in to comment.