Skip to content

Commit

Permalink
Remove now unnecessary Path → str conversion wrt. xtgeo (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Apr 23, 2020
1 parent 83ab361 commit fafa5d6
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"scipy>=1.2",
"webviz-config>=0.0.48",
"webviz-subsurface-components>=0.0.23",
"xtgeo>=2.1",
"xtgeo>=2.8",
],
tests_require=TESTS_REQUIRE,
extras_require={"tests": TESTS_REQUIRE},
Expand Down
6 changes: 3 additions & 3 deletions webviz_subsurface/plugins/_segy_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _set_zslice(state):
if not state:
raise PreventUpdate
state = json.loads(state)
cube = load_cube_data(str(get_path(state["cubepath"])))
cube = load_cube_data(get_path(state["cubepath"]))
shapes = [
{
"type": "line",
Expand Down Expand Up @@ -370,7 +370,7 @@ def _set_iline(state):
if not state:
raise PreventUpdate
state = json.loads(state)
cube = load_cube_data(str(get_path(state["cubepath"])))
cube = load_cube_data(get_path(state["cubepath"]))
shapes = [
{
"type": "line",
Expand Down Expand Up @@ -416,7 +416,7 @@ def _set_xline(state):
if not state:
raise PreventUpdate
state = json.loads(state)
cube = load_cube_data(str(get_path(state["cubepath"])))
cube = load_cube_data(get_path(state["cubepath"]))
shapes = [
{
"type": "line",
Expand Down
10 changes: 4 additions & 6 deletions webviz_subsurface/plugins/_surface_viewer_fmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,15 @@ def get_real_runpath(self, data, ensemble, real):
]["RUNPATH"].unique()[0]
)

return str(
get_path(str(runpath / "share" / "results" / "maps" / f"{data}.gri"))
)
return get_path(runpath / "share" / "results" / "maps" / f"{data}.gri")

def get_ens_runpath(self, data, ensemble):
data = make_fmu_filename(data)
runpaths = self.ens_df.loc[(self.ens_df["ENSEMBLE"] == ensemble)][
"RUNPATH"
].unique()
return [
str((Path(runpath) / "share" / "results" / "maps" / f"{data}.gri"))
Path(runpath) / "share" / "results" / "maps" / f"{data}.gri"
for runpath in runpaths
]

Expand Down Expand Up @@ -552,14 +550,14 @@ def add_webvizstore(self):
for filename in filenames:
path = Path(runpath) / "share" / "results" / "maps" / filename
if path.exists():
store_functions.append((get_path, [{"path": str(path)}]))
store_functions.append((get_path, [{"path": path}]))

# Calculate and store statistics
for _, ens_df in self.ens_df.groupby("ENSEMBLE"):
runpaths = list(ens_df["RUNPATH"].unique())
for filename in filenames:
paths = [
str(Path(runpath) / "share" / "results" / "maps" / filename)
Path(runpath) / "share" / "results" / "maps" / filename
for runpath in runpaths
]
for statistic in ["Mean", "StdDev", "Min", "Max"]:
Expand Down
16 changes: 8 additions & 8 deletions webviz_subsurface/plugins/_surface_with_grid_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _render_surface(
surfacepath, surface_type, gridparameter, color_values, colorscale
):

surface = xtgeo.RegularSurface(str(get_path(surfacepath)))
surface = xtgeo.RegularSurface(get_path(surfacepath))
hillshading = True
min_val = None
max_val = None
Expand All @@ -345,8 +345,8 @@ def _render_surface(
min_val = color_values[0] if color_values else None
max_val = color_values[1] if color_values else None
color = ListedColormap(colorscale) if colorscale else "viridis"
grid = load_grid(str(get_path(self.gridfile)))
gridparameter = load_grid_parameter(grid, str(get_path(gridparameter)))
grid = load_grid(get_path(self.gridfile))
gridparameter = load_grid_parameter(grid, get_path(gridparameter))
surface.slice_grid3d(grid, gridparameter)
surface.values = surface.values.filled(0)
if min_val is not None:
Expand Down Expand Up @@ -377,14 +377,14 @@ def _render_surface(
def _render_fence(coords, gridparameter, surfacepath, color_values, colorscale):
if not coords:
raise PreventUpdate
grid = load_grid(str(get_path(self.gridfile)))
gridparameter = load_grid_parameter(grid, str(get_path(gridparameter)))
grid = load_grid(get_path(self.gridfile))
gridparameter = load_grid_parameter(grid, get_path(gridparameter))
fence = get_fencespec(coords)
hmin, hmax, vmin, vmax, values = grid.get_randomline(
fence, gridparameter, zincrement=0.5
)

surface = xtgeo.RegularSurface(str(get_path(surfacepath)))
surface = xtgeo.RegularSurface(get_path(surfacepath))
s_arr = get_surface_fence(fence, surface)
return make_heatmap(
values,
Expand Down Expand Up @@ -413,8 +413,8 @@ def _render_fence(coords, gridparameter, surfacepath, color_values, colorscale):
[State(self.ids("gridparameter"), "value")],
)
def _update_color_slider(_clicks, gridparameter):
grid = load_grid(str(get_path(self.gridfile)))
gridparameter = load_grid_parameter(grid, str(get_path(gridparameter)))
grid = load_grid(get_path(self.gridfile))
gridparameter = load_grid_parameter(grid, get_path(gridparameter))

minv = float(f"{gridparameter.values.min():2f}")
maxv = float(f"{gridparameter.values.max():2f}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def _render_surface(
surfacepath, surface_type, cubepath, color_values, colorscale
):

surface = xtgeo.RegularSurface(str(get_path(surfacepath)))
surface = xtgeo.RegularSurface(get_path(surfacepath))
hillshading = True
min_val = None
max_val = None
Expand Down Expand Up @@ -366,7 +366,7 @@ def _render_fence(coords, cubepath, surfacepath, color_values, colorscale):
fence = get_fencespec(coords)
hmin, hmax, vmin, vmax, values = cube.get_randomline(fence)

surface = xtgeo.RegularSurface(str(get_path(surfacepath)))
surface = xtgeo.RegularSurface(get_path(surfacepath))
s_arr = get_surface_fence(fence, surface)
return make_heatmap(
values,
Expand Down
10 changes: 5 additions & 5 deletions webviz_subsurface/plugins/_well_cross_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def set_callbacks(self, app):
)
def _render_section(well, cube, options, sampling, nextend):
"""Update cross section"""
well = load_well(str(get_path(well)))
well = load_well(get_path(well))
xsect = XSectionFigure(
well=well,
zmin=self.zmin,
Expand All @@ -232,7 +232,7 @@ def _render_section(well, cube, options, sampling, nextend):
sampling=int(sampling),
)

surfaces = [load_surface(str(get_path(surf))) for surf in self.surfacefiles]
surfaces = [load_surface(get_path(surf)) for surf in self.surfacefiles]

xsect.plot_surfaces(
surfaces=surfaces,
Expand All @@ -241,7 +241,7 @@ def _render_section(well, cube, options, sampling, nextend):
)

if "show_seismic" in options:
cube = load_cube_data(str(get_path(cube)))
cube = load_cube_data(get_path(cube))
xsect.plot_cube(cube)

xsect.plot_well(
Expand Down Expand Up @@ -279,8 +279,8 @@ def _render_surface(wellfile):
"""Update map"""
wellname = Path(wellfile).stem
wellfile = get_path(wellfile)
surface = load_surface(str(get_path(self.surfacefiles[0])))
well = load_well(str(wellfile))
surface = load_surface(get_path(self.surfacefiles[0]))
well = load_well(wellfile)
s_layer = make_surface_layer(
surface, name=self.surfacenames[0], hillshading=True,
)
Expand Down
14 changes: 7 additions & 7 deletions webviz_subsurface/plugins/_well_cross_section_fmu.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import io
import os
import json
from uuid import uuid4
from pathlib import Path
from typing import List
import io
import json

import numpy as np
import xtgeo
Expand Down Expand Up @@ -422,7 +423,7 @@ def _render_section(
self.surfacefiles[self.surfacenames.index(name)]
for name in surfacenames
]
well = load_well(str(get_path(well)))
well = load_well(get_path(well))
xsect = XSectionFigure(
well=well,
zmin=self.zmin,
Expand All @@ -444,7 +445,7 @@ def _render_section(
)

if "show_seismic" in options:
cube = load_cube_data(str(get_path(cube)))
cube = load_cube_data(get_path(cube))
xsect.plot_cube(cube)

xsect.plot_well(
Expand Down Expand Up @@ -550,10 +551,9 @@ def add_webvizstore(self):
def calculate_surface_statistics(
realdf, ensemble, surfacefile, surfacefolder
) -> io.BytesIO:
real_paths = list(realdf[realdf["ENSEMBLE"] == ensemble]["RUNPATH"])
fns = [
str(Path(Path(real_path) / Path(surfacefolder) / Path(surfacefile)))
for real_path in real_paths
os.path.join(real_path, surfacefolder, surfacefile)
for real_path in list(realdf[realdf["ENSEMBLE"] == ensemble]["RUNPATH"])
]
surfaces = get_surfaces(fns)
return io.BytesIO(
Expand Down

0 comments on commit fafa5d6

Please sign in to comment.