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

Fix linting #49

Merged
merged 8 commits into from
Feb 10, 2025
Merged
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
Expand Up @@ -8,6 +8,7 @@

from webviz_subsurface._utils.enum_shim import StrEnum
from webviz_subsurface._utils.perf_timer import PerfTimer

from ._polygon_discovery import PolygonsFileInfo
from .ensemble_polygon_provider import (
EnsemblePolygonProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ def _handle_polygons_request(

def _create_polygons_geojson(polygons: xtgeo.Polygons) -> Dict:
feature_arr = []
prop_style = dict(color=[0, 0, 0, 255])
prop_style = {"color": [0, 0, 0, 255]}
for name, polygon in polygons.dataframe.groupby("POLY_ID"):
coords = [list(zip(polygon.X_UTME, polygon.Y_UTMN))]
feature = geojson.Feature(
geometry=geojson.Polygon(coords),
properties=dict(name=f"id:{name}", **prop_style),
properties={"name": f"id:{name}", **prop_style},
)
feature_arr.append(feature)
return geojson.FeatureCollection(features=feature_arr)
10 changes: 5 additions & 5 deletions webviz_subsurface/plugins/_co2_leakage/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from webviz_config.utils import StrEnum, callback_typecheck

from webviz_subsurface._providers import FaultPolygonsServer, SurfaceImageServer
from webviz_subsurface._providers.ensemble_polygon_provider import PolygonServer
from webviz_subsurface.plugins._co2_leakage._utilities.callbacks import (
SurfaceData,
create_map_annotations,
Expand All @@ -29,31 +30,30 @@
FaultPolygonsHandler,
)
from webviz_subsurface.plugins._co2_leakage._utilities.generic import (
BoundarySettings,
Co2MassScale,
Co2VolumeScale,
GraphSource,
MapAttribute,
MapThresholds,
MapType,
BoundarySettings,
)
from webviz_subsurface.plugins._co2_leakage._utilities.initialization import (
init_containment_data_providers,
init_dictionary_of_content,
init_map_attribute_names,
init_menu_options,
init_polygon_provider_handlers,
init_realizations,
init_surface_providers,
init_unsmry_data_providers,
init_well_pick_provider,
init_polygon_provider_handlers,
)
from webviz_subsurface.plugins._co2_leakage.views.mainview.mainview import (
MainView,
MapViewElement,
)
from webviz_subsurface.plugins._co2_leakage.views.mainview.settings import ViewSettings
from webviz_subsurface._providers.ensemble_polygon_provider import PolygonServer

from . import _error
from ._utilities.color_tables import co2leakage_color_tables
Expand All @@ -69,8 +69,6 @@ class CO2Leakage(WebvizPluginABC):
ensemble

* **`ensembles`:** Which ensembles in `shared_settings` to visualize.
* **`file_containment_boundary`:** Path to a polygon representing the containment area
* **`file_hazardous_boundary`:** Path to a polygon representing the hazardous area
* **`well_pick_file`:** Path to a file containing well picks
* **`plume_mass_relpath`:** Path to a table of co2 containment data (amount of
CO2 outside/inside a boundary), for co2 mass. Relative to each realization.
Expand All @@ -89,6 +87,8 @@ class CO2Leakage(WebvizPluginABC):
names and surface names used in the well pick file
* **`map_surface_names_to_fault_polygons`:** Optional mapping between surface map
names and surface names used by the fault polygons
* **`boundary_settings`:** Settings (paths etc) for polygons representing the
containment and hazardous areas
"""

class Ids(StrEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,6 @@ def plume_sort_key(name: str) -> int:

plume_groups = sorted(plume_groups, key=plume_sort_key)

containments = ["hazardous", "outside", "contained"]
phases = [phase for phase in menu_options["phases"] if phase != "total"]
if "zone" in [mark_choice, color_choice]:
region = "all"
if "region" in [mark_choice, color_choice]:
Expand All @@ -515,8 +513,8 @@ def plume_sort_key(name: str) -> int:
"color_choice": color_choice,
"mark_choice": mark_choice,
"sorting": sorting,
"phases": phases,
"containments": containments,
"phases": [phase for phase in menu_options["phases"] if phase != "total"],
"containments": ["hazardous", "outside", "contained"],
"plume_groups": plume_groups,
"use_stats": lines_to_show == "stat",
"date_option": date_option,
Expand Down
23 changes: 11 additions & 12 deletions webviz_subsurface/plugins/_co2_leakage/_utilities/co2volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _adjust_figure(fig: go.Figure, plot_title: Optional[str] = None) -> None:
fig.layout.legend.itemwidth = 40
fig.layout.xaxis.exponentformat = "power"
if plot_title is not None:
fig.layout.title = plot_title
fig.layout.title.text = plot_title
fig.layout.title.font = {"size": 14}
fig.layout.margin.t = 40
fig.layout.title.y = 0.95
Expand Down Expand Up @@ -634,13 +634,15 @@ def _connect_plume_groups(
color_choice: str,
mark_choice: str,
) -> None:
cols = ["realization"]
col_list = ["realization"]
if color_choice == "plume_group" and mark_choice != "none":
cols.append(mark_choice)
col_list.append(mark_choice)
elif mark_choice == "plume_group":
cols.append(color_choice)
if len(cols) == 1:
cols = cols[0]
col_list.append(color_choice)

cols: Union[List[str], str] = col_list
if len(col_list) == 1:
cols = col_list[0]
# Find points where plumes start or end, to connect the lines
end_points = []
start_points = []
Expand Down Expand Up @@ -691,12 +693,10 @@ def _connect_plume_groups(
if row1.equals(row2):
row_to_change = df.eq(end_point).all(axis=1)
if sum(row_to_change) == 1:
df.loc[row_to_change == True, "amount"] = start_point["amount"]
df.loc[row_to_change, "amount"] = start_point["amount"]
df["is_merged"] = ["+" in x for x in df["plume_group"].values]
df.loc[
(df["plume_group"] != "all")
& (df["is_merged"] == True)
& (df["amount"] == 0.0),
(df["plume_group"] != "all") & (df["is_merged"]) & (df["amount"] == 0.0),
"amount",
] = np.nan
df.drop(columns="is_merged", inplace=True)
Expand All @@ -722,7 +722,7 @@ def generate_co2_time_containment_figure(
if "plume_group" in df:
try:
_connect_plume_groups(df, color_choice, mark_choice)
except Exception:
except ValueError:
pass

fig = go.Figure()
Expand Down Expand Up @@ -812,7 +812,6 @@ def generate_co2_time_containment_figure(
return fig


# pylint: disable=too-many-locals
def generate_co2_statistics_figure(
table_provider: ContainmentDataProvider,
realizations: List[int],
Expand Down
9 changes: 8 additions & 1 deletion webviz_subsurface/plugins/_co2_leakage/_utilities/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ class MapGroup(StrEnum):
TRAPPED_GAS = "CO2 MASS"


map_group_labels = {"SGAS": "Gas phase", "AMFG": "Dissolved phase", "XMF2": "Dissolved phase", "SGSTRAND": "Trapped gas phase", "SGTRH": "Trapped gas phase", "CO2 MASS": "CO2 mass"}
map_group_labels = {
"SGAS": "Gas phase",
"AMFG": "Dissolved phase",
"XMF2": "Dissolved phase",
"SGSTRAND": "Trapped gas phase",
"SGTRH": "Trapped gas phase",
"CO2 MASS": "CO2 mass",
}


class MapType(StrEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
EnsembleWellPicks,
)
from webviz_subsurface.plugins._co2_leakage._utilities.generic import (
BoundarySettings,
FilteredMapAttribute,
GraphSource,
MapAttribute,
MapNamingConvention,
MenuOptions,
BoundarySettings,
)
from webviz_subsurface.plugins._co2_leakage._utilities.polygon_handler import (
PolygonHandler,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import List, Optional

from webviz_subsurface._providers.ensemble_polygon_provider import (
PolygonServer,
EnsemblePolygonProviderFactory,
PolygonServer,
)
from webviz_subsurface._providers.ensemble_polygon_provider.ensemble_polygon_provider import (
PolygonsAddress,
Expand All @@ -29,10 +29,14 @@ def __init__(
server.add_provider(self._provider)

def extract_hazardous_poly_url(self, realization: List[int]) -> Optional[str]:
return self._extract_polygon_url(self._hazardous_name, self._attribute, realization)
return self._extract_polygon_url(
self._hazardous_name, self._attribute, realization
)

def extract_containment_poly_url(self, realization: List[int]) -> Optional[str]:
return self._extract_polygon_url(self._containment_name, self._attribute, realization)
return self._extract_polygon_url(
self._containment_name, self._attribute, realization
)

def _extract_polygon_url(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def menu_options(self) -> MenuOptions:
"regions": [],
"phases": ["total", "gas", "dissolved"],
"plume_groups": [],
"dates": [],
}

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
LayoutStyle,
MapAttribute,
MapGroup,
map_group_labels,
MapThresholds,
MapType,
MenuOptions,
map_group_labels,
)


Expand Down Expand Up @@ -1254,7 +1254,8 @@ def _compile_property_options(
map_attribute_names: FilteredMapAttribute,
) -> List[Dict[str, Any]]:
requested_map_groups = [
map_group_labels[MapGroup[key.name].value] for key in map_attribute_names.filtered_values.keys()
map_group_labels[MapGroup[key.name].value]
for key in map_attribute_names.filtered_values.keys()
]
unique_requested_map_groups = list(set(requested_map_groups))
return [
Expand Down
Loading