From c8b268deace8b5583cb330918673c6cb84486682 Mon Sep 17 00:00:00 2001 From: mferrera Date: Wed, 13 Dec 2023 07:44:11 +0100 Subject: [PATCH] CLN: Use xtgeoviz for quickplots --- pyproject.toml | 1 + src/xtgeo/__init__.py | 8 ++++++-- src/xtgeo/grid3d/_roff_grid.py | 2 +- src/xtgeo/surface/regular_surface.py | 4 ++-- src/xtgeo/well/wells.py | 4 ++-- src/xtgeo/xyz/polygons.py | 4 ++-- tests/test_plot/test_matplotlib_import.py | 1 + 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fba7468ae..786dd5eff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,6 +62,7 @@ dependencies = [ "tables;platform_system != 'Darwin' and python_version > '3.8'", # TODO: mac... "tables<3.9;platform_system != 'Darwin' and python_version == '3.8'", # TODO: mac... "typing_extensions", + "xtgeoviz", ] [project.urls] diff --git a/src/xtgeo/__init__.py b/src/xtgeo/__init__.py index 47cf212d8..cda3a5eb2 100644 --- a/src/xtgeo/__init__.py +++ b/src/xtgeo/__init__.py @@ -5,6 +5,7 @@ import os +import sys import timeit import warnings @@ -38,10 +39,10 @@ def _xprint(msg): ROXAR = True try: import roxar -except Exception: +except ImportError: ROXAR = False -if not ROXAR: +if sys.platform == "linux" and not ROXAR: _display = os.environ.get("DISPLAY", "") _hostname = os.environ.get("HOSTNAME", "") _host = os.environ.get("HOST", "") @@ -169,3 +170,6 @@ def _xprint(msg): warnings.filterwarnings("default", category=DeprecationWarning, module="xtgeo") _xprint("XTGEO __init__ done") + +# Remove symbols imported for internal use +del os, sys, timeit, warnings, TIME0, DEBUG, ROXAR, _timer, _xprint diff --git a/src/xtgeo/grid3d/_roff_grid.py b/src/xtgeo/grid3d/_roff_grid.py index 4a2e3c5ad..b0a9ce4fc 100644 --- a/src/xtgeo/grid3d/_roff_grid.py +++ b/src/xtgeo/grid3d/_roff_grid.py @@ -308,7 +308,7 @@ def xtgeo_subgrids(self) -> dict[str, range] | None: @staticmethod def _from_xtgeo_subgrids( - xtgeo_subgrids: MutableMapping[str, range | Sequence] + xtgeo_subgrids: MutableMapping[str, range | Sequence], ) -> np.ndarray: """ Args: diff --git a/src/xtgeo/surface/regular_surface.py b/src/xtgeo/surface/regular_surface.py index d6befb7b5..8ee089a3c 100644 --- a/src/xtgeo/surface/regular_surface.py +++ b/src/xtgeo/surface/regular_surface.py @@ -3046,9 +3046,9 @@ def quickplot( xtg.warn(f"None or too few map nodes for plotting. Skip output {filename}!") return - import xtgeo.plot + import xtgeoviz.plot - mymap = xtgeo.plot.Map() + mymap = xtgeoviz.plot.Map() logger.info("Infotext is <%s>", infotext) mymap.canvas(title=title, subtitle=subtitle, infotext=infotext) diff --git a/src/xtgeo/well/wells.py b/src/xtgeo/well/wells.py index 41a1668c0..4eff9cd17 100644 --- a/src/xtgeo/well/wells.py +++ b/src/xtgeo/well/wells.py @@ -222,9 +222,9 @@ def quickplot(self, filename=None, title="QuickPlot"): title (str): Title of plot """ - import xtgeo.plot + import xtgeoviz.plot - mymap = xtgeo.plot.Map() + mymap = xtgeoviz.plot.Map() mymap.canvas(title=title) diff --git a/src/xtgeo/xyz/polygons.py b/src/xtgeo/xyz/polygons.py index 8327708fc..a9e1e4204 100644 --- a/src/xtgeo/xyz/polygons.py +++ b/src/xtgeo/xyz/polygons.py @@ -860,9 +860,9 @@ def quickplot( linewidth (float): Width of line. color (str): Name of color (may use matplotib shortcuts, e.g. 'r' for 'red') """ - import xtgeo.plot + import xtgeoviz.plot - mymap = xtgeo.plot.Map() + mymap = xtgeoviz.plot.Map() mymap.canvas(title=title, subtitle=subtitle, infotext=infotext) if others: diff --git a/tests/test_plot/test_matplotlib_import.py b/tests/test_plot/test_matplotlib_import.py index 692c11ad7..82f7ededd 100644 --- a/tests/test_plot/test_matplotlib_import.py +++ b/tests/test_plot/test_matplotlib_import.py @@ -50,6 +50,7 @@ def test_that_mpl_dynamically_imports(): assert "matplotlib.pyplot" in sys.modules +@mock.patch.object(sys, "platform", "linux") @mock.patch.dict(sys.modules) @mock.patch.dict(os.environ, {"LSB_JOBID": "1"}) def test_that_agg_backend_set_when_lsf_job():