Skip to content

Commit

Permalink
add metric option to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
asnyv committed Aug 11, 2020
1 parent a423b7f commit d4d447f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"BULK_OIL": {"description": "Bulk volume (oil zone)", "unit": ""},
"BULK_GAS": {"description": "Bulk volume (gas zone)", "unit": ""},
"BULK_TOTAL": {"description": "Bulk volume (total)", "unit": ""},
"NET_OIL": {"description": "Net volume (oil zone)", "unit": ""},
"NET_GAS": {"description": "Net volume (gas zone)", "unit": ""},
"NET_TOTAL": {"description": "Net volume (total)", "unit": ""},
"PORV_OIL": {"description": "Pore volume (oil zone)", "unit": ""},
"PORV_GAS": {"description": "Pore volume (gas zone)", "unit": ""},
"PORV_TOTAL": {"description": "Pore volume (total)", "unit": ""},
"PORE_OIL": {"description": "Pore volume (oil zone)", "unit": ""},
"PORE_GAS": {"description": "Pore volume (gas zone)", "unit": ""},
"PORE_TOTAL": {"description": "Pore volume (total)", "unit": ""},
"HCPV_OIL": {"description": "Hydro carbon pore volume (oil zone)", "unit": ""},
"HCPV_GAS": {"description": "Hydro carbon pore volume (gas zone)", "unit": ""},
"HCPV_TOTAL": {"description": "Hydro carbon pore volume (total zone)", "unit": ""},
"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³"}
}
21 changes: 15 additions & 6 deletions webviz_subsurface/_abbreviations/volume_terminology.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import json
import pathlib
from typing import Optional
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, metadata: Optional[dict] = None):
def volume_description(column: str, metadata: Optional[Union[dict, str]] = None):
"""Return description for the column if defined"""
if metadata is not None:
try:
return metadata[column]["description"]
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:
Expand All @@ -21,16 +27,19 @@ def volume_description(column: str, metadata: Optional[dict] = None):
return description


def volume_unit(column: str, metadata: Optional[dict] = None):
def volume_unit(column: str, metadata: Optional[Union[dict, str]] = None):
"""Return unit for the column if defined"""
if metadata is not None:
try:
return metadata[column]["unit"]
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: dict):
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 "")
27 changes: 16 additions & 11 deletions webviz_subsurface/plugins/_inplace_volumes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pathlib import Path
import json
from typing import Optional

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -91,12 +92,12 @@ class InplaceVolumes(WebvizPluginABC):
def __init__(
self,
app,
csvfile: Path = None,
ensembles: list = None,
volfiles: dict = None,
csvfile: Optional[Path] = None,
ensembles: Optional[list] = None,
volfiles: Optional[dict] = None,
volfolder: str = "share/results/volumes",
response: str = "STOIIP_OIL",
metadata: Path = None,
metadata: Optional[str] = None,
):

super().__init__()
Expand Down Expand Up @@ -126,12 +127,16 @@ def __init__(
)

self.initial_response = response
self.metadata_path = metadata
self.metadata = (
self.metadata_path
if self.metadata_path is None
else json.load(get_metadata(self.metadata_path))
)
if isinstance(metadata, str) and metadata.lower() == "metric":
self.metadata_path = None
self.metadata = metadata
else:
self.metadata_path = None if metadata is None else Path(metadata)
self.metadata = (
self.metadata_path
if self.metadata_path is None
else json.load(get_metadata(self.metadata_path))
)
self.selectors_id = {x: self.uuid(x) for x in self.selectors}
self.plotly_theme = app.webviz_settings["theme"].plotly_theme
if len(self.volumes["ENSEMBLE"].unique()) > 1:
Expand Down Expand Up @@ -207,7 +212,7 @@ def add_webvizstore(self):
],
)
)
if self.metadata is not None:
if self.metadata_path is not None:
functions.append((get_metadata, [{"metadata": self.metadata_path}]))
return functions

Expand Down
27 changes: 15 additions & 12 deletions webviz_subsurface/plugins/_inplace_volumes_onebyone.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ class InplaceVolumesOneByOne(WebvizPluginABC):
def __init__(
self,
app,
csvfile_vol: Path = None,
csvfile_parameters: Path = None,
ensembles: list = None,
volfiles: dict = None,
csvfile_vol: Optional[Path] = None,
csvfile_parameters: Optional[Path] = None,
ensembles: Optional[list] = None,
volfiles: Optional[dict] = None,
volfolder: str = "share/results/volumes",
response: str = "STOIIP_OIL",
metadata: Path = None,
metadata: Optional[str] = None,
):

super().__init__()
Expand Down Expand Up @@ -163,13 +163,16 @@ def __init__(
'"ensembles" and "volfiles"'
)
self.initial_response = response
self.metadata_path = metadata
self.metadata = (
self.metadata_path
if self.metadata_path is None
else json.load(get_metadata(self.metadata_path))
)

if isinstance(metadata, str) and metadata.lower() == "metric":
self.metadata_path = None
self.metadata = metadata
else:
self.metadata_path = None if metadata is None else Path(metadata)
self.metadata = (
self.metadata_path
if self.metadata_path is None
else json.load(get_metadata(self.metadata_path))
)
# Merge into one dataframe
# (TODO: Should raise error if not all ensembles have sensitivity data)
self.volumes = pd.merge(volumes, parameters, on=["ENSEMBLE", "REAL"])
Expand Down

0 comments on commit d4d447f

Please sign in to comment.