Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ragged dtype=object BaseSignal saving .hspy should give better error #141

Closed
magnunor opened this issue Jun 27, 2023 · 3 comments
Closed
Milestone

Comments

@magnunor
Copy link
Contributor

magnunor commented Jun 27, 2023

When trying to save a ragged BaseSignal with dtype=object, the error message is confusing for users. Example:

import numpy as np
import hyperspy.api as hs

data = np.empty((3, 5), dtype=object)
for ix in range(data.shape[-1]):
    for iy in range(data.shape[-2]):
        data[iy, ix] = np.random.randint(1, 100, size=(5, 2))

s = hs.signals.BaseSignal(data, ragged=True)
s.save("test.hspy", overwrite=True)

Gives the error message TypeError: Object dtype dtype('O') has no native HDF5 equivalent. This is due to h5py not supporting dtype=object.

However, the error message could be improved to something like: Saving ragged signals with dtype=object is not supported, try saving it as the .zspy format instead.

@CSSFrancis
Copy link
Member

@magnunor That is a good point! I ran into this the other day as well.

That being said I think we need to improve the performance of the read for ragged arrays. I don't know if this is a regression from zarr but currently the time to load a ragged arrays seems to increase exponentially with the number of navigation positions. This causes it to become fairly unusable when you have even 100x100 navigation positions.

I'll see if I can look more into this...

@ericpre ericpre transferred this issue from hyperspy/hyperspy Jul 5, 2023
@ericpre
Copy link
Member

ericpre commented Jul 8, 2023

The issue is rather that hspy should be able to save this type of data. A workaround may be to unfold the signal when writing (write with navigation dimension 1) and fold it to the correct navigation shape when reading - see h5py/h5py#876.

@ericpre
Copy link
Member

ericpre commented Dec 16, 2023

Fixed in #164.

@ericpre ericpre closed this as completed Dec 16, 2023
@ericpre ericpre added this to the v0.2 milestone Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants