diff --git a/regularizepsf/psf.py b/regularizepsf/psf.py index 9ad9fe4..70a9ed4 100644 --- a/regularizepsf/psf.py +++ b/regularizepsf/psf.py @@ -3,6 +3,7 @@ from __future__ import annotations import inspect +import pathlib from typing import TYPE_CHECKING, Any, cast from functools import partial @@ -17,7 +18,6 @@ from regularizepsf.visualize import KERNEL_IMSHOW_ARGS_DEFAULT, PSF_IMSHOW_ARGS_DEFAULT, visualize_grid if TYPE_CHECKING: - import pathlib from numbers import Real from collections.abc import Callable @@ -272,6 +272,7 @@ def save(self, path: pathlib.Path) -> None: None """ + path = pathlib.Path(path) if path.suffix == ".h5": with h5py.File(path, "w") as f: f.create_dataset("coordinates", data=self.coordinates) @@ -302,6 +303,7 @@ def load(cls, path: pathlib.Path) -> ArrayPSF: loaded model """ + path = pathlib.Path(path) if path.suffix == ".h5": with h5py.File(path, "r") as f: coordinates = [tuple(c) for c in f["coordinates"][:]] diff --git a/regularizepsf/transform.py b/regularizepsf/transform.py index 7107522..4d70a6f 100644 --- a/regularizepsf/transform.py +++ b/regularizepsf/transform.py @@ -2,6 +2,7 @@ from __future__ import annotations +import pathlib from typing import TYPE_CHECKING import h5py @@ -15,7 +16,6 @@ from regularizepsf.visualize import KERNEL_IMSHOW_ARGS_DEFAULT, visualize_grid if TYPE_CHECKING: - import pathlib from regularizepsf.psf import ArrayPSF @@ -173,6 +173,7 @@ def save(self, path: pathlib.Path) -> None: None """ + path = pathlib.Path(path) if path.suffix == ".h5": with h5py.File(path, "w") as f: f.create_dataset("coordinates", data=self.coordinates) @@ -201,6 +202,7 @@ def load(cls, path: pathlib.Path) -> ArrayPSFTransform: PSFTransform """ + path = pathlib.Path(path) if path.suffix == ".h5": with h5py.File(path, "r") as f: coordinates = [tuple(c) for c in f["coordinates"][:]]