Skip to content

Commit d4d447f

Browse files
committed
add metric option to metadata
1 parent a423b7f commit d4d447f

File tree

4 files changed

+72
-29
lines changed

4 files changed

+72
-29
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"BULK_OIL": {"description": "Bulk volume (oil zone)", "unit": ""},
3+
"BULK_GAS": {"description": "Bulk volume (gas zone)", "unit": ""},
4+
"BULK_TOTAL": {"description": "Bulk volume (total)", "unit": ""},
5+
"NET_OIL": {"description": "Net volume (oil zone)", "unit": ""},
6+
"NET_GAS": {"description": "Net volume (gas zone)", "unit": ""},
7+
"NET_TOTAL": {"description": "Net volume (total)", "unit": ""},
8+
"PORV_OIL": {"description": "Pore volume (oil zone)", "unit": ""},
9+
"PORV_GAS": {"description": "Pore volume (gas zone)", "unit": ""},
10+
"PORV_TOTAL": {"description": "Pore volume (total)", "unit": ""},
11+
"PORE_OIL": {"description": "Pore volume (oil zone)", "unit": ""},
12+
"PORE_GAS": {"description": "Pore volume (gas zone)", "unit": ""},
13+
"PORE_TOTAL": {"description": "Pore volume (total)", "unit": ""},
14+
"HCPV_OIL": {"description": "Hydro carbon pore volume (oil zone)", "unit": ""},
15+
"HCPV_GAS": {"description": "Hydro carbon pore volume (gas zone)", "unit": ""},
16+
"HCPV_TOTAL": {"description": "Hydro carbon pore volume (total zone)", "unit": ""},
17+
"STOIIP_OIL": {"description": "Stock tank oil initially in place (oil zone)", "unit": "Sm³"},
18+
"STOIIP_GAS": {"description": "Stock tank oil initially in place (gas zone)", "unit": "Sm³"},
19+
"STOIIP_TOTAL": {"description": "Stock tank oil initially in place (total)", "unit": "Sm³"},
20+
"GIIP_OIL": {"description": "Gas initially in place (oil zone)", "unit": "Sm³"},
21+
"GIIP_GAS": {"description": "Gas initially in place (gas zone)", "unit": "Sm³"},
22+
"GIIP_TOTAL": {"description": "Gas initially in place (total)", "unit": "Sm³"},
23+
"RECOVERABLE_OIL": {"description": "Recoverable volume (oil zone)", "unit": "Sm³"},
24+
"RECOVERABLE_GAS": {"description": "Recoverable volume (gas zone)", "unit": "Sm³"},
25+
"RECOVERABLE_TOTAL": {"description": "Recoverable volume (total)", "unit": "Sm³"}
26+
}
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import json
22
import pathlib
3-
from typing import Optional
3+
from typing import Optional, Union
44

55
_DATA_PATH = pathlib.Path(__file__).parent.absolute() / "abbreviation_data"
66

77
VOLUME_TERMINOLOGY = json.loads((_DATA_PATH / "volume_terminology.json").read_text())
8+
VOLUME_TERMINOLOGY_METRIC = json.loads(
9+
(_DATA_PATH / "volume_terminology_metric.json").read_text()
10+
)
811

912

10-
def volume_description(column: str, metadata: Optional[dict] = None):
13+
def volume_description(column: str, metadata: Optional[Union[dict, str]] = None):
1114
"""Return description for the column if defined"""
1215
if metadata is not None:
1316
try:
14-
return metadata[column]["description"]
17+
if isinstance(metadata, dict):
18+
return metadata[column]["description"]
19+
if isinstance(metadata, str) and metadata.lower() == "metric":
20+
return VOLUME_TERMINOLOGY_METRIC[column]["description"]
1521
except KeyError:
1622
pass
1723
try:
@@ -21,16 +27,19 @@ def volume_description(column: str, metadata: Optional[dict] = None):
2127
return description
2228

2329

24-
def volume_unit(column: str, metadata: Optional[dict] = None):
30+
def volume_unit(column: str, metadata: Optional[Union[dict, str]] = None):
2531
"""Return unit for the column if defined"""
2632
if metadata is not None:
2733
try:
28-
return metadata[column]["unit"]
34+
if isinstance(metadata, dict):
35+
return metadata[column]["unit"]
36+
if isinstance(metadata, str) and metadata.lower() == "metric":
37+
return VOLUME_TERMINOLOGY_METRIC[column]["unit"]
2938
except KeyError:
3039
pass
3140
return ""
3241

