Skip to content

Commit

Permalink
: make compatible with upstream ert storage
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkwah committed Jun 8, 2021
1 parent 96951af commit 4252bf8
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions ert3/storage/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ def _init_experiment(
url=f"{_STORAGE_URL}/experiments/{exp_id}/ensembles",
json={
"parameter_names": [
f"{record}@{param}"
f"{record}.{param}"
for record, params in parameters.items()
for param in params
],
"response_names": [],
"size": ensemble_size,
"metadata": {"name": experiment_name},
},
)
if response.status_code != 200:
Expand Down Expand Up @@ -141,7 +142,7 @@ def _add_numerical_data(
record_type=_get_record_type(ensemble_record),
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
record_url = f"{_STORAGE_URL}/ensembles/{ensemble_id}/records/{record_name}"

for idx, record in enumerate(ensemble_record.records):
Expand Down Expand Up @@ -187,35 +188,34 @@ def _add_parameter_numerical_data(
record_type=_get_record_type(ensemble_record),
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp

for idx, record in enumerate(ensemble_record.records):
for param_name in record.index:
record_url = f"{_STORAGE_URL}/ensembles/{ensemble_id}/records/{record_name}%40{param_name}"
df = pd.DataFrame(
[record.data[param_name]], columns=[param_name], index=[idx]
)
response = requests.post(
url=f"{record_url}/matrix",
params={"realization_index": idx},
data=df.to_csv().encode(),
headers={"content-type": "text/csv"},
)

if response.status_code == 409:
raise ert3.exceptions.ElementExistsError("Record already exists")

if response.status_code != 200:
raise ert3.exceptions.StorageError(response.text)
record = ensemble_record.records[0]
for param_name in record.index:
record_url = (
f"{_STORAGE_URL}/ensembles/{ensemble_id}/records/{record_name}.{param_name}"
)
df = pd.DataFrame(
[r.data[param_name] for r in ensemble_record.records],
columns=[param_name],
)
response = requests.post(
url=f"{record_url}/matrix",
data=df.to_csv().encode(),
headers={"content-type": "text/csv"},
)

meta_response = requests.put(
url=f"{record_url}/metadata",
params={"realization_index": idx},
json=metadata.dict(),
)
if response.status_code == 409:
raise ert3.exceptions.ElementExistsError("Record already exists")
if response.status_code != 200:
raise ert3.exceptions.StorageError(response.text)
meta_response = requests.put(
url=f"{record_url}/metadata",
json=metadata.dict(),
)

if meta_response.status_code != 200:
raise ert3.exceptions.StorageError(meta_response.text)
if meta_response.status_code != 200:
raise ert3.exceptions.StorageError(meta_response.text)


def _response2record(
Expand Down Expand Up @@ -277,7 +277,7 @@ def _get_numerical_data(
f"Cannot get {record_name} data, no experiment named: {experiment_name}"
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
metadata = _get_numerical_metadata(ensemble_id, record_name)

records = []
Expand Down Expand Up @@ -315,13 +315,13 @@ def _get_experiment_parameters(
f"Cannot get parameters from non-existing experiment: {experiment_name}"
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
response = requests.get(url=f"{_STORAGE_URL}/ensembles/{ensemble_id}/parameters")
if response.status_code != 200:
raise ert3.exceptions.StorageError(response.text)
parameters = {}
for name in response.json():
key, val = name.split("@")
key, val = name.split(".")
if key in parameters:
parameters[key].append(val)
else:
Expand Down Expand Up @@ -361,7 +361,7 @@ def get_ensemble_record(
if record_name in param_names:
ensemble_records = [
_get_numerical_data(
workspace, experiment_name, f"{record_name}%40{param_name}"
workspace, experiment_name, f"{record_name}.{param_name}"
)
for param_name in param_names[record_name]
]
Expand Down Expand Up @@ -391,7 +391,7 @@ def get_ensemble_record_names(
f"Cannot get record names of non-existing experiment: {experiment_name}"
)

ensemble_id = experiment["ensembles"][0] # currently just one ens per exp
ensemble_id = experiment["ensemble_ids"][0] # currently just one ens per exp
response = requests.get(url=f"{_STORAGE_URL}/ensembles/{ensemble_id}/records")
if response.status_code != 200:
raise ert3.exceptions.StorageError(response.text)
Expand Down

0 comments on commit 4252bf8

Please sign in to comment.