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

Non-FEI MRC Files Fail to Load #96

Closed
Tracked by #99
AndrewHerzing opened this issue Mar 20, 2023 · 0 comments · Fixed by #131
Closed
Tracked by #99

Non-FEI MRC Files Fail to Load #96

AndrewHerzing opened this issue Mar 20, 2023 · 0 comments · Fixed by #131
Labels
type: bug Something isn't working

Comments

@AndrewHerzing
Copy link

Describe the bug

For MRC files that are not collected by FEI software, an error will result when using hs.load() to read them. The issue is related to a change in NumPy which occurred several years ago. The bug was fixed for cases where the MRC file contains an FEI-style header, but the case for other MRC files was ignored.

The issue is that the value std_header['NEXT'] is a NumPy array, whereas the code expects it to be an integer.

To Reproduce

A test non-FEI MRC file can be found here:

https://drive.google.com/file/d/1zv1gaa3YYe8Sg5kbaUsPx3qV5yfcFsyX/view?usp=sharing
It is a short tilt series consisting of 9 images which are 512x512 pixels each with 'int16' data type which was generated using SerialEM.

If Hyperspy is used to import the MRC file, it will fail.

import hyperspy.api as hs
s = hs.load('NonFEI_MRC_Test_File.mrc')

File ~/anaconda3/envs/tomo/lib/python3.9/site-packages/hyperspy/io_plugins/mrc.py:155, in file_reader(filename, endianess, **kwds)
    153 else:
    154     _logger.warning("There was a problem reading the extended header")
--> 155     f.seek(1024 + std_header['NEXT'])
    156     fei_header = None
    157 NX, NY, NZ = std_header['NX'], std_header['NY'], std_header['NZ']

TypeError: only integer scalar arrays can be converted to a scalar index

To fix

All that needs to be done is to change line 155 of mrc.py by adding a [0] after the call to the std_header dictionary. Currently, the line reads:

f.seek(1024 + std_header['NEXT'])

It should read:

 f.seek(1024 + std_header['NEXT'][0])
@AndrewHerzing AndrewHerzing added the type: bug Something isn't working label Mar 20, 2023
@jlaehne jlaehne added this to the v0.1.0 initial release milestone Apr 17, 2023
@jlaehne jlaehne mentioned this issue Apr 17, 2023
19 tasks
@ericpre ericpre mentioned this issue Jun 1, 2023
8 tasks
@jlaehne jlaehne linked a pull request Jun 2, 2023 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants