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

KWave adapter rotation bug fix #270

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -110,14 +110,10 @@ def forward_model(self, detection_geometry: DetectionGeometryBase) -> np.ndarray
axes = (0, 2)
image_slice = np.s_[:]

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]
[image_slice], 3, axes=axes)
data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND] = data_dict[Tags.DATA_FIELD_SPEED_OF_SOUND][image_slice].T
data_dict[Tags.DATA_FIELD_DENSITY] = data_dict[Tags.DATA_FIELD_DENSITY][image_slice].T
data_dict[Tags.DATA_FIELD_ALPHA_COEFF] = data_dict[Tags.DATA_FIELD_ALPHA_COEFF][image_slice].T
data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE] = data_dict[Tags.DATA_FIELD_INITIAL_PRESSURE][image_slice].T

time_series_data, global_settings = self.k_wave_acoustic_forward_model(
detection_geometry,
Expand Down Expand Up @@ -249,10 +245,6 @@ def k_wave_acoustic_forward_model(self, detection_geometry: DetectionGeometryBas
subprocess.run(cmd)

raw_time_series_data = sio.loadmat(optical_path)[Tags.DATA_FIELD_TIME_SERIES_DATA]

# reverse the order of detector elements from matlab to python order
raw_time_series_data = raw_time_series_data[::-1, :]

time_grid = sio.loadmat(optical_path + "dt.mat")
num_time_steps = int(np.round(time_grid["number_time_steps"]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def reconstruction_algorithm(self, time_series_sensor_data, detection_geometry):

reconstructed_data = sio.loadmat(acoustic_path + "tr.mat")[Tags.DATA_FIELD_RECONSTRUCTED_DATA]

reconstructed_data = np.flipud(np.rot90(reconstructed_data, 1, axes))
reconstructed_data = reconstructed_data.T

field_of_view_mm = detection_geometry.get_field_of_view_mm()
field_of_view_voxels = (field_of_view_mm / spacing_in_mm).astype(np.int32)
Expand Down
8 changes: 4 additions & 4 deletions simpa/visualisation/matplotlib_data_visualisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def visualise_data(wavelength: int = None,
plt.title(data_item_names[i])
if len(np.shape(data_to_show[i])) > 2:
pos = int(np.shape(data_to_show[i])[1] / 2) - 1
data = np.rot90(data_to_show[i][:, pos, :], -1)
data = data_to_show[i][:, pos, :].T
plt.imshow(np.log10(data) if logscales[i] else data, cmap=cmaps[i])
else:
data = np.rot90(data_to_show[i][:, :], -1)
data = data_to_show[i][:, :].T
plt.imshow(np.log10(data) if logscales[i] else data, cmap=cmaps[i])
plt.colorbar()

Expand All @@ -233,10 +233,10 @@ def visualise_data(wavelength: int = None,
plt.title(data_item_names[i])
if len(np.shape(data_to_show[i])) > 2:
pos = int(np.shape(data_to_show[i])[0] / 2)
data = np.rot90(data_to_show[i][pos, :, :], -1)
data = data_to_show[i][pos, :, :].T
plt.imshow(np.log10(data) if logscales[i] else data, cmap=cmaps[i])
else:
data = np.rot90(data_to_show[i][:, :], -1)
data = data_to_show[i][:, :].T
plt.imshow(np.log10(data) if logscales[i] else data, cmap=cmaps[i])
plt.colorbar()

Expand Down
4 changes: 2 additions & 2 deletions simpa_examples/perform_iterative_qPAI_reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __init__(self):
if i == 0:
plt.ylabel("x-z", fontsize=10)
plt.title(label[i], fontsize=10)
plt.imshow(np.rot90(quantity, -1))
plt.imshow(quantity.T)
plt.xticks(fontsize=6)
plt.yticks(fontsize=6)
plt.colorbar()
Expand All @@ -222,7 +222,7 @@ def __init__(self):
if i == 0:
plt.ylabel("y-z", fontsize=10)
plt.title(label[i], fontsize=10)
plt.imshow(np.rot90(quantity, -1))
plt.imshow(quantity.T)
plt.xticks(fontsize=6)
plt.yticks(fontsize=6)
plt.colorbar()
Expand Down
6 changes: 3 additions & 3 deletions simpa_tests/manual_tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
plt.figure(figsize=(9, 3))
plt.subplot(1, 3, 1)
plt.title("Initial pressure")
plt.imshow(np.rot90(initial_pressure[:, 20, :], 3))
plt.imshow(initial_pressure[:, 20, :].T)
plt.subplot(1, 3, 2)
plt.title("Pipeline\nReconstruction")
if self.reconstructed_image_pipeline is not None:
plt.imshow(np.rot90(self.reconstructed_image_pipeline, 3))
plt.imshow(self.reconstructed_image_pipeline.T)
plt.subplot(1, 3, 3)
plt.title("Convenience Method\nReconstruction")
if self.reconstructed_image_convenience is not None:
plt.imshow(np.rot90(self.reconstructed_image_convenience, 3))
plt.imshow(self.reconstructed_image_convenience.T)

plt.tight_layout()
if show_figure_on_screen:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def setup(self):
self.VOLUME_PLANAR_DIM_IN_MM/2,
0]))
self.device.set_detection_geometry(LinearArrayDetectionGeometry(device_position_mm=self.device.device_position_mm, pitch_mm=0.25,
number_detector_elements=200))
number_detector_elements=200, field_of_view_extent_mm=[-37.5, 37.5, 0, 0, 0, 25]))
self.device.add_illumination_geometry(SlitIlluminationGeometry(slit_vector_mm=[100, 0, 0]))

# run pipeline including volume creation and optical mcx simulation
Expand All @@ -107,29 +107,14 @@ def test_convenience_function(self):
self.VOLUME_NAME + ".hdf5",
Tags.DATA_FIELD_INITIAL_PRESSURE, wavelength=700)
image_slice = np.s_[:, 40, :]
self.initial_pressure = np.rot90(initial_pressure[image_slice], -1)

