Skip to content

Commit ddfb939

Browse files
committed
Split lazy signals into their modules to defer dask import when importing non lazy signals
1 parent 2f50b20 commit ddfb939

11 files changed

+140
-40
lines changed

hyperspy/_signals/complex_signal.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
PLOT2D_KWARGS_DOCSTRING,
3030
)
3131
from hyperspy.docstrings.signal import (
32-
LAZYSIGNAL_DOC,
3332
NUM_WORKERS_ARG,
3433
SHOW_PROGRESSBAR_ARG,
3534
)
@@ -420,9 +419,3 @@ def argand_diagram(self, size=[256, 256], range=None):
420419
argand_diagram.axes_manager.signal_axes[1].units = units_imag
421420

422421
return argand_diagram
423-
424-
425-
class LazyComplexSignal(ComplexSignal, signals.LazySignal):
426-
"""Lazy general signal class for complex data."""
427-
428-
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "ComplexSignal")

hyperspy/_signals/complex_signal1d.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
from hyperspy import signals
2121
from hyperspy._signals.common_signal1d import CommonSignal1D
22-
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
2322

2423

2524
class ComplexSignal1D(signals.ComplexSignal, CommonSignal1D):
@@ -29,9 +28,3 @@ class ComplexSignal1D(signals.ComplexSignal, CommonSignal1D):
2928

3029
def __init__(self, *args, **kwargs):
3130
super().__init__(*args, **kwargs)
32-
33-
34-
class LazyComplexSignal1D(ComplexSignal1D, signals.LazyComplexSignal):
35-
"""Lazy signal class for complex 1-dimensional data."""
36-
37-
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "ComplexSignal1D")

hyperspy/_signals/complex_signal2d.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
PLOT2D_DOCSTRING,
2626
PLOT2D_KWARGS_DOCSTRING,
2727
)
28-
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
2928

3029

3130
class ComplexSignal2D(signals.ComplexSignal, CommonSignal2D):
@@ -121,9 +120,3 @@ def plot(
121120
PLOT2D_DOCSTRING,
122121
PLOT2D_KWARGS_DOCSTRING,
123122
)
124-
125-
126-
class LazyComplexSignal2D(ComplexSignal2D, signals.LazyComplexSignal):
127-
"""Lazy Signal class for complex 2-dimensional data."""
128-
129-
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "ComplexSignal2D")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2007-2025 The HyperSpy developers
3+
#
4+
# This file is part of HyperSpy.
5+
#
6+
# HyperSpy is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# HyperSpy is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with HyperSpy. If not, see <https://www.gnu.org/licenses/#GPL>.
18+
19+
from hyperspy import signals
20+
from hyperspy._signals.complex_signal import ComplexSignal
21+
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
22+
23+
24+
class LazyComplexSignal(ComplexSignal, signals.LazySignal):
25+
"""Lazy general signal class for complex data."""
26+
27+
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "ComplexSignal")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2007-2025 The HyperSpy developers
3+
#
4+
# This file is part of HyperSpy.
5+
#
6+
# HyperSpy is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# HyperSpy is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with HyperSpy. If not, see <https://www.gnu.org/licenses/#GPL>.
18+
19+
from hyperspy import signals
20+
from hyperspy._signals.complex_signal1d import ComplexSignal1D
21+
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
22+
23+
24+
class LazyComplexSignal1D(ComplexSignal1D, signals.LazyComplexSignal):
25+
"""Lazy signal class for complex 1-dimensional data."""
26+
27+
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "ComplexSignal1D")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2007-2025 The HyperSpy developers
3+
#
4+
# This file is part of HyperSpy.
5+
#
6+
# HyperSpy is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# HyperSpy is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with HyperSpy. If not, see <https://www.gnu.org/licenses/#GPL>.
18+
19+
from hyperspy import signals
20+
from hyperspy._signals.complex_signal2d import ComplexSignal2D
21+
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
22+
23+
24+
class LazyComplexSignal2D(ComplexSignal2D, signals.LazyComplexSignal):
25+
"""Lazy Signal class for complex 2-dimensional data."""
26+
27+
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "ComplexSignal2D")

hyperspy/_signals/lazy_signal1d.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2007-2025 The HyperSpy developers
3+
#
4+
# This file is part of HyperSpy.
5+
#
6+
# HyperSpy is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# HyperSpy is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with HyperSpy. If not, see <https://www.gnu.org/licenses/#GPL>.
18+
19+
from hyperspy import signals
20+
from hyperspy._signals.signal1d import Signal1D
21+
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
22+
23+
24+
class LazySignal1D(signals.LazySignal, Signal1D):
25+
"""Lazy general 1D signal class."""
26+
27+
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "Signal1D")

hyperspy/_signals/lazy_signal2d.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2007-2025 The HyperSpy developers
3+
#
4+
# This file is part of HyperSpy.
5+
#
6+
# HyperSpy is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# HyperSpy is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with HyperSpy. If not, see <https://www.gnu.org/licenses/#GPL>.
18+
19+
from hyperspy import signals
20+
from hyperspy._signals.signal2d import Signal2D
21+
from hyperspy.docstrings.signal import LAZYSIGNAL_DOC
22+
23+
24+
class LazySignal2D(signals.LazySignal, Signal2D):
25+
"""Lazy general 2D signal class."""
26+
27+
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "Signal2D")

hyperspy/_signals/signal1d.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
)
3636
from hyperspy.docstrings.signal import (
3737
IN_PLACE,
38-
LAZYSIGNAL_DOC,
3938
NAVIGATION_MASK_ARG,
4039
NUM_WORKERS_ARG,
4140
SHOW_PROGRESSBAR_ARG,
@@ -1757,9 +1756,3 @@ def plot(
17571756
BASE_PLOT_DOCSTRING_PARAMETERS,
17581757
PLOT1D_DOCSTRING,
17591758
)
1760-
1761-
1762-
class LazySignal1D(signals.LazySignal, Signal1D):
1763-
"""Lazy general 1D signal class."""
1764-
1765-
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "Signal1D")

hyperspy/_signals/signal2d.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
PLOT2D_KWARGS_DOCSTRING,
3636
)
3737
from hyperspy.docstrings.signal import (
38-
LAZYSIGNAL_DOC,
3938
NUM_WORKERS_ARG,
4039
SHOW_PROGRESSBAR_ARG,
4140
)
@@ -1118,9 +1117,3 @@ def find_peaks(
11181117
DISPLAY_DT,
11191118
TOOLKIT_DT,
11201119
)
1121-
1122-
1123-
class LazySignal2D(signals.LazySignal, Signal2D):
1124-
"""Lazy general 2D signal class."""
1125-
1126-
__doc__ += LAZYSIGNAL_DOC.replace("__BASECLASS__", "Signal2D")

0 commit comments

Comments
 (0)