Skip to content

Commit ca5443c

Browse files
committed
fix: lazy import scipy and matplotlib
1 parent cf98f4e commit ca5443c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

tidy3d/components/medium.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import numpy as npo
1616
import pydantic.v1 as pd
1717
import xarray as xr
18-
from scipy import signal
1918

2019
from tidy3d.components.material.tcad.heat import ThermalSpecType
2120

@@ -3482,6 +3481,11 @@ def _real_partial_fraction_decomposition(
34823481
34833482
"""
34843483

3484+
try:
3485+
from scipy import signal
3486+
except ImportError:
3487+
raise ImportError("scipy is required to use this method.")
3488+
34853489
if a.ndim != 1 or np.any(np.iscomplex(a)):
34863490
raise ValidationError(
34873491
"Numerator coefficients must be a one-dimensional array of real numbers."

tidy3d/components/mode/mode_solver.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import numpy as np
1212
import pydantic.v1 as pydantic
1313
import xarray as xr
14-
from matplotlib.collections import PatchCollection
15-
from matplotlib.patches import Rectangle
1614

1715
from ...constants import C_0
1816
from ...exceptions import SetupError, ValidationError
@@ -2315,6 +2313,13 @@ def _plot_pml(
23152313
cls, simulation: Simulation, plane: Box, mode_spec: ModeSpec, ax: Ax = None
23162314
) -> Ax:
23172315
"""Plot the mode plane absorbing boundaries."""
2316+
2317+
try:
2318+
from matplotlib.collections import PatchCollection
2319+
from matplotlib.patches import Rectangle
2320+
except ImportError:
2321+
raise ImportError("matplotlib is required to plot the mode plane absorbing boundaries.")
2322+
23182323
# Get the mode plane normal axis, center, and limits.
23192324
_, h_lim, v_lim, _ = cls._center_and_lims(simulation=simulation, plane=plane)
23202325

0 commit comments

Comments
 (0)