From 3dccd5510d8e1bd37130a163f20630f2d613c3f1 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Sat, 30 Sep 2023 08:06:52 -0600 Subject: [PATCH] FIX: Make matplotlib an optional import Only import it when needed in the plotting routines. It shouldn't be a hard dependency, but when one would `import bezpy` before it would be required because of the imports being in general modules. --- bezpy/__init__.py | 15 +-------------- bezpy/__version__.py | 2 -- bezpy/mt/__init__.py | 1 - bezpy/mt/site.py | 8 ++++++-- 4 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 bezpy/__version__.py diff --git a/bezpy/__init__.py b/bezpy/__init__.py index 491dd09..217d9c5 100644 --- a/bezpy/__init__.py +++ b/bezpy/__init__.py @@ -6,17 +6,4 @@ from . import tl from . import mag -# Let users know if they're missing any of our hard dependencies -HARD_DEPENDENCIES = ("numpy", "pandas", "scipy", "shapely") -MISSING_DEPENDENCIES = [] - -for dependency in HARD_DEPENDENCIES: - try: - __import__(dependency) - except ImportError: - MISSING_DEPENDENCIES.append(dependency) - -if MISSING_DEPENDENCIES: - raise ImportError( - "Missing required dependencies {0}".format(MISSING_DEPENDENCIES)) -del HARD_DEPENDENCIES, MISSING_DEPENDENCIES, dependency +__version__ = '0.1.0' diff --git a/bezpy/__version__.py b/bezpy/__version__.py deleted file mode 100644 index a021f3e..0000000 --- a/bezpy/__version__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""Current bezpy version.""" -__version__ = '0.0.2' diff --git a/bezpy/mt/__init__.py b/bezpy/mt/__init__.py index dc4c925..521c54d 100644 --- a/bezpy/mt/__init__.py +++ b/bezpy/mt/__init__.py @@ -3,4 +3,3 @@ from .impulse import * from .utils import * from .io import * -from .plotting import * diff --git a/bezpy/mt/site.py b/bezpy/mt/site.py index 2e3f4ec..982b539 100644 --- a/bezpy/mt/site.py +++ b/bezpy/mt/site.py @@ -7,10 +7,8 @@ import numpy as np import pandas as pd import scipy.interpolate -import matplotlib.pyplot as plt from .utils import apparent_resistivity -from .plotting import plot_apparent_resistivity # ---------------------------- # Constants @@ -184,6 +182,8 @@ def spline_interp(self, freqs, logspace=True, extrapolate=1, def plot_apparent_resistivity(self, interp_freqs=None): """Plot the apparent resistivity and phase of the transfer function.""" + # lazy-load this so we don't require matplotlib to be installed by default + from .plotting import plot_apparent_resistivity xlim = [10**np.floor(np.log10(np.min(self.periods))), 10**np.ceil(np.log10(np.max(self.periods)))] fig, ax_res, ax_phase = plot_apparent_resistivity(self.periods, self.Z, self.Z_var, @@ -262,6 +262,8 @@ def _repr_html_(self): def plot_depth(self, ax=None): """Plots the resistivity vs. depth profile.""" + # lazy-load this so we don't require matplotlib to be installed by default + import matplotlib.pyplot as plt if ax is None: _, ax = plt.subplots() ax.step(self.resistivities, np.insert(self.depths, 0, 0)/1000., label=self.name) @@ -313,6 +315,8 @@ def calcZ(self, freqs): def plot_apparent_resistivity(self, interp_freqs=None): """Plots the apparent resistivity and phase for the site.""" + # lazy-load this so we don't require matplotlib to be installed by default + from .plotting import plot_apparent_resistivity if interp_freqs is None: raise ValueError("Need interpolation frequencies to plot the resistivity at.")