Skip to content

Commit

Permalink
Account for ert and ert3 discrepancy when uploading parameter data to…
Browse files Browse the repository at this point in the history
… storage.
  • Loading branch information
DanSava committed Nov 23, 2021
1 parent 906aaa0 commit 1a22ee8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
28 changes: 20 additions & 8 deletions webviz_ert/data_loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,27 @@ def get_experiment_priors(self, experiment_id: str) -> dict:
)

def get_ensemble_parameter_data(
self, ensemble_id: str, parameter_name: str
self,
ensemble_id: str,
parameter_name: str,
realizations: list,
) -> pd.DataFrame:
resp = self._get(
url=f"ensembles/{ensemble_id}/records/{parameter_name}",
headers={"accept": "application/x-parquet"},
)
stream = io.BytesIO(resp.content)
df = pd.read_parquet(stream)
return df

try:
resp = self._get(
url=f"ensembles/{ensemble_id}/records/{parameter_name}",
headers={"accept": "application/x-parquet"},
)
stream = io.BytesIO(resp.content)
df = pd.read_parquet(stream)
return df
except DataLoaderException as e:
logger.error(e)
return self.get_ensemble_record_data(
ensemble_id=ensemble_id,
record_name=parameter_name,
active_realizations=realizations,
)

def get_ensemble_record_data(
self, ensemble_id: str, record_name: str, active_realizations: List[int]
Expand Down
8 changes: 7 additions & 1 deletion webviz_ert/models/ensemble_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@


def _create_parameter_models(
parameters_names: list, priors: dict, ensemble_id: str, project_id: str
parameters_names: list,
priors: dict,
ensemble_id: str,
project_id: str,
realizations: list,
) -> Optional[Mapping[str, ParametersModel]]:
parameters = {}
for param in parameters_names:
Expand All @@ -30,6 +34,7 @@ def _create_parameter_models(
param_id="", # TODO?
project_id=project_id,
ensemble_id=ensemble_id,
realizations=realizations,
)
return parameters

Expand Down Expand Up @@ -109,6 +114,7 @@ def parameters(
parameter_priors,
ensemble_id=self._id,
project_id=self._project_id,
realizations=self._active_realizations,
)
return self._parameters

Expand Down
5 changes: 4 additions & 1 deletion webviz_ert/models/parameter_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ def __init__(self, **kwargs: Any):
self._data_loader = get_data_loader(self._project_id)

def data_df(self) -> pd.DataFrame:
realization = [] if self._realizations is None else self._realizations
if self._data_df.empty:
_data_df = self._data_loader.get_ensemble_parameter_data(
ensemble_id=self._ensemble_id, parameter_name=self.key
ensemble_id=self._ensemble_id,
parameter_name=self.key,
realizations=realization,
)
if _data_df is not None:
_data_df = _data_df.transpose()
Expand Down

0 comments on commit 1a22ee8

Please sign in to comment.