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

feature: Ensure img_path is of type Path #108

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AFMReader/topostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def load_topostats(file_path: Path | str) -> tuple:
try:
with h5py.File(file_path, "r") as f:
data = unpack_hdf5(open_hdf5_file=f, group_path="/")

if data["topostats_file_version"] >= 0.2:
data["img_path"] = Path(data["img_path"])
file_version = data["topostats_file_version"]
logger.info(f"[{filename}] TopoStats file version : {file_version}")
image = data["image"]
Expand Down
Binary file added tests/resources/sample_0_2.topostats
Binary file not shown.
33 changes: 31 additions & 2 deletions tests/test_topostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,36 @@
0.1,
(64, 64),
1.97601171875,
{"topostats_file_version", "image", "pixel_to_nm_scaling"},
{
"pixel_to_nm_scaling",
"image",
"topostats_file_version",
},
112069.51332503435,
id="version",
id="version 0.1",
),
pytest.param(
"sample_0_2.topostats",
0.2,
(64, 64),
1.97601171875,
{
"disordered_traces",
"filename",
"grain_curvature_stats",
"grain_masks",
"height_profiles",
"image",
"image_original",
"img_path",
"nodestats",
"ordered_traces",
"pixel_to_nm_scaling",
"splining",
"topostats_file_version",
},
1176.601500471239,
id="version 0.2",
),
],
)
Expand All @@ -47,3 +74,5 @@ def test_load_topostats(
assert set(result_data.keys()) == data_keys # type: ignore
assert result_data["topostats_file_version"] == topostats_file_version
assert result_image.sum() == image_sum
if topostats_file_version >= 0.2:
assert isinstance(result_data["img_path"], Path)