From f4b87ca88f4e8d2eea227ea4c33236af396e84a3 Mon Sep 17 00:00:00 2001 From: Yannick Augenstein Date: Mon, 8 Jul 2024 14:42:34 +0200 Subject: [PATCH] Lazily load `scipy.io` in `SimulationData.to_mat_file()` to speed up overall module import time --- tidy3d/components/data/sim_data.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tidy3d/components/data/sim_data.py b/tidy3d/components/data/sim_data.py index 9f6f730e2..f0107b4dd 100644 --- a/tidy3d/components/data/sim_data.py +++ b/tidy3d/components/data/sim_data.py @@ -12,7 +12,6 @@ import numpy as np import pydantic.v1 as pd import xarray as xr -from scipy.io import savemat from ...exceptions import DataError, FileError, Tidy3dKeyError from ...log import log @@ -1041,6 +1040,8 @@ def to_mat_file(self, fname: str, **kwargs): modified_sim_dict = replace_values(sim_dict, None, []) try: + from scipy.io import savemat + savemat(fname, modified_sim_dict, **kwargs) except Exception as e: raise ValueError(