pyxem / kikuchipy

Toolbox for analysis of electron backscatter diffraction (EBSD) patterns
https://kikuchipy.org
GNU General Public License v3.0
81 stars 29 forks source link

kikuchipy v0.10.0 incompatible with SciPy > 1.13 #687

Closed Fred-Ad closed 1 week ago

Fred-Ad commented 1 month ago

In a new enviroonment I have : Kikuchipy 0.10.0, Python 3.12.6, Hyperspy 1.7.6

When loading a master pattern generated by EMsoft,

import kikuchipy as kp
mp = kp.load('MCoutput.h5')

I have this error :

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[3], [line 1](vscode-notebook-cell:?execution_count=3&line=1)
----> [1](vscode-notebook-cell:?execution_count=3&line=1) mp = kp.load('MCoutput.h5')

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\kikuchipy\io\_io.py:148, in load(filename, lazy, **kwargs)
    [146](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:146) out = []
    [147](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:147) for signal in signal_dicts:
--> [148](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:148)     out.append(_dict2signal(signal, lazy=lazy))
    [149](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:149)     directory, filename = os.path.split(os.path.abspath(filename))
    [150](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:150)     filename, extension = os.path.splitext(filename)

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\kikuchipy\io\_io.py:195, in _dict2signal(signal_dict, lazy)
    [192](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:192)     if "Signal" in md and "signal_type" in md["Signal"]:
    [193](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:193)         signal_type = md["Signal"]["signal_type"]
--> [195](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:195) signal = _assign_signal_subclass(
    [196](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:196)     signal_dimension=2,
    [197](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:197)     signal_type=signal_type,
    [198](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:198)     dtype=signal_dict["data"].dtype,
    [199](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:199)     lazy=lazy,
    [200](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:200) )(**signal_dict)
    [202](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:202) if signal._lazy:
    [203](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:203)     signal._make_lazy()

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\kikuchipy\io\_io.py:337, in _assign_signal_subclass(dtype, signal_dimension, signal_type, lazy)
    [330](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:330)     raise ValueError(
    [331](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:331)         f"Signal dimension must be a positive integer and not '{signal_dimension}'"
    [332](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:332)     )
    [334](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:334) # Get possible signal classes
    [335](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:335) signals = {
    [336](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:336)     key: value
--> [337](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:337)     for key, value in find_subclasses(kikuchipy.signals, BaseSignal).items()
    [338](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:338)     if value._lazy == lazy
    [339](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:339) }
    [341](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:341) # Get signals matching both input signal's dtype and signal dimension
    [342](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/io/_io.py:342) dtype_matches = [s for s in signals.values() if s._dtype == dtype]

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\hyperspy\misc\utils.py:949, in find_subclasses(mod, cls)
    [933](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:933) def find_subclasses(mod, cls):
    [934](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:934)     """Find all the subclasses in a module.
    [935](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:935) 
    [936](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:936)     Parameters
   (...)
    [944](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:944) 
    [945](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:945)     """
    [946](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:946)     return dict(
    [947](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:947)         [
    [948](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:948)             (name, obj)
--> [949](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:949)             for name, obj in inspect.getmembers(mod)
    [950](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:950)             if inspect.isclass(obj) and issubclass(obj, cls)
    [951](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:951)         ]
    [952](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/misc/utils.py:952)     )

File d:\Windows\mambaforge\envs\kp12\Lib\inspect.py:614, in getmembers(object, predicate)
    [611](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:611) def getmembers(object, predicate=None):
    [612](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:612)     """Return all members of an object as (name, value) pairs sorted by name.
    [613](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:613)     Optionally, only return members that satisfy a given predicate."""
--> [614](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:614)     return _getmembers(object, predicate, getattr)

File d:\Windows\mambaforge\envs\kp12\Lib\inspect.py:592, in _getmembers(object, predicate, getter)
    [587](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:587) for key in names:
    [588](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:588)     # First try to get the value via getattr.  Some descriptors don't
    [589](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:589)     # like calling their __get__ (see bug #1785), so fall back to
    [590](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:590)     # looking in the __dict__.
    [591](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:591)     try:
