Skip to content

Add installed simpa version in hdf5 files #325

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

Merged
merged 10 commits into from
Jul 29, 2024
6 changes: 6 additions & 0 deletions simpa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

from .utils import *
from .log import Logger
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("simpa")
except PackageNotFoundError:
__version__ = "unknown version"

from .core.simulation_modules.volume_creation_module.volume_creation_module_model_based_adapter import \
ModelBasedVolumeCreationAdapter
from .core.simulation_modules.volume_creation_module.volume_creation_module_segmentation_based_adapter import \
Expand Down
5 changes: 4 additions & 1 deletion simpa/core/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# SPDX-License-Identifier: MIT

from simpa.utils import Tags
from simpa import __version__

from simpa.io_handling.io_hdf5 import save_hdf5, load_hdf5, save_data_field, load_data_field
from simpa.io_handling.ipasc import export_to_ipasc
from simpa.utils.settings import Settings
Expand Down Expand Up @@ -54,7 +56,8 @@ def simulate(simulation_pipeline: list, settings: Settings, digital_device_twin:
simpa_output_path = path + settings[Tags.VOLUME_NAME]

settings[Tags.SIMPA_OUTPUT_PATH] = simpa_output_path + ".hdf5"


simpa_output[Tags.SIMPA_VERSION] = __version__
simpa_output[Tags.SETTINGS] = settings
simpa_output[Tags.DIGITAL_DEVICE] = digital_device_twin
simpa_output[Tags.SIMULATION_PIPELINE] = [type(x).__name__ for x in simulation_pipeline]
Expand Down
2 changes: 2 additions & 0 deletions simpa/io_handling/io_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def data_grabber(file, path):
"""

if isinstance(h5file[path], h5py._hl.dataset.Dataset):
if isinstance(h5file[path][()], bytes):
return h5file[path][()].decode("utf-8")
return h5file[path][()]

dictionary = {}
Expand Down
2 changes: 1 addition & 1 deletion simpa/utils/dict_path_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def generate_dict_path(data_field, wavelength: (int, float) = None) -> str:
:return: String which defines the path to the data_field.
"""

if data_field in [Tags.SIMULATIONS, Tags.SETTINGS, Tags.DIGITAL_DEVICE, Tags.SIMULATION_PIPELINE]:
if data_field in [Tags.SIMPA_VERSION, Tags.SIMULATIONS, Tags.SETTINGS, Tags.DIGITAL_DEVICE, Tags.SIMULATION_PIPELINE]:
return "/" + data_field + "/"

all_wl_independent_properties = wavelength_independent_properties + toolkit_tags
Expand Down
2 changes: 1 addition & 1 deletion simpa/utils/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ class Tags:
Default filename of the SIMPA output if not specified otherwise.\n
Usage: SIMPA package, naming convention
"""
SIMPA_VERSION = ("simpa_version", str)
SIMPA_VERSION = "simpa_version"
"""
Version number of the currently installed simpa package
Usage: SIMPA package
Expand Down
Loading