Skip to content

Commit

Permalink
fix plots and imports in scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
djps authored Feb 27, 2024
1 parent b4f694f commit f84c453
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
9 changes: 4 additions & 5 deletions examples/at_circular_piston_3D/at_circular_piston_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from kwave.options.simulation_execution_options import SimulationExecutionOptions
from kwave.options.simulation_options import SimulationOptions


# material values
c0: float = 1500.0 # sound speed [m/s]
rho0: float = 1000.0 # density [kg/m^3]
Expand Down Expand Up @@ -209,10 +208,10 @@

# plot the source mask (pml is outside the grid in this example)
fig2, ax2 = plt.subplots(1, 1)
ax2.pcolormesh(1e3 * np.squeeze(kgrid.x_vec),
1e3 * np.squeeze(kgrid.y_vec),
source.p_mask[:, :, int(np.ceil(Nz / 2))].T,
shading='gouraud')
ax2.pcolormesh(1e3 * np.squeeze(kgrid.y_vec),
1e3 * np.squeeze(kgrid.x_vec),
np.flip(source.p_mask[:, :, int(np.ceil(Nz / 2))], axis=0),
shading='nearest')
ax2.set(xlabel='y [mm]',
ylabel='x [mm]',
title='Source Mask')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

from kwave.kspaceFirstOrder3D import kspaceFirstOrder3D

from kwave.options import SimulationOptions, SimulationExecutionOptions
from kwave.options.simulation_options import SimulationOptions
from kwave.options.simulation_execution_options import SimulationExecutionOptions

verbose: bool = False

Expand Down Expand Up @@ -199,20 +200,21 @@
grid_weights = karray.get_array_grid_weights(kgrid)

fig2, (ax2a, ax2b) = plt.subplots(1, 2)
ax2a.pcolormesh(1e3 * np.squeeze(kgrid.x_vec),
1e3 * np.squeeze(kgrid.y_vec),
source.p_mask[:, :, int(np.ceil(Nz / 2))].T,
shading='gouraud')
ax2a.pcolormesh(1e3 * np.squeeze(kgrid.y_vec),
1e3 * np.squeeze(kgrid.x_vec),
np.flip(source.p_mask[:, :, int(np.ceil(Nz / 2))], axis=0),
shading='nearest')
ax2a.set(xlabel='y [mm]',
ylabel='x [mm]',
title='Source Mask')
ax2b.pcolormesh(1e3 * np.squeeze(kgrid.x_vec),
1e3 * np.squeeze(kgrid.y_vec),
grid_weights[:, :, int(np.ceil(Nz / 2))].T,
shading='gouraud')
ax2b.pcolormesh(1e3 * np.squeeze(kgrid.y_vec),
1e3 * np.squeeze(kgrid.x_vec),
np.flip(grid_weights[:, :, int(np.ceil(Nz / 2))], axis=0),
shading='nearest')
ax2b.set(xlabel='y [mm]',
ylabel='x [mm]',
title='Off-Grid Source Weights')
plt.tight_layout(pad=1.2)

# plot the pressure field
fig3, ax3 = plt.subplots(1, 1)
Expand Down
34 changes: 18 additions & 16 deletions examples/at_focused_bowl_3D/at_focused_bowl_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

from kwave.kspaceFirstOrder3D import kspaceFirstOrder3D

from kwave.options import SimulationOptions, SimulationExecutionOptions
from kwave.options.simulation_options import SimulationOptions
from kwave.options.simulation_execution_options import SimulationExecutionOptions


def L2_error(x: np.ndarray, y: np.ndarray, ord=None) -> float:
Expand Down Expand Up @@ -202,16 +203,16 @@ def L2_error(x: np.ndarray, y: np.ndarray, ord=None) -> float:

# calculate analytical solution
p_ref_axial, _, _ = focused_bowl_oneil(source_roc,
source_diameter,
source_amp / (c0 * rho0),
source_f0,
c0,
rho0,
axial_positions=x_ref)
source_diameter,
source_amp / (c0 * rho0),
source_f0,
c0,
rho0,
axial_positions=x_ref)

# calculate analytical solution at exactly the same points as k-Wave
p_ref_axial_kw, _, _ = focused_bowl_oneil(source_roc, source_diameter, source_amp / (c0 * rho0),
source_f0, c0, rho0, axial_positions=x_vec)
source_f0, c0, rho0, axial_positions=x_vec)

# calculate errors
L2 = L2_error(p_ref_axial_kw, amp_on_axis, ord=2)
Expand Down Expand Up @@ -240,20 +241,21 @@ def L2_error(x: np.ndarray, y: np.ndarray, ord=None) -> float:
grid_weights = karray.get_array_grid_weights(kgrid)

fig2, (ax2a, ax2b) = plt.subplots(1, 2)
ax2a.pcolormesh(1e3 * np.squeeze(kgrid.x_vec),
1e3 * np.squeeze(kgrid.y_vec),
source.p_mask[:, :, int(np.ceil(Nz / 2))].T,
shading='gouraud')
ax2a.pcolormesh(1e3 * np.squeeze(kgrid.y_vec),
1e3 * np.squeeze(kgrid.x_vec),
np.flip(source.p_mask[:, :, int(np.ceil(Nz / 2))], axis=0),
shading='nearest')
ax2a.set(xlabel='y [mm]',
ylabel='x [mm]',
title='Source Mask')
ax2b.pcolormesh(1e3 * np.squeeze(kgrid.x_vec),
1e3 * np.squeeze(kgrid.y_vec),
grid_weights[:, :, int(np.ceil(Nz / 2))].T,
shading='gouraud')
ax2b.pcolormesh(1e3 * np.squeeze(kgrid.y_vec),
1e3 * np.squeeze(kgrid.x_vec),
np.flip(grid_weights[:, :, int(np.ceil(Nz / 2))], axis=0),
shading='nearest')
ax2b.set(xlabel='y [mm]',
ylabel='x [mm]',
title='Off-Grid Source Weights')
plt.tight_layout(pad=1.2)

# plot the pressure field
fig3, ax3 = plt.subplots(1, 1)
Expand Down

0 comments on commit f84c453

Please sign in to comment.