--> [592](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:592)         value = getter(object, key)
    [593](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:593)         # handle the duplicate key
    [594](file:///D:/Windows/mambaforge/envs/kp12/Lib/inspect.py:594)         if key in processed:

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\kikuchipy\signals\__init__.py:65, in __getattr__(name)
     [63](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/__init__.py:63) if name in _import_mapping.keys():
     [64](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/__init__.py:64)     import_path = f"{__name__}.{_import_mapping.get(name)}"
---> [65](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/__init__.py:65)     return getattr(importlib.import_module(import_path), name)
     [66](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/__init__.py:66) else:  # pragma: no cover
     [67](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/__init__.py:67)     return importlib.import_module("." + name, __name__)

File d:\Windows\mambaforge\envs\kp12\Lib\importlib\__init__.py:90, in import_module(name, package)
     [88](file:///D:/Windows/mambaforge/envs/kp12/Lib/importlib/__init__.py:88)             break
     [89](file:///D:/Windows/mambaforge/envs/kp12/Lib/importlib/__init__.py:89)         level += 1
---> [90](file:///D:/Windows/mambaforge/envs/kp12/Lib/importlib/__init__.py:90) return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1387, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1360, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1331, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:935, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:995, in exec_module(self, module)

File <frozen importlib._bootstrap>:488, in _call_with_frames_removed(f, *args, **kwds)

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\kikuchipy\signals\ebsd.py:77
     [66](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:66) from kikuchipy.pattern._pattern import (
     [67](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:67)     _downsample2d,
     [68](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:68)     _dynamic_background_frequency_space_setup,
   (...)
     [74](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:74)     fft_frequency_vectors,
     [75](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:75) )
     [76](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:76) from kikuchipy.pattern.chunk import _average_neighbour_patterns
---> [77](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:77) from kikuchipy.signals._kikuchipy_signal import KikuchipySignal2D, LazyKikuchipySignal2D
     [78](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:78) from kikuchipy.signals.util._crystal_map import (
     [79](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:79)     _equal_phase,
     [80](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:80)     _get_indexed_points_in_data_in_xmap,
     [81](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:81)     _xmap_is_compatible_with_signal,
     [82](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:82) )
     [83](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:83) from kikuchipy.signals.util._dask import (
     [84](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:84)     _get_chunk_overlap_depth,
     [85](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:85)     _rechunk_learning_results,
   (...)
     [88](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:88)     get_dask_array,
     [89](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/ebsd.py:89) )

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\kikuchipy\signals\_kikuchipy_signal.py:27
     [24](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/_kikuchipy_signal.py:24) import warnings
     [26](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/_kikuchipy_signal.py:26) import dask.array as da
---> [27](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/_kikuchipy_signal.py:27) from hyperspy._lazy_signals import LazySignal2D
     [28](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/_kikuchipy_signal.py:28) from hyperspy.misc.rgb_tools import rgb_dtypes
     [29](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/kikuchipy/signals/_kikuchipy_signal.py:29) from hyperspy.signals import Signal2D

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\hyperspy\_lazy_signals.py:28
     [26](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_lazy_signals.py:26) from hyperspy._signals.complex_signal1d import LazyComplexSignal1D
     [27](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_lazy_signals.py:27) from hyperspy._signals.complex_signal2d import LazyComplexSignal2D
---> [28](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_lazy_signals.py:28) from hyperspy._signals.dielectric_function import LazyDielectricFunction
     [29](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_lazy_signals.py:29) from hyperspy._signals.hologram_image import LazyHologramImage

File d:\Windows\mambaforge\envs\kp12\Lib\site-packages\hyperspy\_signals\dielectric_function.py:21
     [19](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_signals/dielectric_function.py:19) import numpy as np
     [20](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_signals/dielectric_function.py:20) from scipy import constants
---> [21](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_signals/dielectric_function.py:21) from scipy.integrate import simps, cumtrapz
     [23](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_signals/dielectric_function.py:23) from hyperspy._signals.complex_signal1d import (ComplexSignal1D,
     [24](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_signals/dielectric_function.py:24)                                                 LazyComplexSignal1D)
     [25](file:///D:/Windows/mambaforge/envs/kp12/Lib/site-packages/hyperspy/_signals/dielectric_function.py:25) from hyperspy.misc.eels.tools import eels_constant

ImportError: cannot import name 'simps' from 'scipy.integrate' (d:\Windows\mambaforge\envs\kp12\Lib\site-packages\scipy\integrate\__init__.py)

It seems that scipy changed scipy.integrate.simps to scipy.integrate.simpson since 1.6, but I bet hyperspy would have change it for a while, no ?

hakonanes commented 1 month ago

Hi @Fred-Ad!

Indeed, HyperSpy have changed this in v2. I'm working on us supporting that version. Until then, the solution is to install scipy < 1.14, where scipy.integrate.simps is still importable.

The same problem was reported by @yuanh6 in https://github.com/pyxem/kikuchipy/issues/685 and this seemed to fix his issue.

Fred-Ad commented 1 month ago

For the moment I changed simps by simpson and cumtrpz by cumulative_trapezoid in _Hyperspy/_signals/dielectric_function_ and it works.

Fred-Ad commented 1 month ago

Hi @Fred-Ad!

Indeed, HyperSpy have changed this in v2. I'm working on us supporting that version. Until then, the solution is to install scipy < 1.14, where scipy.integrate.simps is still importable.

The same problem was reported by @yuanh6 in #685 and this seemed to fix his issue.

Oh, sorry I missed this one. Thanks Hakon !

hakonanes commented 1 month ago

Not at all, thanks for reporting! I've made the title more descriptive and pinned the issue so that others who experience the same issue sees it.

hakonanes commented 1 week ago

@Fred-Ad, kikuchipy v0.11.0 with HyperSpy v2 support is now available from PyPI. So this shouldn't be a problem for newer environments.