Skip to content

Commit 9517136

Browse files
committed
Avoid assuming inplace units + support descriptions of any column.
1 parent 22644b9 commit 9517136

File tree

5 files changed

+199
-111
lines changed

5 files changed

+199
-111
lines changed

webviz_subsurface/_abbreviations/abbreviation_data/volume_terminology.json

+72-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,74 @@
11
{
2-
"BULK_OIL": {"label": "Bulk volume (oil zone)", "unit": ""},
3-
"BULK_GAS": {"label": "Bulk volume (gas zone)", "unit": ""},
4-
"BULK_TOTAL": {"label": "Bulk volume (total)", "unit": ""},
5-
"NET_OIL": {"label": "Net volume (oil zone)", "unit": ""},
6-
"NET_GAS": {"label": "Net volume (gas zone)", "unit": ""},
7-
"NET_TOTAL": {"label": "Net volume (total)", "unit": ""},
8-
"PORV_OIL": {"label": "Pore volume (oil zone)", "unit": ""},
9-
"PORV_GAS": {"label": "Pore volume (gas zone)", "unit": ""},
10-
"PORV_TOTAL": {"label": "Pore volume (total)", "unit": ""},
11-
"PORE_OIL": {"label": "Pore volume (oil zone)", "unit": ""},
12-
"PORE_GAS": {"label": "Pore volume (gas zone)", "unit": ""},
13-
"PORE_TOTAL": {"label": "Pore volume (total)", "unit": ""},
14-
"HCPV_OIL": {"label": "Hydro carbon pore volume (oil zone)", "unit": ""},
15-
"HCPV_GAS": {"label": "Hydro carbon pore volume (gas zone)", "unit": ""},
16-
"HCPV_TOTAL": {"label": "Hydro carbon pore volume (total zone)", "unit": ""},
17-
"STOIIP_OIL": {"label": "Stock tank oil initially in place (oil zone)", "unit": "Sm³", "eclsum": ["FOIPL", "ROIPL"]},
18-
"STOIIP_GAS": {"label": "Stock tank oil initially in place (gas zone)", "unit": "Sm³", "eclsum": ["FOIPG", "ROIPG"]},
19-
"STOIIP_TOTAL": {"label": "Stock tank oil initially in place (total)", "unit": "Sm³", "eclsum": ["FOIP", "ROIP"]},
20-
"GIIP_OIL": {"label": "Gas initially in place (oil zone)", "unit": "Sm³", "eclsum": ["FGIPL", "RGIPL"]},
21-
"GIIP_GAS": {"label": "Gas initially in place (gas zone)", "unit": "Sm³", "eclsum": ["FGIPG", "RGIPG"]},
22-
"GIIP_TOTAL": {"label": "Gas initially in place (total)", "unit": "Sm³", "eclsum": ["FGIP", "RGIP"]},
23-
"RECOVERABLE_OIL": {"label": "Recoverable volume (oil zone)", "unit": "Sm³"},
24-
"RECOVERABLE_GAS": {"label": "Recoverable volume (gas zone)", "unit": "Sm³"},
25-
"RECOVERABLE_TOTAL": {"label": "Recoverable volume (total)", "unit": "Sm³"}
2+
"BULK_OIL": {
3+
"description": "Bulk volume (oil zone)"
4+
},
5+
"BULK_GAS": {
6+
"description": "Bulk volume (gas zone)"
7+
},
8+
"BULK_TOTAL": {
9+
"description": "Bulk volume (total)"
10+
},
11+
"NET_OIL": {
12+
"description": "Net volume (oil zone)"
13+
},
14+
"NET_GAS": {
15+
"description": "Net volume (gas zone)"
16+
},
17+
"NET_TOTAL": {
18+
"description": "Net volume (total)"
19+
},
20+
"PORV_OIL": {
21+
"description": "Pore volume (oil zone)"
22+
},
23+
"PORV_GAS": {
24+
"description": "Pore volume (gas zone)"
25+
},
26+
"PORV_TOTAL": {
27+
"description": "Pore volume (total)"
28+
},
29+
"PORE_OIL": {
30+
"description": "Pore volume (oil zone)"
31+
},
32+
"PORE_GAS": {
33+
"description": "Pore volume (gas zone)"
34+
},
35+
"PORE_TOTAL": {
36+
"description": "Pore volume (total)"
37+
},
38+
"HCPV_OIL": {
39+
"description": "Hydro carbon pore volume (oil zone)"
40+
},
41+
"HCPV_GAS": {
42+
"description": "Hydro carbon pore volume (gas zone)"
43+
},
44+
"HCPV_TOTAL": {
45+
"description": "Hydro carbon pore volume (total zone)"
46+
},
47+
"STOIIP_OIL": {
48+
"description": "Stock tank oil initially in place (oil zone)"
49+
},
50+
"STOIIP_GAS": {
51+
"description": "Stock tank oil initially in place (gas zone)"
52+
},
53+
"STOIIP_TOTAL": {
54+
"description": "Stock tank oil initially in place (total)"
55+
},
56+
"GIIP_OIL": {
57+
"description": "Gas initially in place (oil zone)"
58+
},
59+
"GIIP_GAS": {
60+
"description": "Gas initially in place (gas zone)"
61+
},
62+
"GIIP_TOTAL": {
63+
"description": "Gas initially in place (total)"
64+
},
65+
"RECOVERABLE_OIL": {
66+
"description": "Recoverable volume (oil zone)"
67+
},
68+
"RECOVERABLE_GAS": {
69+
"description": "Recoverable volume (gas zone)"
70+
},
71+
"RECOVERABLE_TOTAL": {
72+
"description": "Recoverable volume (total)"
73+
}
2674
}
27-
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import json
22
import pathlib
3-
3+
from typing import Optional
44

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

