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

T162 heterogenous sos #176

Open
wants to merge 50 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1968b05
Fixed syntax in type hints of the function arguments
cbender98 Jul 22, 2022
195e62d
added Tag which defines whether to consider heterogenous sos
cbender98 Jul 22, 2022
022bb36
1st version of heterogenous sos delay calculation
cbender98 Jul 22, 2022
b63b0fe
corrected type hints in arguments, add arguments
cbender98 Jul 22, 2022
e357d97
improved accuray to ~10^(-13) (compared with homogenous calculation a…
cbender98 Aug 4, 2022
d6eb409
fixed interpolation by transposing sos-map
cbender98 Aug 5, 2022
fa8b083
new test for heterogenous reconsruction based on MinimalKWaveTest.py
cbender98 Aug 5, 2022
4c9123c
moved and renamed; added gaussian noise and 2 regions sos-maps
cbender98 Aug 8, 2022
e3c323a
renamed manual test for testing hDAS recon using toy sos-maps
cbender98 Aug 9, 2022
f9b5ef0
write new test for hDAS using tissue based sos and simulated p0
cbender98 Aug 9, 2022
9ccfda7
update type hints, comments; differentiate between float/array hand…
cbender98 Aug 9, 2022
480ff61
removed unnecessary comments/prints, replaced prints by logger prints
cbender98 Aug 9, 2022
464149b
last version using grid_sample function (integral offset by 1 with re…
cbender98 Aug 16, 2022
44f9969
added bilinear interpolation function of imgs/maps
cbender98 Aug 16, 2022
d3ef49c
debugged for pixels outside the to interpolated map to take the neare…
cbender98 Sep 9, 2022
58a2e81
manual test for testing hDAS using 3 point like vessels
cbender98 Sep 9, 2022
13fb5a5
memory optimized version for 2d interpolation, but can be made nicer
cbender98 Sep 9, 2022
090b54c
renamed the file again and fixed some typos
cbender98 Sep 9, 2022
a04779d
added new function with own interpolation, changed errors due to offs…
cbender98 Sep 9, 2022
f3304f0
optimized 2d interpolation in terms of gpu memory usage, added print_…
cbender98 Sep 13, 2022
a8ceb2a
automated test for testing 2d interpolation function
cbender98 Sep 13, 2022
4b0b95e
fixed typo (one blank space too much)
cbender98 Sep 13, 2022
9c4796d
debugged 3d interpolation and wrote test for 2d and 3d interpolation
cbender98 Sep 13, 2022
39b0c4f
tried some memory reducing methods
cbender98 Sep 13, 2022
a13b63f
optimized memory usage in interpolation
cbender98 Sep 13, 2022
6582173
for 400x400 fov fixed memory issue
cbender98 Sep 13, 2022
d508626
delete comment with old memory expensive 2d interpolation
cbender98 Sep 13, 2022
42b562d
renamed file and added one vessel
cbender98 Sep 14, 2022
3425b22
restructured a few lines
cbender98 Sep 14, 2022
697c69f
converted jupyter-notebook into python file
cbender98 Sep 14, 2022
f909b2c
convert notebook to automatic test: compares numerically integrated d…
cbender98 Sep 15, 2022
8ce85e6
added some boolean as input parameters for debugging and verboseness,
cbender98 Sep 15, 2022
4e349fc
decrease computation time down to 70%
cbender98 Sep 15, 2022
4af3232
outsourced toms homogen delay calculation,
cbender98 Sep 16, 2022
94d69cb
applied memory reducing steps also to 3dim case and tested it against…
cbender98 Sep 16, 2022
daed4bd
added verbosity handling and also changed input parameters to be in t…
cbender98 Sep 16, 2022
448557b
renamed class name
cbender98 Sep 16, 2022
309f52b
delete optionality parameters:
cbender98 Sep 19, 2022
f134b63
deleted all optional parameters (also mixed_coordinate_system)
cbender98 Sep 19, 2022
3aae172
added comments and type hints
cbender98 Sep 19, 2022
88b5080
also works for cpu now
cbender98 Sep 19, 2022
ae58450
deleted function w/ own interpolation due to computation time
cbender98 Sep 26, 2022
d078547
added parameter for random sensor
cbender98 Sep 26, 2022
d0391f6
commented and added new plot
cbender98 Sep 27, 2022
95b5b04
save path changes
cbender98 Sep 27, 2022
749f5ee
delete unneccessary import
cbender98 Sep 27, 2022
fcebc8a
Merge branch 'develop' into T162_HeterogenousSOS
leoyala Dec 14, 2022
74896f1
added logger as parameter to `calculate_delays_for_homogen_sos`
leoyala Dec 14, 2022
dccdbb3
debugged assert error (correct position boundaries of sensor sampling)
cbender98 Dec 16, 2022
0c0fb8b
corrected heterogeneous spelling
cbender98 Dec 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from scipy.spatial.transform import Rotation
from simpa.core.simulation_modules.acoustic_forward_module import AcousticForwardModelBaseAdapter
import gc
from typing import Union


class KWaveAdapter(AcousticForwardModelBaseAdapter):
Expand All @@ -34,16 +35,16 @@ class KWaveAdapter(AcousticForwardModelBaseAdapter):
The initial pressure distribution:
Tags.OPTICAL_MODEL_INITIAL_PRESSURE
Acoustic tissue properties:
Tags.PROPERTY_SPEED_OF_SOUND
Tags.PROPERTY_DENSITY
Tags.PROPERTY_ALPHA_COEFF
Tags.DATA_FIELD_SPEED_OF_SOUND
Tags.DATA_FIELD_DENSITY
Tags.DATA_FIELD_ALPHA_COEFF
The digital twin of the imaging device:
Tags.DIGITAL_DEVICE
Other parameters:
Tags.PERFORM_UPSAMPLING
Tags.SPACING_MM
Tags.UPSCALE_FACTOR
Tags.PROPERTY_ALPHA_POWER
Tags.DATA_FIELD_ALPHA_POWER
Tags.GPU
Tags.PMLInside
Tags.PMLAlpha
Expand Down Expand Up @@ -127,11 +128,11 @@ def forward_model(self, detection_geometry: DetectionGeometryBase) -> np.ndarray
return time_series_data

def k_wave_acoustic_forward_model(self, detection_geometry: DetectionGeometryBase,
speed_of_sound: float, density: float,
speed_of_sound: Union[float, np.ndarray], density: float,
alpha_coeff: float, initial_pressure: np.ndarray,
optical_path: str = "temporary") -> tuple:
"""
Runs the acoustic forward model with the given parameters speed_of_sound (float), density (float),
Runs the acoustic forward model with the given parameters speed_of_sound (float or np.ndarray), density (float),
alpha_coeff (float) for the initial_pressure distribution (numpy array) and a given detection geometry.
Uses the given optical_path (str) or if none is given a temporary one for saving temporary files.
Note, that in order to work properly, this function assumes that several settings mentioned above are set.
Expand Down Expand Up @@ -165,7 +166,15 @@ def k_wave_acoustic_forward_model(self, detection_geometry: DetectionGeometryBas
else:
simulate_2d = False

data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = np.ones_like(initial_pressure) * speed_of_sound
self.logger.debug(f"Input SoS has shape {speed_of_sound.shape} and std {np.std(speed_of_sound)}")

if isinstance(speed_of_sound, float):
data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = np.ones_like(initial_pressure) * speed_of_sound
elif isinstance(speed_of_sound, np.ndarray):
data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = speed_of_sound
else:
self.logger.warning("Speed-of-sound has unsuported type (neither float nor np.ndarray)")

data_dict[Tags.DATA_FIELD_DENSITY] = np.ones_like(initial_pressure) * density
data_dict[Tags.DATA_FIELD_ALPHA_COEFF] = np.ones_like(initial_pressure) * alpha_coeff
data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE] = initial_pressure
Expand Down Expand Up @@ -272,7 +281,7 @@ def k_wave_acoustic_forward_model(self, detection_geometry: DetectionGeometryBas

def perform_k_wave_acoustic_forward_simulation(initial_pressure: np.array,
detection_geometry: DetectionGeometryBase,
speed_of_sound: float = 1540.0,
speed_of_sound: Union[float, np.ndarray] = 1540.0,
density: float = 1000.0,
alpha_coeff: float = 0.02,
acoustic_settings: Settings = None,
Expand All @@ -288,9 +297,9 @@ def perform_k_wave_acoustic_forward_simulation(initial_pressure: np.array,
spacing_mm: float = 0.5) -> np.array:
"""
Convenience function for performing a k-Wave acoustic forward simulation using a given detection geometry and
initial pressure distribution (numpy array) with the following parameters speed_of_sound (float), density (float),
alpha_coeff (float) as well as acoustic_settings (Settings). The acoustic settings may be parsed individually,
however, they will be overwritten if they are also set in the acoustic_settings.
initial pressure distribution (numpy array) with the following parameters speed_of_sound (float or np.ndarray),
density (float), alpha_coeff (float) as well as acoustic_settings (Settings). The acoustic settings may be parsed
individually. However, they will be overwritten if they are also set in the acoustic_settings.

:param initial_pressure:
:param detection_geometry:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from simpa.utils import Settings
from simpa.core.simulation_modules.reconstruction_module.reconstruction_utils import bandpass_filter_with_settings, apply_b_mode
from simpa.utils.quality_assurance.data_sanity_testing import assert_array_well_defined
from typing import Union


class ReconstructionAdapterBase(SimulationModule):
Expand Down Expand Up @@ -89,14 +90,14 @@ def run(self, device):
self.logger.info("Performing reconstruction...[Done]")


def create_reconstruction_settings(speed_of_sound_in_m_per_s: int = 1540, time_spacing_in_s: float = 2.5e-8,
def create_reconstruction_settings(speed_of_sound_in_m_per_s: Union[int, np.ndarray] = 1540, time_spacing_in_s: float = 2.5e-8,
sensor_spacing_in_mm: float = 0.1,
recon_mode: str = Tags.RECONSTRUCTION_MODE_PRESSURE,
apodization: str = Tags.RECONSTRUCTION_APODIZATION_BOX) -> Settings:
"""
Function that creates SIMPA settings for reconstruction convenience function.

:param speed_of_sound_in_m_per_s: (int) speed of sound in medium in meters per second (default: 1540 m/s)
:param speed_of_sound_in_m_per_s: (int or np.ndarry) speed of sound in medium in meters per second (default: 1540 m/s)
:param time_spacing_in_s: (float) time between sampling points in seconds (default: 2.5e-8 s which is equal to 40 MHz)
:param sensor_spacing_in_mm: (float) space between sensor elements in millimeters (default: 0.1 mm)
:param recon_mode: SIMPA Tag defining the reconstruction mode - pressure default OR differential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
compute_image_dimensions, preparing_reconstruction_and_obtaining_reconstruction_settings
from simpa.core.device_digital_twins import DetectionGeometryBase
from simpa.core.simulation_modules.reconstruction_module import create_reconstruction_settings
from typing import Union


class DelayAndSumAdapter(ReconstructionAdapterBase):
Expand Down Expand Up @@ -42,8 +43,8 @@ def reconstruction_algorithm(self, time_series_sensor_data, detection_geometry:

values, _ = compute_delay_and_sum_values(time_series_sensor_data, sensor_positions, xdim,
ydim, zdim, xdim_start, xdim_end, ydim_start, ydim_end, zdim_start, zdim_end, spacing_in_mm, speed_of_sound_in_m_per_s,
time_spacing_in_ms, self.logger, torch_device,
self.component_settings)
time_spacing_in_ms, self.logger, torch_device, self.component_settings,
self.global_settings, detection_geometry.device_position_mm)

_sum = torch.sum(values, dim=3)
counter = torch.count_nonzero(values, dim=3)
Expand All @@ -56,7 +57,7 @@ def reconstruction_algorithm(self, time_series_sensor_data, detection_geometry:

def reconstruct_delay_and_sum_pytorch(time_series_sensor_data: np.ndarray,
detection_geometry: DetectionGeometryBase,
speed_of_sound_in_m_per_s: int = 1540,
speed_of_sound_in_m_per_s: Union[int, np.ndarray] = 1540,
time_spacing_in_s: float = 2.5e-8,
sensor_spacing_in_mm: float = 0.1,
recon_mode: str = Tags.RECONSTRUCTION_MODE_PRESSURE,
Expand All @@ -66,7 +67,7 @@ def reconstruct_delay_and_sum_pytorch(time_series_sensor_data: np.ndarray,

:param time_series_sensor_data: (2D numpy array) sensor data of shape (sensor elements, time steps)
:param detection_geometry: The DetectionGeometryBase that should be used to reconstruct the given time series data
:param speed_of_sound_in_m_per_s: (int) speed of sound in medium in meters per second (default: 1540 m/s)
:param speed_of_sound_in_m_per_s: (int or np.ndarray) speed of sound in medium in meters per second (default: 1540 m/s)
:param time_spacing_in_s: (float) time between sampling points in seconds (default: 2.5e-8 s which is equal to 40 MHz)
:param sensor_spacing_in_mm: (float) space between sensor elements in millimeters (default: 0.1 mm)
:param recon_mode: SIMPA Tag defining the reconstruction mode - pressure default OR differential
Expand Down
Loading