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

Incorrect Scale Conversion for Non-FEI MRC Files #91

Open
Tracked by #99
AndrewHerzing opened this issue Mar 8, 2023 · 8 comments · Fixed by #131
Open
Tracked by #99

Incorrect Scale Conversion for Non-FEI MRC Files #91

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

Comments

@AndrewHerzing
Copy link

For MRC files that are not collected by FEI software, the scale is assumed to be in Angstroms and Hyperspy converts it to nanometers. However, the conversion is done by multiplying by 10 rather than dividing by 10. The relevant lines of code are 179 - 187 in mrc.py.

    if fei_header is None:
        # The scale is in Amstrongs, we convert it to nm
        scales = [10 * float(std_header['Zlen'] / std_header['MZ'])
                  if float(std_header['MZ']) != 0 else 1,
                  10 * float(std_header['Ylen'] / std_header['MY'])
                  if float(std_header['MY']) != 0 else 1,
                  10 * float(std_header['Xlen'] / std_header['MX'])
                  if float(std_header['MX']) != 0 else 1, ]
        offsets = [10 * float(std_header['ZORIGIN']),
                   10 * float(std_header['YORIGIN']),
                   10 * float(std_header['XORIGIN']), ]
@AndrewHerzing AndrewHerzing added the type: bug Something isn't working label Mar 8, 2023
@CSSFrancis CSSFrancis transferred this issue from hyperspy/hyperspy Mar 8, 2023
@CSSFrancis
Copy link
Member

Hi @AndrewHerzing! It might be better to have this as a rosettasciio issue rather than a hyperspy issue. We can always make the changes both places but it is just better to have all of the discussion in rosettasciio rather than in hyperspy.

@AndrewHerzing
Copy link
Author

This makes sense. Looks like a pretty easy fix.

@AndrewHerzing
Copy link
Author

Here is a link to test dataset which will reproduce the error:

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. The pixel size should be 4.416 nm rather than 441.6 as the reader is currently written.

@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
@ericpre
Copy link
Member

ericpre commented Jun 4, 2023

@AndrewHerzing, thank you for sharing the file, we are finally getting around sorting these mrc issues in #131. Is it possible to get smaller test file? If so, when you have a chance, could get and share a smallest possible file to add to the test suite please? Was the file created using IMOD/SerialEM?

@ericpre
Copy link
Member

ericpre commented Jun 4, 2023

This was close automatically when merging #131, but let's keep it open for now so that we don't forget to add some test file.

@ericpre ericpre reopened this Jun 4, 2023
@AndrewHerzing
Copy link
Author

Here is a ~1MB MRC that was generated with SerialEM. This is the smallest I can create at the moment because our scope is down for repair. The scale as read by Hyperspy is 315 nm whereas it should be 3.15 nm.

https://drive.google.com/file/d/1vGQO9VM1JFyOwHMzZYnDxnnPdejTDw58/view?usp=sharing

@jlaehne
Copy link
Contributor

jlaehne commented Jun 5, 2023

By the way, with the development versions of HyperSpy (RELEASE_next_major branch) and RosettaSciIO, you should already be able to read the files correctly - in case you are comfortable to install these.

@ericpre
Copy link
Member

ericpre commented Jun 6, 2023

Thank you @AndrewHerzing, would it be possible to wait to even smaller file? Maybe with different dtype too? The bug has been fixed and until we have a new file we can check manually, when necessary. it seems that most of the code was more than 10 years for the mrc reader (possibly written at a time, where writing test wasn't enforced!) and it is not like the code need to be changed very often! :)

@ericpre ericpre removed this from the v0.1.0 initial release milestone Jun 6, 2023
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.

4 participants