Skip to content

Commit

Permalink
FIX: Make matplotlib an optional import
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greglucas committed Sep 30, 2023
1 parent 53f5d93 commit 3dccd55
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
15 changes: 1 addition & 14 deletions bezpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 0 additions & 2 deletions bezpy/__version__.py

This file was deleted.

1 change: 0 additions & 1 deletion bezpy/mt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
from .impulse import *
from .utils import *
from .io import *
from .plotting import *
8 changes: 6 additions & 2 deletions bezpy/mt/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.")

Expand Down

0 comments on commit 3dccd55

Please sign in to comment.