Skip to content

Commit

Permalink
chore: Remove unused method, test and package dependencies
Browse files Browse the repository at this point in the history
Closes #1036

With the delegation of much I/O (Input/Output) functionality to @SylviaWhittle `AFMReader` (see #1031) we have removed
most of the methods to the `io.LoadScan()` class. One that slipped through was `_spm_pixel_to_nm_scaling()` and this
commit removes it along with its associated test.

Further the delegation of reading AFM files using `AFMReader` means `TopoStats` no longer has explicit dependencies on
the `igor2`, `pySPM` or `tifffile` packages and so these have been removed from the `dependencies` section of
`pyproject.toml`. These are dependencies of `AFMReader` and will still be installed in virtual environments.
  • Loading branch information
ns-rse committed Dec 11, 2024
1 parent df4cb02 commit f80e625
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 65 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ dependencies = [
"art",
"AFMReader",
"h5py",
"igor2",
"keras",
"matplotlib",
"numpy",
"numpyencoder",
"pandas",
"pySPM",
"pyyaml",
"ruamel.yaml",
"schema",
Expand All @@ -54,7 +52,6 @@ dependencies = [
"skan~=0.11.0",
"snoop",
"tensorflow",
"tifffile",
"topoly",
"tqdm",
]
Expand Down
29 changes: 0 additions & 29 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import logging
from datetime import datetime
from pathlib import Path
from unittest.mock import patch

import h5py
import numpy as np
import pandas as pd
import pySPM
import pytest

from topostats.io import (
Expand Down Expand Up @@ -603,33 +601,6 @@ def test_load_scan_topostats(load_scan_topostats: LoadScans) -> None:
assert grain_trace_data.keys() == {"above"}


@patch("pySPM.SPM.SPM_image.pxs")
@pytest.mark.parametrize(
("unit", "x", "y", "expected_px2nm"),
[
pytest.param("mm", 0.01, 0.01, 10000, id="mm units; square"),
pytest.param("um", 1.5, 1.5, 1500, id="um units; square"),
pytest.param("nm", 50, 50, 50, id="nm units; square"),
pytest.param("pm", 233, 233, 0.233, id="pm units; square"),
pytest.param("pm", 1, 512, 0.001, id="pm units; rectangular (thin)"),
pytest.param("pm", 512, 1, 0.512, id="pm units; rectangular (tall)"),
],
)
def test__spm_pixel_to_nm_scaling(
mock_pxs,
load_scan_spm: LoadScans,
spm_channel_data: pySPM.SPM.SPM_image,
unit: str,
x: int,
y: int,
expected_px2nm: float,
) -> None:
"""Test extraction of pixels to nanometer scaling."""
mock_pxs.return_value = [(x, unit), (y, unit)] # issue is that pxs is a func that returns the data
result = load_scan_spm._spm_pixel_to_nm_scaling(spm_channel_data)
assert result == expected_px2nm


@pytest.mark.parametrize(
("load_scan_object", "length", "image_shape", "image_sum", "filename", "pixel_to_nm_scaling"),
[
Expand Down
33 changes: 0 additions & 33 deletions topostats/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import numpy as np
import numpy.typing as npt
import pandas as pd
import pySPM
from AFMReader import asd, gwy, ibw, jpk, spm, topostats
from numpyencoder import NumpyEncoder
from ruamel.yaml import YAML, YAMLError
Expand Down Expand Up @@ -642,38 +641,6 @@ def load_spm(self) -> tuple[npt.NDArray, float]:
LOGGER.error(f"File Not Found : {self.img_path}")
raise

def _spm_pixel_to_nm_scaling(self, channel_data: pySPM.SPM.SPM_image) -> float:
"""
Extract pixel to nm scaling from the SPM image metadata.
Parameters
----------
channel_data : pySPM.SPM.SPM_image
Channel data from PySPM.
Returns
-------
float
Pixel to nm scaling factor.
"""
unit_dict = {
"pm": 1e-3,
"nm": 1,
"um": 1e3,
"mm": 1e6,
}
px_to_real = channel_data.pxs()
# Has potential for non-square pixels but not yet implemented
pixel_to_nm_scaling = (
px_to_real[0][0] * unit_dict[px_to_real[0][1]],
px_to_real[1][0] * unit_dict[px_to_real[1][1]],
)[0]
if px_to_real[0][0] == 0 and px_to_real[1][0] == 0:
pixel_to_nm_scaling = 1
LOGGER.warning(f"[{self.filename}] : Pixel size not found in metadata, defaulting to 1nm")
LOGGER.debug(f"[{self.filename}] : Pixel to nm scaling : {pixel_to_nm_scaling}")
return pixel_to_nm_scaling

def load_topostats(self) -> tuple[npt.NDArray, float]:
"""
Load a .topostats file (hdf5 format).
Expand Down

0 comments on commit f80e625

Please sign in to comment.