3342

34-
def column_title(response: str, metadata: dict):
43+
def column_title(response: str, metadata: Union[dict, str]):
3544
unit = volume_unit(response, metadata)
3645
return f"{volume_description(response, metadata)}" + (f" [{unit}]" if unit else "")

webviz_subsurface/plugins/_inplace_volumes.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pathlib import Path
22
import json
3+
from typing import Optional
34

45
import numpy as np
56
import pandas as pd
@@ -91,12 +92,12 @@ class InplaceVolumes(WebvizPluginABC):
9192
def __init__(
9293
self,
9394
app,
94-
csvfile: Path = None,
95-
ensembles: list = None,
96-
volfiles: dict = None,
95+
csvfile: Optional[Path] = None,
96+
ensembles: Optional[list] = None,
97+
volfiles: Optional[dict] = None,
9798
volfolder: str = "share/results/volumes",
9899
response: str = "STOIIP_OIL",
99-
metadata: Path = None,
100+
metadata: Optional[str] = None,
100101
):
101102

102103
super().__init__()
@@ -126,12 +127,16 @@ def __init__(
126127
)
127128

128129
self.initial_response = response
129-
self.metadata_path = metadata
130-
self.metadata = (
131-
self.metadata_path
132-
if self.metadata_path is None
133-
else json.load(get_metadata(self.metadata_path))
134-
)
130+
if isinstance(metadata, str) and metadata.lower() == "metric":
131+
self.metadata_path = None
132+
self.metadata = metadata
133+
else:
134+
self.metadata_path = None if metadata is None else Path(metadata)
135+
self.metadata = (
136+
self.metadata_path
137+
if self.metadata_path is None
138+
else json.load(get_metadata(self.metadata_path))
139+
)
135140
self.selectors_id = {x: self.uuid(x) for x in self.selectors}
136141
self.plotly_theme = app.webviz_settings["theme"].plotly_theme
137142
if len(self.volumes["ENSEMBLE"].unique()) > 1:
@@ -207,7 +212,7 @@ def add_webvizstore(self):
207212
],
208213
)
209214
)
210-
if self.metadata is not None:
215+
if self.metadata_path is not None:
211216
functions.append((get_metadata, [{"metadata": self.metadata_path}]))
212217
return functions
213218

webviz_subsurface/plugins/_inplace_volumes_onebyone.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ class InplaceVolumesOneByOne(WebvizPluginABC):
117117
def __init__(
118118
self,
119119
app,
120-
csvfile_vol: Path = None,
121-
csvfile_parameters: Path = None,
122-
ensembles: list = None,
123-
volfiles: dict = None,
120+
csvfile_vol: Optional[Path] = None,
121+
csvfile_parameters: Optional[Path] = None,
122+
ensembles: Optional[list] = None,
123+
volfiles: Optional[dict] = None,
124124
volfolder: str = "share/results/volumes",
125125
response: str = "STOIIP_OIL",
126-
metadata: Path = None,
126+
metadata: Optional[str] = None,
127127
):
128128

129129
super().__init__()
@@ -163,13 +163,16 @@ def __init__(
163163
'"ensembles" and "volfiles"'
164164
)
165165
self.initial_response = response
166-
self.metadata_path = metadata
167-
self.metadata = (
168-
self.metadata_path
169-
if self.metadata_path is None
170-
else json.load(get_metadata(self.metadata_path))
171-
)
172-
166+
if isinstance(metadata, str) and metadata.lower() == "metric":
167+
self.metadata_path = None
168+
self.metadata = metadata
169+
else:
170+
self.metadata_path = None if metadata is None else Path(metadata)
171+
self.metadata = (
172+
self.metadata_path
173+
if self.metadata_path is None
174+
else json.load(get_metadata(self.metadata_path))
175+
)
173176
# Merge into one dataframe
174177
# (TODO: Should raise error if not all ensembles have sensitivity data)
175178
self.volumes = pd.merge(volumes, parameters, on=["ENSEMBLE", "REAL"])

0 commit comments

Comments
 (0)