pyxem / kikuchipy

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

Fails with NumPy v1.20 with TypeError: expected dtype object, got 'numpy.dtype[float32]' #319

Closed hakonanes closed 3 years ago

hakonanes commented 3 years ago

Most changes of NumPy array data types in kikuchipy are done by passing numpy.dtype.float32 etc. to numpy.ndarray.astype(). This is not supported after NumPy v1.20 and yields this error TypeError: expected dtype object, got 'numpy.dtype[float32]'.

The solution is to install NumPy v1.19, via either pip install numpy==1.19 or conda install numpy==1.19.

We should consider releasing another patch forcing <1.20 in setup.py (and update the conda feedstock).

pc494 commented 3 years ago

What is/was the motivation to for using float32? Most of the numpy documention seems to be using float64 which:

"...matches the precision of the builtin python float."

source: https://numpy.org/doc/stable/user/basics.types.html#basics-types

hakonanes commented 3 years ago

The motivation was to half memory use. The precision provided by 32-bit floating point was determined sufficient considering most detectors store patterns either with 255 (8-bit) or 65534 (16-bit) grey levels.

pc494 commented 3 years ago

I would be inclined to check that (a quick google brought up mixed results, eg [1]), if it were the case I would have expected to see more people using float32 though...

[1] - https://stackoverflow.com/questions/43440821/the-real-difference-between-float32-and-float64

hakonanes commented 3 years ago

I've mostly seen 32-bit float pattern processing used in the EBSD community, e.g. by EMsoft and Dream3D. That's why we opted for this in kikuchipy as well.