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

Bruker get_channel floating point parsing error #38

Closed
SylviaWhittle opened this issue Jan 9, 2024 · 6 comments
Closed

Bruker get_channel floating point parsing error #38

SylviaWhittle opened this issue Jan 9, 2024 · 6 comments

Comments

@SylviaWhittle
Copy link

SylviaWhittle commented Jan 9, 2024

Describe the bug
Hi there 😄

We have been using pySPM for a while now to open Bruker .spm files, and it has been going seamlessly. Today we have noticed that on files that previously definitely loaded properly, it now throws this error. The files are non-square in their aspect ratio.

The issue appears to be the handling of floating point values in the get_channel() method of the Bruker class.

What is weird is that this error happens on both version 0.2.23 and 0.5.1 and manually setting the versions to previous versions does not fix it.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[9], [line 7](vscode-notebook-cell:?execution_count=9&line=7)
      [3](vscode-notebook-cell:?execution_count=9&line=3) data = pySPM.Bruker(file)
      [5](vscode-notebook-cell:?execution_count=9&line=5) data.list_channels()
----> [7](vscode-notebook-cell:?execution_count=9&line=7) height = data.get_channel('Height')

File [/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:173](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:173), in Bruker.get_channel(self, channel, backward, corr, debug, encoding, lazy, mfm)
    [171](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:171)     print("xres/yres", xres, yres)
    [172](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:172) scan_size = self.layers[i][b'Scan Size'][0].split()
--> [173](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:173) aspect_ratio = [int(x) for x in self.layers[i][b'Aspect Ratio'][0].split(b":")]
    [174](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:174) if debug:
    [175](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:175)     print("aspect ratio", aspect_ratio)

File [/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:173](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:173), in <listcomp>(.0)
    [171](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:171)     print("xres/yres", xres, yres)
    [172](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:172) scan_size = self.layers[i][b'Scan Size'][0].split()
--> [173](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:173) aspect_ratio = [int(x) for x in self.layers[i][b'Aspect Ratio'][0].split(b":")]
    [174](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:174) if debug:
    [175](https://file+.vscode-resource.vscode-cdn.net/opt/homebrew/Caskroom/miniforge/base/envs/new/lib/python3.10/site-packages/pySPM/Bruker.py:175)     print("aspect ratio", aspect_ratio)

ValueError: invalid literal for int() with base 10: b'0.51216'

To Reproduce
file used:
not_working_file.spm.zip

I had to compress it since GitHub won't allow .spm uploads. I hope this doesn't corrupt it.

from pathlib import Path

import pySPM

print("pySPM version: ", pySPM.__version__)

file = Path('/Users/sylvi/Downloads/not_working_file.spm')

data = pySPM.Bruker(file)

data.list_channels()

height = data.get_channel('Height')

Expected behavior
Loading the height channel data as usual.

Screenshots
image

Information:

  • OS: Windows 10 (intel x86), macOS Sonoma (ARM M1 Pro)
  • Python version: 3.10.9
  • PySPM version: 0.5.1

Please run the following and attach the result to your issue

import sys
import pySPM
import numpy as np
import scipy
import matplotlib as mpl
print("Python",sys.version)
print("pySPM",pySPM.__version__)
print("numpy",np.__version__)
print("scipy",scipy.__version__)
print("matplotlib", mpl.__version__)
Python 3.10.9 | packaged by conda-forge | (main, Feb  2 2023, 20:26:08) [Clang 14.0.6 ]
pySPM 0.5.1
numpy 1.26.3
scipy 1.10.1
matplotlib 3.7.1
@scholi
Copy link
Owner

scholi commented Jan 9, 2024

It seems that the aspect ratio is a float and not a pair of int.
Which picture has the correct aspect ratio? A or B?
A)
image
B)
image

@SylviaWhittle
Copy link
Author

Thank you for your attention

B is correct.

I have been told that we have successfully used pySPM on these images before which is strange... It seems that it shouldn't have ever worked if the code assumed a pair of integers.

@scholi
Copy link
Owner

scholi commented Jan 10, 2024

What is the real size of your image? 300μm horizontally? but for the vertical axis Gwyddion tells me about 210μm while the aspect ratio of 0.51216 of 300μm is 153μm which is strange...

@scholi
Copy link
Owner

scholi commented Jan 10, 2024

Could you try this branch: https://github.com/scholi/pySPM/tree/Bruker_non_square
Please test it with Bruker file having various aspect ratio. If you see that this work then we can merge it to master and create a new release. I have myself no more access to a Bruken instrument and thus cannot perform the tests myself....

@SylviaWhittle
Copy link
Author

The real size of the image as reported by Nanoscope, are 300nm x 210nm (0.7 aspect ratio)
image

I also held a tape measure up to my screen and confirmed an aspect ratio of 0.7.

We have no idea where the 0.51216 aspect ratio could come from. It is very strange. It is also strange that these files loaded perfectly fine before about December 22nd 2023. Perhaps there is some user error in there somewhere...

Your branch works on both the files that were not previously able to be loaded. I cannot share the second one as it is a collaborator's data and we don't have permission to share it.

Here is a screenshot of it working:
image

Thank you for your time, it is very much appreciated by our team 😄

@scholi
Copy link
Owner

scholi commented Jan 11, 2024

Ok good to hear that it works :). So I will merge this branch to master.

@scholi scholi closed this as completed Jan 11, 2024
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

2 participants