77
VOLUME_TERMINOLOGY = json.loads((_DATA_PATH / "volume_terminology.json").read_text())
88

99

10-
def volume_description(column: str):
10+
def volume_description(column: str, metadata: Optional[dict] = None):
1111
"""Return description for the column if defined"""
12+
if metadata is not None:
13+
try:
14+
return metadata[column]["description"]
15+
except KeyError:
16+
pass
1217
try:
13-
label = VOLUME_TERMINOLOGY[column]["label"]
18+
description = VOLUME_TERMINOLOGY[column]["description"]
1419
except KeyError:
15-
label = column
16-
return label
20+
description = column
21+
return description
1722

1823

19-
def volume_unit(column: str):
24+
def volume_unit(column: str, metadata: Optional[dict] = None):
2025
"""Return unit for the column if defined"""
21-
try:
22-
unit = VOLUME_TERMINOLOGY[column]["unit"]
23-
except KeyError:
24-
unit = ""
25-
return unit
26+
if metadata is not None:
27+
try:
28+
return metadata[column]["unit"]
29+
except KeyError:
30+
pass
31+
return ""
2632

2733

28-
def volume_simulation_vector_match(column: str):
29-
"""Return a list of simulation vectors that match the column
30-
Useful to verify/propose data to compare.
31-
"""
32-
try:
33-
vectors = VOLUME_TERMINOLOGY[column]["eclsum"]
34-
except KeyError:
35-
vectors = []
36-
return vectors if isinstance(vectors, list) else [vectors]
34+
def column_title(response: str, metadata: dict):
35+
unit = volume_unit(response, metadata)
36+
return f"{volume_description(response, metadata)}" + (f" [{unit}]" if unit else "")

webviz_subsurface/_datainput/inplace_volumes.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import os
2+
from pathlib import Path
3+
from io import BytesIO
4+
import json
25

36
import pandas as pd
47
import fmu.ensemble
@@ -40,3 +43,14 @@ def extract_volumes(ensemble_paths, volfolder, volfiles) -> pd.DataFrame:
4043
f"Ensure that the files are present in relative folder {volfolder}"
4144
)
4245
return pd.concat(dfs)
46+
47+
48+
@CACHE.memoize(timeout=CACHE.TIMEOUT)
49+
@webvizstore
50+
def get_metadata(metadata: Path) -> BytesIO:
51+
"""Returns a json formatted dict stored in a BytesIO object"""
52+
metadict = json.loads(metadata.read_text())
53+
bytesio = BytesIO()
54+
bytesio.write(json.dumps(metadict).encode())
55+
bytesio.seek(0)
56+
return bytesio

0 commit comments

Comments
 (0)