Skip to content

Commit

Permalink
fixing bytes io issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollman committed Sep 16, 2024
1 parent f9e8ef1 commit 1bc7a19
Show file tree
Hide file tree
Showing 2 changed files with 533 additions and 358 deletions.
20 changes: 14 additions & 6 deletions meshparty/skeleton_io.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
import h5py
import orjson
import json
Expand Down Expand Up @@ -77,11 +78,15 @@ def write_skeleton_h5_by_part(
"""

if os.path.isfile(filename):
if overwrite:
os.remove(filename)
else:
return
if isinstance(filename, (str, Path)):
if os.path.isfile(filename):
if overwrite:
os.remove(filename)
else:
raise FileExistsError(
f"File {filename} already exists, use overwrite=True to overwrite"
)

with h5py.File(filename, "w") as f:
f.attrs["file_version"] = FILE_VERSION

Expand Down Expand Up @@ -141,7 +146,10 @@ def read_skeleton_h5_by_part(filename):
overwrite, whether to overwrite file
"""
assert os.path.isfile(filename)
# if filename is a string test that it is a file
if isinstance(filename, (str, Path)):
if not os.path.isfile(filename):
raise FileNotFoundError(f"File {filename} not found")

with h5py.File(filename, "r") as f:
vertices = f["vertices"][()]
Expand Down
Loading

0 comments on commit 1bc7a19

Please sign in to comment.