Skip to content

Commit eb48817

Browse files
MaCuineajkosciessa
authored andcommitted
Improve T1 tran plot + bug fix missing input param setup_grid_source_sensor
- Adapt percentage of dt_stability limit to 90%, because 1% will result in very long simulations.
1 parent a925c6d commit eb48817

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

functions/preprocess_brain.m

+6-7
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,17 @@
7171

7272
% Creates and exports an unprocessed T1 slice that is oriented
7373
% along the transducer's axis
74-
[t1_with_trans_img, ~] = plot_t1_with_transducer(...
75-
t1_image, round(t1_header.PixelDimensions(1),2), trans_pos_grid, focus_pos_grid, parameters);
76-
7774
h = figure;
78-
imshow(rot90(t1_with_trans_img));
75+
imshowpair(plot_t1_with_transducer(t1_image, t1_header.PixelDimensions(1), trans_pos_grid, focus_pos_grid, parameters), ...
76+
plot_t1_with_transducer(t1_image, t1_header.PixelDimensions(1), trans_pos_grid, focus_pos_grid, parameters, 'slice_dim', 1),'montage');
77+
7978
title('T1 with transducer');
8079
output_plot_filename = fullfile(parameters.debug_dir, ...
8180
sprintf('sub-%03d_t1_with_transducer_before_smoothing_and_cropping%s.png', ...
8281
subject_id, parameters.results_filename_affix));
8382
saveas(h, output_plot_filename, 'png')
84-
close(h); clear t1_with_trans_img;
85-
83+
close(h);
84+
8685
%% SEGMENTATION using SimNIBS
8786

8887
disp('Starting segmentation...')
@@ -111,7 +110,7 @@
111110
focus_pos_final = [];
112111
final_transformation_matrix = [];
113112
inv_final_transformation_matrix = [];
114-
return;
113+
return;
115114
end
116115
else
117116
disp('Skipping, the file already exists, loading it instead.')

functions/setup_grid_source_sensor.m

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [kgrid, source, sensor, source_labels] = setup_grid_source_sensor(parameters, max_sound_speed, trans_pos_final, focus_pos_final)
1+
function [kgrid, source, sensor, source_labels] = setup_grid_source_sensor(parameters, max_sound_speed, trans_pos_final, focus_pos_final, grid_time_step)
22

33
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
44
% Set up the transducer and sensor %
@@ -21,6 +21,10 @@
2121
wave_period = 1 / parameters.transducer.source_freq_hz; % period [s]
2222

2323
% Check the number of input arguments
24+
% As a default the time step is based on the default CFL number of 0.3.
25+
% If grid_time_step is given, it means that the transducer and sensor
26+
% has to be set up again with a smaller time step due to simulation
27+
% instability.
2428
if nargin < 5
2529
% Calculate the time step using an integer number of points per period
2630
points_per_wavelength = max_sound_speed / (parameters.transducer.source_freq_hz * parameters.grid_step_m); % points per wavelength

single_subject_pipeline.m

+8-1
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,17 @@
246246
max_sound_speed = max(kwave_medium.sound_speed(:));
247247
[kgrid, source, sensor, source_labels] = setup_grid_source_sensor(parameters, max_sound_speed, trans_pos_final, focus_pos_final);
248248
% check stability
249+
% If estimated time step is smaller than the time step based on
250+
% default CFL, the estimated time step is used to redefine
251+
% transducer and sensor. Note: the estimated time step doesn't
252+
% guarantee a stable simulation. If Nan numbers are acquired as
253+
% a result, you may want to try a time step smaller than the
254+
% estimated time step.
249255
disp('Check stability...')
250256
dt_stability_limit = checkStability(kgrid, kwave_medium);
251257
if ~isinf(dt_stability_limit) && kgrid.dt > dt_stability_limit
252-
grid_time_step = dt_stability_limit/100; % use a 1% of the limit (which are only aan approximation in the heterogenous medium case: http://www.k-wave.org/documentation/checkStability.php)
258+
disp('Adapt time step for simulation stability...')
259+
grid_time_step = dt_stability_limit*0.90; % use 90% of the limit (which are only an approximation in the heterogenous medium case: http://www.k-wave.org/documentation/checkStability.php)
253260
[kgrid, source, sensor, source_labels] = setup_grid_source_sensor(parameters, max_sound_speed, trans_pos_final, focus_pos_final, grid_time_step);
254261
end
255262
end

0 commit comments

Comments
 (0)