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

T239 wavelength independent volume creation #240

Merged
merged 7 commits into from
Sep 19, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ def run(self, device: DigitalDeviceTwinBase):

self.logger.debug(f"field of view to crop: {field_of_view_voxels}")

wavelength = self.global_settings[Tags.WAVELENGTH]

for data_field in data_fields:
# Crop wavelength-independent properties only in the last wavelength run
if (data_field in TissueProperties.wavelength_independent_properties
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a comment of what happens in these lines would be super helpful for reading. E.g. for wavelength-independent data field skip all wavelengths except of the last one and only crop it then

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed :)

and wavelength != self.global_settings[Tags.WAVELENGTHS][-1]):
continue
self.logger.debug(f"Cropping data field {data_field}...")

# load
wavelength = self.global_settings[Tags.WAVELENGTH]
data_array = load_data_field(self.global_settings[Tags.SIMPA_OUTPUT_PATH], data_field, wavelength)
self.logger.debug(f"data array shape before cropping: {np.shape(data_array)}")
self.logger.debug(f"data array shape len: {len(np.shape(data_array))}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ def forward_model(self, detection_geometry: DetectionGeometryBase) -> np.ndarray

"""

wavelength = self.global_settings[Tags.WAVELENGTH]
optical_path = generate_dict_path(Tags.OPTICAL_MODEL_OUTPUT_NAME,
wavelength=self.global_settings[Tags.WAVELENGTH])
wavelength=wavelength)

self.logger.debug(f"OPTICAL_PATH: {str(optical_path)}")

data_dict = {}
file_path = self.global_settings[Tags.SIMPA_OUTPUT_PATH]
data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE] = load_data_field(file_path, Tags.DATA_FIELD_INITIAL_PRESSURE)
data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE] = load_data_field(file_path, Tags.DATA_FIELD_INITIAL_PRESSURE,
wavelength=wavelength)
data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = load_data_field(file_path, Tags.DATA_FIELD_SPEED_OF_SOUND)
data_dict[Tags.DATA_FIELD_DENSITY] = load_data_field(file_path, Tags.DATA_FIELD_DENSITY)
data_dict[Tags.DATA_FIELD_ALPHA_COEFF] = load_data_field(file_path, Tags.DATA_FIELD_ALPHA_COEFF)
Expand All @@ -108,15 +110,14 @@ def forward_model(self, detection_geometry: DetectionGeometryBase) -> np.ndarray
axes = (0, 2)
image_slice = np.s_[:]

wavelength = str(self.global_settings[Tags.WAVELENGTH])
data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = np.rot90(data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND][image_slice],
3, axes=axes)
data_dict[Tags.DATA_FIELD_DENSITY] = np.rot90(data_dict[Tags.DATA_FIELD_DENSITY][image_slice],
3, axes=axes)
data_dict[Tags.DATA_FIELD_ALPHA_COEFF] = np.rot90(data_dict[Tags.DATA_FIELD_ALPHA_COEFF][image_slice],
3, axes=axes)
data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE] = np.rot90(data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE]
[wavelength][image_slice], 3, axes=axes)
[image_slice], 3, axes=axes)

time_series_data, global_settings = self.k_wave_acoustic_forward_model(
detection_geometry,
Expand Down
19 changes: 9 additions & 10 deletions simpa/core/simulation_modules/volume_creation_module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import numpy as np
from simpa.core import SimulationModule
from simpa.utils.dict_path_manager import generate_dict_path
from simpa.io_handling import save_hdf5
from simpa.io_handling import save_data_field
from simpa.utils.quality_assurance.data_sanity_testing import assert_equal_shapes, assert_array_well_defined


Expand All @@ -31,7 +31,13 @@ def create_empty_volumes(self):
volume_z_dim = int(round(self.global_settings[Tags.DIM_VOLUME_Z_MM] / voxel_spacing))
sizes = (volume_x_dim, volume_y_dim, volume_z_dim)

wavelength = self.global_settings[Tags.WAVELENGTH]
first_wavelength = self.global_settings[Tags.WAVELENGTHS][0]

for key in TissueProperties.property_tags:
# Create wavelength-independent properties only in the first wavelength run
if key in TissueProperties.wavelength_independent_properties and wavelength != first_wavelength:
continue
volumes[key] = np.zeros(sizes)

return volumes, volume_x_dim, volume_y_dim, volume_z_dim
Expand Down Expand Up @@ -60,13 +66,6 @@ def run(self, device):
continue
assert_array_well_defined(volumes[_volume_name], array_name=_volume_name)

save_volumes = dict()
for key, value in volumes.items():
if key in [Tags.DATA_FIELD_ABSORPTION_PER_CM, Tags.DATA_FIELD_SCATTERING_PER_CM,
Tags.DATA_FIELD_ANISOTROPY]:
save_volumes[key] = {self.global_settings[Tags.WAVELENGTH]: value}
else:
save_volumes[key] = value

volume_path = generate_dict_path(Tags.SIMULATION_PROPERTIES, self.global_settings[Tags.WAVELENGTH])
save_hdf5(save_volumes, self.global_settings[Tags.SIMPA_OUTPUT_PATH], file_dictionary_path=volume_path)
save_data_field(value, self.global_settings[Tags.SIMPA_OUTPUT_PATH],
data_field=key, wavelength=self.global_settings[Tags.WAVELENGTH])
25 changes: 16 additions & 9 deletions simpa/utils/tissue_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@

class TissueProperties(dict):

property_tags = [Tags.DATA_FIELD_ABSORPTION_PER_CM,
Tags.DATA_FIELD_SCATTERING_PER_CM,
Tags.DATA_FIELD_ANISOTROPY,
Tags.DATA_FIELD_GRUNEISEN_PARAMETER,
Tags.DATA_FIELD_SEGMENTATION,
Tags.DATA_FIELD_OXYGENATION,
Tags.DATA_FIELD_DENSITY,
Tags.DATA_FIELD_SPEED_OF_SOUND,
Tags.DATA_FIELD_ALPHA_COEFF]
wavelength_dependent_properties = [
Tags.DATA_FIELD_ABSORPTION_PER_CM,
Tags.DATA_FIELD_SCATTERING_PER_CM,
Tags.DATA_FIELD_ANISOTROPY
]

wavelength_independent_properties = [
Tags.DATA_FIELD_GRUNEISEN_PARAMETER,
Tags.DATA_FIELD_SEGMENTATION,
Tags.DATA_FIELD_OXYGENATION,
Tags.DATA_FIELD_DENSITY,
Tags.DATA_FIELD_SPEED_OF_SOUND,
Tags.DATA_FIELD_ALPHA_COEFF
]

property_tags = wavelength_dependent_properties + wavelength_independent_properties

def __init__(self):
super().__init__()
Expand Down
Loading