Skip to content
15 changes: 8 additions & 7 deletions src/simcardems/save_load_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def dict_to_h5(data, h5name, h5group):
if h5file.keys() != "":
# Creating a temporary h5file and copy to initial file to avoid overwriting
# FIXME : Is there a more elegant way to do this ?
try:
tmp_name = str(h5name.with_suffix("")) + "_tmp.h5"
except Exception:
pass
try:
if isinstance(h5name, str):
tmp_name = str(os.path.splitext(h5name)[0]) + "_tmp.h5"
except Exception:
pass
elif isinstance(h5name, os.PathLike):
tmp_name = str(h5name.with_suffix("")) + "_tmp.h5"
else:
logger.error(
"dict_to_h5 : h5name has wrong type (supported : str / path)",
)

with h5pyfile(tmp_name, "w") as h5file_tmp:
if h5group == "":
Expand Down Expand Up @@ -153,6 +153,7 @@ def save_state(
list(heterogeneous_params.keys()),
)
# Saving homogeneous parameters (float, int)
print("type path = ", type(path))
dict_to_h5(homogeneous_params, path, "ep/cell_params")
else:
dict_to_h5(solver.ode_solver._model.parameters(), path, "ep/cell_params")
Expand Down