# define acoustic settings and run simulation with convenience function
acoustic_settings = {
Tags.ACOUSTIC_SIMULATION_3D: True,
Tags.ACOUSTIC_MODEL_BINARY_PATH: self.path_manager.get_matlab_binary_path(),
Tags.KWAVE_PROPERTY_ALPHA_POWER: 0.00,
Tags.KWAVE_PROPERTY_SENSOR_RECORD: "p",
Tags.KWAVE_PROPERTY_PMLInside: False,
Tags.KWAVE_PROPERTY_PMLSize: [31, 32],
Tags.KWAVE_PROPERTY_PMLAlpha: 1.5,
Tags.KWAVE_PROPERTY_PlotPML: False,
Tags.RECORDMOVIE: False,
Tags.MOVIENAME: "visualization_log",
Tags.ACOUSTIC_LOG_SCALE: True,
Tags.MODEL_SENSOR_FREQUENCY_RESPONSE: False
}
self.initial_pressure = initial_pressure[image_slice].T

time_series_data = perform_k_wave_acoustic_forward_simulation(initial_pressure=self.initial_pressure,
detection_geometry=self.device.
get_detection_geometry(),
speed_of_sound=1540, density=1000,
alpha_coeff=0.0)

alpha_coeff=0.0, spacing_mm=0.25)
# reconstruct the time series data to compare it with initial pressure
self.settings.set_reconstruction_settings({
Tags.RECONSTRUCTION_MODE: Tags.RECONSTRUCTION_MODE_PRESSURE,
Expand All @@ -155,7 +140,7 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
plt.imshow(self.initial_pressure)
plt.subplot(2, 2, 2)
plt.title("Reconstructed Image Pipeline")
plt.imshow(np.rot90(self.reconstructed, -1))
plt.imshow(self.reconstructed.T)
plt.tight_layout()
if show_figure_on_screen:
plt.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
plt.figure(figsize=(9, 3))
plt.subplot(1, 3, 1)
plt.title(f"{self.SPEED_OF_SOUND * 0.975} m/s")
plt.imshow(np.rot90(self.reconstructed_image_950, 3))
plt.imshow(self.reconstructed_image_950.T)
plt.subplot(1, 3, 2)
plt.title(f"{self.SPEED_OF_SOUND} m/s")
plt.imshow(np.rot90(self.reconstructed_image_1000, 3))
plt.imshow(self.reconstructed_image_1000.T)
plt.subplot(1, 3, 3)
plt.title(f"{self.SPEED_OF_SOUND * 1.025} m/s")
plt.imshow(np.rot90(self.reconstructed_image_1050, 3))
plt.imshow(self.reconstructed_image_1050.T)
plt.tight_layout()
if show_figure_on_screen:
plt.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
plt.subplot(4, int(np.ceil(len(self.list_2d_reconstructed_absorptions) / 2)), i + 1)
if i == 0:
plt.ylabel("y-z", fontsize=10)
plt.imshow(np.rot90(quantity, -1))
plt.imshow(quantity.T)
plt.title(label[i], fontsize=10)
plt.xticks(fontsize=6)
plt.yticks(fontsize=6)
Expand All @@ -193,7 +193,7 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
i + int(np.ceil(len(self.list_2d_reconstructed_absorptions) / 2)) + 1)
if i == 0:
plt.ylabel("x-z", fontsize=10)
plt.imshow(np.rot90(quantity, -1))
plt.imshow(quantity.T)
plt.title(label[i], fontsize=10)
plt.xticks(fontsize=6)
plt.yticks(fontsize=6)
Expand All @@ -207,7 +207,7 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
plt.subplot(4, int(np.ceil(len(self.list_2d_reconstructed_absorptions) / 2)),
i + 2 * int(np.ceil(len(self.list_2d_reconstructed_absorptions) / 2)) + 1)
plt.title("Iteration step: " + str(i + 1), fontsize=8)
plt.imshow(np.rot90(quantity, -1)) # absorption maps in list are already 2-d
plt.imshow(quantity.T) # absorption maps in list are already 2-d
plt.colorbar()
plt.clim(cmin, cmax)
plt.axis('off')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def visualise_result(self, show_figure_on_screen=True, save_path=None):
plt.suptitle("Linear Unmixing - Visual Test")
plt.subplot(131)
plt.title("Ground Truth sO2 [%]")
plt.imshow(np.rot90(ground_truth_sO2[:, y_dim, :] * 100, -1), vmin=0, vmax=100)
plt.imshow(ground_truth_sO2[:, y_dim, :].T * 100, vmin=0, vmax=100)
plt.colorbar(fraction=0.05)
plt.subplot(132)
plt.title("Estimated sO2 [%]")
plt.imshow(np.rot90(self.sO2[:, y_dim, :] * 100, -1), vmin=0, vmax=100)
plt.imshow(self.sO2[:, y_dim, :].T * 100, vmin=0, vmax=100)
plt.colorbar(fraction=0.05)
plt.subplot(133)
plt.title("Absolute Difference")
plt.imshow(np.rot90(np.abs(self.sO2 * 100 - ground_truth_sO2 * 100)[:, y_dim, :], -1), cmap="Reds", vmin=0)
plt.imshow(np.abs(self.sO2 * 100 - ground_truth_sO2 * 100)[:, y_dim, :].T, cmap="Reds", vmin=0)
plt.colorbar()
plt.tight_layout()
if show_figure_on_screen:
Expand Down
Loading