-
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.
Co-Authored-By: Therese Natterøy <[email protected]> Co-Authored-By: Sigurd Pettersen <[email protected]>
- Loading branch information
1 parent
ec067f3
commit 41e642c
Showing
37 changed files
with
4,917 additions
and
2 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
Empty file.
96 changes: 96 additions & 0 deletions
96
webviz_subsurface/_components/deckgl_map/deckgl_map_layers_model.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,96 @@ | ||
import warnings | ||
from enum import Enum | ||
from typing import Dict, List | ||
|
||
from .types.deckgl_props import LayerTypes | ||
|
||
|
||
class DeckGLMapLayersModel: | ||
"""Handles updates to the DeckGLMap layers prop""" | ||
|
||
def __init__(self, layers: List[Dict]) -> None: | ||
self._layers = layers | ||
|
||
def _update_layer_by_type(self, layer_type: Enum, layer_data: Dict) -> None: | ||
"""Update a layer specification by the layer type. If multiple layers are found, | ||
no update is performed.""" | ||
layers = list(filter(lambda x: x["@@type"] == layer_type, self._layers)) | ||
if not layers: | ||
warnings.warn(f"No {layer_type} found in layer specification!") | ||
if len(layers) > 1: | ||
warnings.warn( | ||
f"Multiple layers of type {layer_type} found in layer specification!" | ||
) | ||
if len(layers) == 1: | ||
layer_idx = self._layers.index(layers[0]) | ||
self._layers[layer_idx].update(layer_data) | ||
|
||
def update_layer_by_id(self, layer_id: str, layer_data: Dict) -> None: | ||
"""Update a layer specification by the layer id.""" | ||
layers = list(filter(lambda x: x["id"] == layer_id, self._layers)) | ||
if not layers: | ||
warnings.warn(f"No layer with id {layer_id} found in layer specification!") | ||
if len(layers) > 1: | ||
warnings.warn( | ||
f"Multiple layers with id {layer_id} found in layer specification!" | ||
) | ||
if len(layers) == 1: | ||
layer_idx = self._layers.index(layers[0]) | ||
self._layers[layer_idx].update(layer_data) | ||
|
||
def set_propertymap( | ||
self, | ||
image_url: str, | ||
bounds: List[float], | ||
value_range: List[float], | ||
) -> None: | ||
"""Set the property map image url, bounds and value range in the | ||
Colormap and Hillshading layer""" | ||
self._update_layer_by_type( | ||
layer_type=LayerTypes.HILLSHADING, | ||
layer_data={ | ||
"image": image_url, | ||
"bounds": bounds, | ||
"valueRange": value_range, | ||
}, | ||
) | ||
self._update_layer_by_type( | ||
layer_type=LayerTypes.COLORMAP, | ||
layer_data={ | ||
"image": image_url, | ||
"bounds": bounds, | ||
"valueRange": value_range, | ||
}, | ||
) | ||
|
||
def set_colormap_image(self, colormap: str) -> None: | ||
"""Set the colormap image url in the ColormapLayer""" | ||
self._update_layer_by_type( | ||
layer_type=LayerTypes.COLORMAP, | ||
layer_data={ | ||
"colormap": colormap, | ||
}, | ||
) | ||
|
||
def set_colormap_range(self, colormap_range: List[float]) -> None: | ||
"""Set the colormap range in the ColormapLayer""" | ||
self._update_layer_by_type( | ||
layer_type=LayerTypes.COLORMAP, | ||
layer_data={ | ||
"colorMapRange": colormap_range, | ||
}, | ||
) | ||
|
||
def set_well_data(self, well_data: List[Dict]) -> None: | ||
"""Set the well data json url in the WellsLayer""" | ||
self._update_layer_by_type( | ||
layer_type=LayerTypes.WELL, | ||
layer_data={ | ||
"data": well_data, | ||
}, | ||
) | ||
|
||
@property | ||
def layers(self) -> List[Dict]: | ||
"""Returns the full layers specification""" | ||
return self._layers |
Empty file.
218 changes: 218 additions & 0 deletions
218
webviz_subsurface/_components/deckgl_map/types/deckgl_props.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,218 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
from typing import Any, Dict, List, Optional | ||
|
||
import pydeck | ||
from geojson.feature import FeatureCollection | ||
from pydeck.types import String | ||
from typing_extensions import Literal | ||
|
||
|
||
class LayerTypes(str, Enum): | ||
HILLSHADING = "Hillshading2DLayer" | ||
MAP3D = "Map3DLayer" | ||
COLORMAP = "ColormapLayer" | ||
WELL = "WellsLayer" | ||
DRAWING = "DrawingLayer" | ||
FAULTPOLYGONS = "FaultPolygonsLayer" | ||
|
||
|
||
class LayerIds(str, Enum): | ||
HILLSHADING = "hillshading-layer" | ||
MAP3D = "map3d-layer" | ||
COLORMAP = "colormap-layer" | ||
WELL = "wells-layer" | ||
DRAWING = "drawing-layer" | ||
FAULTPOLYGONS = "fault-polygons-layer" | ||
|
||
|
||
class LayerNames(str, Enum): | ||
HILLSHADING = "Hillshading" | ||
MAP3D = "Map" | ||
COLORMAP = "Colormap" | ||
WELL = "Wells" | ||
DRAWING = "Drawings" | ||
FAULTPOLYGONS = "Fault polygons" | ||
|
||
|
||
@dataclass | ||
class Bounds: | ||
x_min: int = 0 | ||
y_min: int = 0 | ||
x_max: int = 10 | ||
y_max: int = 10 | ||
|
||
|
||
# pylint: disable=too-few-public-methods | ||
class DeckGLMapProps: | ||
"""Default prop settings for DeckGLMap""" | ||
|
||
bounds: List[float] = [0, 0, 10000, 10000] | ||
value_range: List[float] = [0, 1] | ||
image: str = "/surface/UNDEF.png" | ||
color_map_name: str = "Physics" | ||
edited_data: Dict[str, Any] = { | ||
"data": {"type": "FeatureCollection", "features": []}, | ||
"selectedWell": "", | ||
"selectedFeatureIndexes": [], | ||
} | ||
resources: Dict[str, Any] = {} | ||
|
||
|
||
class Hillshading2DLayer(pydeck.Layer): | ||
def __init__( | ||
self, | ||
image: str = DeckGLMapProps.image, | ||
name: str = LayerNames.HILLSHADING, | ||
bounds: List[float] = None, | ||
value_range: List[float] = None, | ||
uuid: Optional[str] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
super().__init__( | ||
type=LayerTypes.HILLSHADING, | ||
id=uuid if uuid is not None else LayerIds.HILLSHADING, | ||
image=String(image), | ||
name=String(name), | ||
bounds=bounds if bounds is not None else DeckGLMapProps.bounds, | ||
valueRange=value_range if value_range is not None else [0, 1], | ||
**kwargs, | ||
) | ||
|
||
|
||
class Map3DLayer(pydeck.Layer): | ||
# pylint: disable=too-many-arguments | ||
def __init__( | ||
self, | ||
mesh: str = DeckGLMapProps.image, | ||
property_texture: str = DeckGLMapProps.image, | ||
color_map_name: str = DeckGLMapProps.color_map_name, | ||
name: str = LayerNames.MAP3D, | ||
bounds: List[float] = None, | ||
mesh_value_range: List[float] = None, | ||
mesh_max_error: int = 5, | ||
property_value_range: List[float] = None, | ||
color_map_range: List[float] = None, | ||
contours: List[float] = None, | ||
rot_deg: float = 0.0, | ||
uuid: Optional[str] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
super().__init__( | ||
type=LayerTypes.MAP3D, | ||
id=uuid if uuid is not None else LayerIds.MAP3D, | ||
mesh=String(mesh), | ||
propertyTexture=String(property_texture), | ||
colorMapName=String(color_map_name), | ||
name=String(name), | ||
bounds=bounds if bounds is not None else DeckGLMapProps.bounds, | ||
meshValueRange=mesh_value_range if mesh_value_range is not None else [0, 1], | ||
propertyValueRange=property_value_range | ||
if property_value_range is not None | ||
else [0, 1], | ||
colorMapRange=color_map_range if color_map_range is not None else [0, 1], | ||
meshMaxError=mesh_max_error, | ||
contours=contours if contours is not None else [0, 100], | ||
rotDeg=rot_deg, | ||
**kwargs, | ||
) | ||
|
||
|
||
class ColormapLayer(pydeck.Layer): | ||
def __init__( | ||
self, | ||
image: str = DeckGLMapProps.image, | ||
color_map_name: str = DeckGLMapProps.color_map_name, | ||
name: str = LayerNames.COLORMAP, | ||
bounds: List[float] = None, | ||
value_range: List[float] = None, | ||
color_map_range: List[float] = None, | ||
uuid: Optional[str] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
super().__init__( | ||
type=LayerTypes.COLORMAP, | ||
id=uuid if uuid is not None else LayerIds.COLORMAP, | ||
image=String(image), | ||
colorMapName=String(color_map_name), | ||
name=String(name), | ||
bounds=bounds if bounds is not None else DeckGLMapProps.bounds, | ||
valueRange=value_range if value_range is not None else [0, 1], | ||
colorMapRange=color_map_range if color_map_range is not None else [0, 1], | ||
**kwargs, | ||
) | ||
|
||
|
||
class WellsLayer(pydeck.Layer): | ||
def __init__( | ||
self, | ||
data: FeatureCollection = None, | ||
name: str = LayerNames.WELL, | ||
uuid: Optional[str] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
super().__init__( | ||
type="GeoJsonLayer", | ||
id=uuid if uuid is not None else LayerIds.WELL, | ||
name=String(name), | ||
data={"type": "FeatureCollection", "features": []} | ||
if data is None | ||
else data, | ||
get_text="properties.attribute", | ||
get_text_size=12, | ||
get_text_anchor=String("start"), | ||
# logData=log_data, | ||
# logrunName=log_run, | ||
# logName=log_name, | ||
# selectedWell=String(selected_well), | ||
pointType=String("circle+text"), | ||
lineWidthMinPixels=2, | ||
pointRadiusMinPixels=2, | ||
pickable=True, | ||
**kwargs, | ||
) | ||
|
||
|
||
class DrawingLayer(pydeck.Layer): | ||
def __init__( | ||
self, | ||
mode: Literal[ # Use Enum? | ||
"view", "modify", "transform", "drawPoint", "drawLineString", "drawPolygon" | ||
] = "view", | ||
uuid: Optional[str] = None, | ||
**kwargs: Any, | ||
): | ||
super().__init__( | ||
type=LayerTypes.DRAWING, | ||
id=uuid if uuid is not None else LayerIds.DRAWING, | ||
name=LayerNames.DRAWING, | ||
mode=String(mode), | ||
**kwargs, | ||
) | ||
|
||
|
||
class FaultPolygonsLayer(pydeck.Layer): | ||
def __init__( | ||
self, | ||
data: FeatureCollection = None, | ||
name: str = LayerNames.FAULTPOLYGONS, | ||
uuid: Optional[str] = None, | ||
**kwargs: Any, | ||
) -> None: | ||
super().__init__( | ||
type=LayerTypes.FAULTPOLYGONS, | ||
id=uuid if uuid is not None else LayerIds.FAULTPOLYGONS, | ||
name=String(name), | ||
data={ | ||
"type": "FeatureCollection", | ||
"features": [], | ||
} | ||
if data is None | ||
else data, | ||
**kwargs, | ||
) | ||
|
||
|
||
class CustomLayer(pydeck.Layer): | ||
def __init__(self, layer_type: str, uuid: str, name: str, **kwargs: Any) -> None: | ||
super().__init__(type=layer_type, id=String(uuid), name=String(name), **kwargs) |
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
8 changes: 8 additions & 0 deletions
8
webviz_subsurface/_providers/ensemble_fault_polygons_provider/__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,8 @@ | ||
from .ensemble_fault_polygons_provider import ( | ||
EnsembleFaultPolygonsProvider, | ||
SimulatedFaultPolygonsAddress, | ||
) | ||
from .ensemble_fault_polygons_provider_factory import ( | ||
EnsembleFaultPolygonsProviderFactory, | ||
) | ||
from .fault_polygons_server import FaultPolygonsAddress, FaultPolygonsServer |
Oops, something went wrong.