Skip to content

Commit

Permalink
Make plot_api return all observations
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Oct 30, 2024
1 parent 5a220c7 commit 60ed648
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/ert/gui/tools/plot/plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,38 @@ def observations_for_key(self, ensemble_ids: List[str], key: str) -> pd.DataFram
timeout=self._timeout,
)
self._check_response(response)
if not response.json():
continue

try:
obs = response.json()[0]
observations = response.json()
observations_dfs = []
if not observations:
continue

observations[0] # Just preserving the old logic/behavior
# but this should really be revised
except (KeyError, IndexError, JSONDecodeError) as e:
raise httpx.RequestError(
f"Observation schema might have changed key={key}, ensemble_name={ensemble.name}, e={e}"
) from e
try:
int(obs["x_axis"][0])
key_index = [int(v) for v in obs["x_axis"]]
except ValueError:
key_index = [pd.Timestamp(v) for v in obs["x_axis"]]

data_struct = {
"STD": obs["errors"],
"OBS": obs["values"],
"key_index": key_index,
}

all_observations = pd.concat(
[all_observations, pd.DataFrame(data_struct)]
)

for obs in observations:
try:
int(obs["x_axis"][0])
key_index = [int(v) for v in obs["x_axis"]]
except ValueError:
key_index = [pd.Timestamp(v) for v in obs["x_axis"]]

observations_dfs.append(
pd.DataFrame(
{
"STD": obs["errors"],
"OBS": obs["values"],
"key_index": key_index,
}
)
)

all_observations = pd.concat([all_observations, *observations_dfs])

return all_observations.T

Expand Down

0 comments on commit 60ed648

Please sign in to comment.