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

[Bug]: AFMReader SPM module unable to handle common units #83

Closed
SylviaWhittle opened this issue Dec 5, 2024 · 1 comment · Fixed by #84
Closed

[Bug]: AFMReader SPM module unable to handle common units #83

SylviaWhittle opened this issue Dec 5, 2024 · 1 comment · Fixed by #84
Assignees
Labels
bug Something isn't working

Comments

@SylviaWhittle
Copy link
Collaborator

SylviaWhittle commented Dec 5, 2024

Describe the bug

Tobi found a bug in TopoStats where some .spm files fail. The issue appears to be that pm is not a valid unit when unpacking the pixel_to_nm_scaling factor. I compared TopoStats' spm loading code to AFMReader's and found that TopoStats has a unit dictionary of:

  unit_dict = {
      "pm": 1e-3,
      "nm": 1,
      "um": 1e3,
      "mm": 1e6,
  }

and AFMReader has:

  unit_dict = {
      "nm": 1,
      "um": 1e3,
  }

This needs updating ASAP. I'll do it.

Tobi's output log is attached below for evidence.

Copy of the output

Traceback (most recent call last):
  File "/Users/t/miniconda3/envs/main_topostats/bin/topostats", line 8, in <module>
    sys.exit(entry_point())
  File "/Users/t/Documents/topostats/main_topostats/TopoStats/topostats/entry_point.py", line 1204, in entry_point
    args.func(args)
  File "/Users/t/Documents/topostats/main_topostats/TopoStats/topostats/run_modules.py", line 231, in process
    all_scan_data.get_data()
  File "/Users/t/Documents/topostats/main_topostats/TopoStats/topostats/io.py", line 790, in get_data
    self.image, self.pixel_to_nm_scaling = suffix_to_loader[suffix]()
  File "/Users/t/Documents/topostats/main_topostats/TopoStats/topostats/io.py", line 640, in load_spm
    return spm.load_spm(file_path=self.img_path, channel=self.channel)
  File "/Users/t/miniconda3/envs/main_topostats/lib/python3.10/site-packages/AFMReader/spm.py", line 102, in load_spm
    return (image, spm_pixel_to_nm_scaling(filename, channel_data))
  File "/Users/t/miniconda3/envs/main_topostats/lib/python3.10/site-packages/AFMReader/spm.py", line 38, in spm_pixel_to_nm_scaling
    px_to_real[1][0] * unit_dict[px_to_real[1][1]],
KeyError: 'pm'
(main_topostats) t@dyn232037 430 minicircles topostats test for Niel % 

To Reproduce

The file is not shared as I presume it's secret, but ask Tobi for the .spm file and run TopoStats using it.

AFMReader Version

0.1.0

Python Version

3.11

Operating System

MacOS M1/M2 (post-2021)

Python Packages

N/A, need to be fast

@ns-rse
Copy link
Collaborator

ns-rse commented Dec 5, 2024

I had clocked these units in the _spm_pixel_to_nm_scaling() function but didn't fully appreciate the implications on loading files and thought it was a method that was used elsewhere (I've a vague recollection that this might have been added after a user wanted a more comprehensive set of units).

Sorry for not copying that over. If this is to be improved here in AFMReader we should also remove _spm_pixel_to_nm_scaling() from TopoStats (captured in #1036).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants