-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e60b90
commit c5ac32a
Showing
10 changed files
with
288 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .well_log_viewer import WellLogViewer |
15 changes: 15 additions & 0 deletions
15
webviz_subsurface/plugins/_well_log_viewer/_validate_log_templates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import List, Dict, Any | ||
from pathlib import Path | ||
|
||
import yaml | ||
|
||
|
||
def load_and_validate_log_templates(log_templates: List[Path]) -> Dict[str, Any]: | ||
validated_templates = {} | ||
for idx, template_path in enumerate(log_templates): | ||
template = yaml.safe_load(template_path.read_text()) | ||
# Validate against json schema here when available | ||
# https://github.com/equinor/webviz-subsurface-components/issues/508 | ||
template_name = template.get("name", f"template_{idx+1}") | ||
validated_templates[template_name] = template | ||
return validated_templates |
1 change: 1 addition & 0 deletions
1
webviz_subsurface/plugins/_well_log_viewer/controllers/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._well_controller import well_controller |
88 changes: 88 additions & 0 deletions
88
webviz_subsurface/plugins/_well_log_viewer/controllers/_well_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from typing import List, Dict, Callable, Tuple, Any, Optional | ||
import xtgeo | ||
import dash | ||
from dash.dependencies import Input, Output | ||
from webviz_subsurface._models.well_set_model import WellSetModel | ||
|
||
|
||
def well_controller( | ||
app: dash.Dash, | ||
well_set_model: WellSetModel, | ||
log_templates: Dict, | ||
get_uuid: Callable, | ||
) -> None: | ||
@app.callback( | ||
Output(get_uuid("well-log-viewer"), "welllog"), | ||
Output(get_uuid("well-log-viewer"), "template"), | ||
Input(get_uuid("well"), "value"), | ||
Input(get_uuid("template"), "value"), | ||
) | ||
def _update_log_data(well_name: str, template: str) -> Tuple[Any, Any]: | ||
well = well_set_model.get_well(well_name) | ||
return xtgeo_well_logs_to_json_format(well), log_templates.get(template) | ||
|
||
|
||
def xtgeo_well_logs_to_json_format(well: xtgeo.Well) -> List[Dict]: | ||
|
||
header = generate_header(well_name=well.name) | ||
curves = [] | ||
|
||
# Calculate well geometrics if MD log is not provided | ||
if well.mdlogname is None: | ||
well.geometrics() | ||
|
||
# Add MD and TVD curves | ||
curves.append(generate_curve(log_name="MD", description="Measured depth")) | ||
curves.append( | ||
generate_curve(log_name="TVD", description="True vertical depth (SS)") | ||
) | ||
# Add additonal logs, skipping geometrical logs if calculated | ||
lognames = [ | ||
logname | ||
for logname in well.lognames | ||
if logname not in ["Q_MDEPTH", "Q_AZI", "Q_INCL", "R_HLEN"] | ||
] | ||
for logname in lognames: | ||
curves.append(generate_curve(log_name=logname.upper())) | ||
|
||
# Filter dataframe to only include relevant logs | ||
curve_names = [well.mdlogname, "Z_TVDSS"] + lognames | ||
dframe = well.dataframe[curve_names] | ||
dframe = dframe.reindex(curve_names, axis=1) | ||
|
||
return [{"header": header, "curves": curves, "data": dframe.values.tolist()}] | ||
|
||
|
||
def generate_header(well_name: str, logrun_name: str = "log") -> Dict[str, Any]: | ||
return { | ||
"name": logrun_name, | ||
"well": well_name, | ||
"wellbore": None, | ||
"field": None, | ||
"country": None, | ||
"date": None, | ||
"operator": None, | ||
"serviceCompany": None, | ||
"runNumber": None, | ||
"elevation": None, | ||
"source": None, | ||
"startIndex": None, | ||
"endIndex": None, | ||
"step": None, | ||
"dataUri": None, | ||
} | ||
|
||
|
||
def generate_curve( | ||
log_name: str, description: Optional[str] = None, value_type: str = "float" | ||
) -> Dict[str, Any]: | ||
return { | ||
"name": log_name, | ||
"description": description, | ||
"valueType": value_type, | ||
"dimensions": 1, | ||
"unit": "m", | ||
"quantity": None, | ||
"axis": None, | ||
"maxSize": 20, | ||
} |
177 changes: 177 additions & 0 deletions
177
webviz_subsurface/plugins/_well_log_viewer/well_log_viewer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
from typing import List, Dict, Union, Tuple, Callable | ||
from pathlib import Path | ||
import json | ||
|
||
import dash | ||
import dash_html_components as html | ||
from webviz_config import WebvizPluginABC | ||
import webviz_core_components as wcc | ||
from webviz_subsurface_components import WellLogViewer as WellLogViewerComponent | ||
|
||
from webviz_subsurface._models.well_set_model import WellSetModel | ||
from webviz_subsurface._utils.webvizstore_functions import find_files, get_path | ||
from .controllers import well_controller | ||
from ._validate_log_templates import load_and_validate_log_templates | ||
|
||
|
||
class WellLogViewer(WebvizPluginABC): | ||
"""Uses [videx-welllog](https://github.com/equinor/videx-wellog) to visualize well logs | ||
from files stored in RMS well format. | ||
?> Currently tracks for visualizing discrete logs are not included. This will | ||
be added in later releases. | ||
--- | ||
* **`wellfolder`:** Path to a folder with well files stored in RMS well format. | ||
* **`wellsuffix`:** File suffix of well files | ||
* **`logtemplates`:** List of yaml based log template configurations. \ | ||
See the data section for description of the format. | ||
* **`mdlog`:** Name of the md log. If not specified, MD will be calculated. | ||
* **`well_tvdmin`:** Truncate well data values above this depth. | ||
* **`well_tvdmax`:** Truncate well data values below this depth. | ||
* **`well_downsample_interval`:** Sampling interval used for coarsening a well trajectory | ||
* **`initial_settings`:** Configuration for initializing the plugin with various \ | ||
properties set. All properties are optional. | ||
See the data section for available properties. | ||
--- | ||
?> The format and documentation of the log template configuration will be improved \ | ||
in later releases. A small configuration sample is provided below. | ||
```yaml | ||
name: All logs # Name of the log template | ||
scale: | ||
primary: MD # Which reference track to visualize as default (MD/TVD) | ||
allowSecondary: False # Set to True to show both MD and TVD reference tracks. | ||
tracks: # The list of log tracks | ||
- title: Porosity # Optional title of log track | ||
plots: # List of which logs to include in the track | ||
- name: PHIT # Upper case name of log | ||
type: area # Type of visualiation (area, line, linestep, dot) | ||
color: green # Color of log | ||
- name: PHIT_ORIG | ||
type: line | ||
- plots: | ||
- name: ZONE | ||
type: area | ||
- plots: | ||
- name: FACIES | ||
type: area | ||
- plots: | ||
- name: VSH | ||
type: area | ||
- plots: | ||
- name: SW | ||
type: dot | ||
styles: # List of styles that can be added to tracks | ||
``` | ||
Format of the `initial_settings` argument: | ||
```yaml | ||
initial_settings: | ||
well: str # Name of well | ||
logtemplate: str # Name of log template | ||
``` | ||
""" | ||
|
||
# pylint: disable=too-many-arguments | ||
def __init__( | ||
self, | ||
app: dash.Dash, | ||
wellfolder: Path, | ||
logtemplates: List[Path], | ||
wellsuffix: str = ".w", | ||
mdlog: str = None, | ||
well_tvdmin: Union[int, float] = None, | ||
well_tvdmax: Union[int, float] = None, | ||
well_downsample_interval: int = None, | ||
initial_settings: Dict = None, | ||
): | ||
|
||
super().__init__() | ||
self._wellfolder = wellfolder | ||
self._wellsuffix = wellsuffix | ||
self._logtemplatefiles = logtemplates | ||
self._wellfiles: List = json.load( | ||
find_files(folder=self._wellfolder, suffix=self._wellsuffix) | ||
) | ||
self._log_templates = load_and_validate_log_templates( | ||
[get_path(fn) for fn in self._logtemplatefiles] | ||
) | ||
self._well_set_model = WellSetModel( | ||
self._wellfiles, | ||
mdlog=mdlog, | ||
tvdmin=well_tvdmin, | ||
tvdmax=well_tvdmax, | ||
downsample_interval=well_downsample_interval, | ||
) | ||
self._initial_settings = initial_settings if initial_settings else {} | ||
self.set_callbacks(app) | ||
|
||
@property | ||
def layout(self) -> html.Div: | ||
return wcc.FlexBox( | ||
[ | ||
wcc.Frame( | ||
style={"height": "90vh", "flex": 1}, | ||
children=[ | ||
wcc.Dropdown( | ||
label="Well", | ||
id=self.uuid("well"), | ||
options=[ | ||
{"label": name, "value": name} | ||
for name in self._well_set_model.well_names | ||
], | ||
value=self._initial_settings.get( | ||
"well_name", self._well_set_model.well_names[0] | ||
), | ||
clearable=False, | ||
), | ||
wcc.Dropdown( | ||
label="Log template", | ||
id=self.uuid("template"), | ||
options=[ | ||
{"label": name, "value": name} | ||
for name in list(self._log_templates.keys()) | ||
], | ||
value=self._initial_settings.get( | ||
"logtemplate", list(self._log_templates.keys())[0] | ||
), | ||
clearable=False, | ||
), | ||
], | ||
), | ||
wcc.Frame( | ||
style={"flex": 6, "height": "90vh"}, | ||
children=[ | ||
WellLogViewerComponent( | ||
id=self.uuid("well-log-viewer"), | ||
template=self._log_templates[ | ||
list(self._log_templates.keys())[0] | ||
], | ||
) | ||
], | ||
), | ||
] | ||
) | ||
|
||
def set_callbacks(self, app: dash.Dash) -> None: | ||
well_controller( | ||
app=app, | ||
well_set_model=self._well_set_model, | ||
log_templates=self._log_templates, | ||
get_uuid=self.uuid, | ||
) | ||
|
||
def add_webvizstore(self) -> List[Tuple[Callable, list]]: | ||
store_functions = [ | ||
(find_files, [{"folder": self._wellfolder, "suffix": self._wellsuffix}]) | ||
] | ||
store_functions.extend([(get_path, [{"path": fn}]) for fn in self._wellfiles]) | ||
store_functions.extend( | ||
[(get_path, [{"path": fn}]) for fn in self._logtemplatefiles] | ||
) | ||
return store_functions |