Skip to content

Commit

Permalink
Merge branch 'develop' into T323_clean_logging
Browse files Browse the repository at this point in the history
  • Loading branch information
frisograce authored Aug 16, 2024
2 parents d581d0a + 09da1a5 commit 7cec4df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from simpa.core.simulation_modules.volume_creation_module import VolumeCreationAdapterBase
from simpa.utils import Tags
from simpa.utils.constants import property_tags
from simpa.io_handling import save_hdf5
import numpy as np
import torch

Expand Down Expand Up @@ -44,21 +42,19 @@ def create_simulation_volume(self) -> dict:

for seg_class in segmentation_classes:
class_properties = class_mapping[seg_class].get_properties_for_wavelength(self.global_settings, wavelength)
for prop_tag in property_tags:
if isinstance(class_properties[prop_tag], (int, float)) or class_properties[prop_tag] == None: # scalar
assigned_prop = class_properties[prop_tag]
for volume_key in volumes.keys():
if isinstance(class_properties[volume_key], (int, float)) or class_properties[volume_key] == None: # scalar
assigned_prop = class_properties[volume_key]
if assigned_prop is None:
assigned_prop = torch.nan
volumes[prop_tag][segmentation_volume == seg_class] = assigned_prop
elif len(torch.Tensor.size(class_properties[prop_tag])) == 3: # 3D map
assigned_prop = class_properties[prop_tag][torch.tensor(segmentation_volume == seg_class)]
volumes[volume_key][segmentation_volume == seg_class] = assigned_prop
elif len(torch.Tensor.size(class_properties[volume_key])) == 3: # 3D map
assigned_prop = class_properties[volume_key][torch.tensor(segmentation_volume == seg_class)]
assigned_prop[assigned_prop is None] = torch.nan
volumes[prop_tag][torch.tensor(segmentation_volume == seg_class)] = assigned_prop
volumes[volume_key][torch.tensor(segmentation_volume == seg_class)] = assigned_prop
else:
raise AssertionError("Properties need to either be a scalar or a 3D map.")

save_hdf5(self.global_settings, self.global_settings[Tags.SIMPA_OUTPUT_PATH], "/settings/")

# convert volumes back to CPU
for key in volumes.keys():
volumes[key] = volumes[key].numpy().astype(np.float64, copy=False)
Expand Down
11 changes: 7 additions & 4 deletions simpa/utils/path_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class PathManager:
one we provided in the `simpa_examples`) in the following places in this order:
1. The optional path you give the PathManager
2. Your $HOME$ directory
3. The current working directory
4. The SIMPA home directory path
2. Your set environment variables
3. Your $HOME$ directory
4. The current working directory
5. The SIMPA home directory path
"""

def __init__(self, environment_path=None):
Expand All @@ -32,6 +33,7 @@ def __init__(self, environment_path=None):
"""
self.logger = Logger()
self.path_config_file_name = 'path_config.env'
override = False
if environment_path is None:
environment_path = os.path.join(str(Path.home()), self.path_config_file_name)
self.logger.debug(f"Using $HOME$ path to search for config file: {environment_path}")
Expand All @@ -44,13 +46,14 @@ def __init__(self, environment_path=None):
f"for {self.path_config_file_name}")
environment_path = os.path.join(environment_path, self.path_config_file_name)
self.logger.debug(f"Using supplied path to search for config file: {environment_path}")
override = True

if environment_path is None or not os.path.exists(environment_path) or not os.path.isfile(environment_path):
error_message = f"Did not find a { self.path_config_file_name} file in any of the standard directories..."
self.logger.warning(error_message)

self.environment_path = environment_path
load_dotenv(environment_path, override=True)
load_dotenv(environment_path, override=override)

def detect_local_path_config(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion simpa_examples/segmentation_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def segmentation_class_mapping():
settings[Tags.SIMULATION_PATH] = path_manager.get_hdf5_file_save_path()
settings[Tags.VOLUME_NAME] = "SegmentationTest"
settings[Tags.RANDOM_SEED] = 1234
settings[Tags.WAVELENGTHS] = [700]
settings[Tags.WAVELENGTHS] = [700, 800]
settings[Tags.SPACING_MM] = spacing
settings[Tags.DIM_VOLUME_X_MM] = segmentation_volume_mask.shape[0] * spacing
settings[Tags.DIM_VOLUME_Y_MM] = segmentation_volume_mask.shape[1] * spacing
Expand Down

0 comments on commit 7cec4df

Please sign in to comment.