Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid assuming inplace units + support descriptions of any column. #389

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,74 @@
{
"BULK_OIL": {"label": "Bulk volume (oil zone)", "unit": "m³"},
"BULK_GAS": {"label": "Bulk volume (gas zone)", "unit": "m³"},
"BULK_TOTAL": {"label": "Bulk volume (total)", "unit": "m³"},
"NET_OIL": {"label": "Net volume (oil zone)", "unit": "m³"},
"NET_GAS": {"label": "Net volume (gas zone)", "unit": "m³"},
"NET_TOTAL": {"label": "Net volume (total)", "unit": "m³"},
"PORV_OIL": {"label": "Pore volume (oil zone)", "unit": "m³"},
"PORV_GAS": {"label": "Pore volume (gas zone)", "unit": "m³"},
"PORV_TOTAL": {"label": "Pore volume (total)", "unit": "m³"},
"PORE_OIL": {"label": "Pore volume (oil zone)", "unit": "m³"},
"PORE_GAS": {"label": "Pore volume (gas zone)", "unit": "m³"},
"PORE_TOTAL": {"label": "Pore volume (total)", "unit": "m³"},
"HCPV_OIL": {"label": "Hydro carbon pore volume (oil zone)", "unit": "m³"},
"HCPV_GAS": {"label": "Hydro carbon pore volume (gas zone)", "unit": "m³"},
"HCPV_TOTAL": {"label": "Hydro carbon pore volume (total zone)", "unit": "m³"},
"STOIIP_OIL": {"label": "Stock tank oil initially in place (oil zone)", "unit": "Sm³", "eclsum": ["FOIPL", "ROIPL"]},
"STOIIP_GAS": {"label": "Stock tank oil initially in place (gas zone)", "unit": "Sm³", "eclsum": ["FOIPG", "ROIPG"]},
"STOIIP_TOTAL": {"label": "Stock tank oil initially in place (total)", "unit": "Sm³", "eclsum": ["FOIP", "ROIP"]},
"GIIP_OIL": {"label": "Gas initially in place (oil zone)", "unit": "Sm³", "eclsum": ["FGIPL", "RGIPL"]},
"GIIP_GAS": {"label": "Gas initially in place (gas zone)", "unit": "Sm³", "eclsum": ["FGIPG", "RGIPG"]},
"GIIP_TOTAL": {"label": "Gas initially in place (total)", "unit": "Sm³", "eclsum": ["FGIP", "RGIP"]},
"RECOVERABLE_OIL": {"label": "Recoverable volume (oil zone)", "unit": "Sm³"},
"RECOVERABLE_GAS": {"label": "Recoverable volume (gas zone)", "unit": "Sm³"},
"RECOVERABLE_TOTAL": {"label": "Recoverable volume (total)", "unit": "Sm³"}
"BULK_OIL": {
"description": "Bulk volume (oil zone)"
},
"BULK_GAS": {
"description": "Bulk volume (gas zone)"
},
"BULK_TOTAL": {
"description": "Bulk volume (total)"
},
"NET_OIL": {
"description": "Net volume (oil zone)"
},
"NET_GAS": {
"description": "Net volume (gas zone)"
},
"NET_TOTAL": {
"description": "Net volume (total)"
},
"PORV_OIL": {
"description": "Pore volume (oil zone)"
},
"PORV_GAS": {
"description": "Pore volume (gas zone)"
},
"PORV_TOTAL": {
"description": "Pore volume (total)"
},
"PORE_OIL": {
"description": "Pore volume (oil zone)"
},
"PORE_GAS": {
"description": "Pore volume (gas zone)"
},
"PORE_TOTAL": {
"description": "Pore volume (total)"
},
"HCPV_OIL": {
"description": "Hydro carbon pore volume (oil zone)"
},
"HCPV_GAS": {
"description": "Hydro carbon pore volume (gas zone)"
},
"HCPV_TOTAL": {
"description": "Hydro carbon pore volume (total zone)"
},
"STOIIP_OIL": {
"description": "Stock tank oil initially in place (oil zone)"
},
"STOIIP_GAS": {
"description": "Stock tank oil initially in place (gas zone)"
},
"STOIIP_TOTAL": {
"description": "Stock tank oil initially in place (total)"
},
"GIIP_OIL": {
"description": "Gas initially in place (oil zone)"
},
"GIIP_GAS": {
"description": "Gas initially in place (gas zone)"
},
"GIIP_TOTAL": {
"description": "Gas initially in place (total)"
},
"RECOVERABLE_OIL": {
"description": "Recoverable volume (oil zone)"
},
"RECOVERABLE_GAS": {
"description": "Recoverable volume (gas zone)"
},
"RECOVERABLE_TOTAL": {
"description": "Recoverable volume (total)"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"BULK_OIL": {"description": "Bulk volume (oil zone)", "unit": "m³"},
"BULK_GAS": {"description": "Bulk volume (gas zone)", "unit": "m³"},
"BULK_TOTAL": {"description": "Bulk volume (total)", "unit": "m³"},
"NET_OIL": {"description": "Net volume (oil zone)", "unit": "m³"},
"NET_GAS": {"description": "Net volume (gas zone)", "unit": "m³"},
"NET_TOTAL": {"description": "Net volume (total)", "unit": "m³"},
"PORV_OIL": {"description": "Pore volume (oil zone)", "unit": "m³"},
"PORV_GAS": {"description": "Pore volume (gas zone)", "unit": "m³"},
"PORV_TOTAL": {"description": "Pore volume (total)", "unit": "m³"},
"PORE_OIL": {"description": "Pore volume (oil zone)", "unit": "m³"},
"PORE_GAS": {"description": "Pore volume (gas zone)", "unit": "m³"},
"PORE_TOTAL": {"description": "Pore volume (total)", "unit": "m³"},
"HCPV_OIL": {"description": "Hydro carbon pore volume (oil zone)", "unit": "m³"},
"HCPV_GAS": {"description": "Hydro carbon pore volume (gas zone)", "unit": "m³"},
"HCPV_TOTAL": {"description": "Hydro carbon pore volume (total zone)", "unit": "m³"},
"STOIIP_OIL": {"description": "Stock tank oil initially in place (oil zone)", "unit": "Sm³"},
"STOIIP_GAS": {"description": "Stock tank oil initially in place (gas zone)", "unit": "Sm³"},
"STOIIP_TOTAL": {"description": "Stock tank oil initially in place (total)", "unit": "Sm³"},
"GIIP_OIL": {"description": "Gas initially in place (oil zone)", "unit": "Sm³"},
"GIIP_GAS": {"description": "Gas initially in place (gas zone)", "unit": "Sm³"},
"GIIP_TOTAL": {"description": "Gas initially in place (total)", "unit": "Sm³"},
"RECOVERABLE_OIL": {"description": "Recoverable volume (oil zone)", "unit": "Sm³"},
"RECOVERABLE_GAS": {"description": "Recoverable volume (gas zone)", "unit": "Sm³"},
"RECOVERABLE_TOTAL": {"description": "Recoverable volume (total)", "unit": "Sm³"}
}
53 changes: 31 additions & 22 deletions webviz_subsurface/_abbreviations/volume_terminology.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
import json
import pathlib

from typing import Optional, Union

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

VOLUME_TERMINOLOGY = json.loads((_DATA_PATH / "volume_terminology.json").read_text())
VOLUME_TERMINOLOGY_METRIC = json.loads(
(_DATA_PATH / "volume_terminology_metric.json").read_text()
)


def volume_description(column: str):
def volume_description(column: str, metadata: Optional[Union[dict, str]] = None):
"""Return description for the column if defined"""
if metadata is not None:
try:
if isinstance(metadata, dict):
return metadata[column]["description"]
if isinstance(metadata, str) and metadata.lower() == "metric":
return VOLUME_TERMINOLOGY_METRIC[column]["description"]
except KeyError:
pass
try:
label = VOLUME_TERMINOLOGY[column]["label"]
description = VOLUME_TERMINOLOGY[column]["description"]
except KeyError:
label = column
return label
description = column
return description


def volume_unit(column: str):
def volume_unit(column: str, metadata: Optional[Union[dict, str]] = None):
"""Return unit for the column if defined"""
try:
unit = VOLUME_TERMINOLOGY[column]["unit"]
except KeyError:
unit = ""
return unit


def volume_simulation_vector_match(column: str):
"""Return a list of simulation vectors that match the column
Useful to verify/propose data to compare.
"""
try:
vectors = VOLUME_TERMINOLOGY[column]["eclsum"]
except KeyError:
vectors = []
return vectors if isinstance(vectors, list) else [vectors]
if metadata is not None:
try:
if isinstance(metadata, dict):
return metadata[column]["unit"]
if isinstance(metadata, str) and metadata.lower() == "metric":
return VOLUME_TERMINOLOGY_METRIC[column]["unit"]
except KeyError:
pass
return ""


def column_title(response: str, metadata: Union[dict, str]):
unit = volume_unit(response, metadata)
return f"{volume_description(response, metadata)}" + (f" [{unit}]" if unit else "")
14 changes: 14 additions & 0 deletions webviz_subsurface/_datainput/inplace_volumes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
from pathlib import Path
from io import BytesIO
import json

import pandas as pd
import fmu.ensemble
Expand Down Expand Up @@ -40,3 +43,14 @@ def extract_volumes(ensemble_paths, volfolder, volfiles) -> pd.DataFrame:
f"Ensure that the files are present in relative folder {volfolder}"
)
return pd.concat(dfs)


@CACHE.memoize(timeout=CACHE.TIMEOUT)
@webvizstore
def get_metadata(metadata: Path) -> BytesIO:
"""Returns a json formatted dict stored in a BytesIO object"""
metadict = json.loads(metadata.read_text())
bytesio = BytesIO()
bytesio.write(json.dumps(metadict).encode())
bytesio.seek(0)
return bytesio
Loading