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

Convert str to Path if needed #230

Merged
merged 5 commits into from
Nov 16, 2024
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
4 changes: 3 additions & 1 deletion regularizepsf/psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import inspect
import pathlib
from typing import TYPE_CHECKING, Any, cast
from functools import partial

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"][:]]
Expand Down
4 changes: 3 additions & 1 deletion regularizepsf/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import pathlib
from typing import TYPE_CHECKING

import h5py
Expand All @@ -15,7 +16,6 @@
from regularizepsf.visualize import KERNEL_IMSHOW_ARGS_DEFAULT, visualize_grid

if TYPE_CHECKING:
import pathlib

from regularizepsf.psf import ArrayPSF

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"][:]]
Expand Down
Loading