Skip to content

Commit

Permalink
updating examples with modal decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-shalloo committed Nov 13, 2024
1 parent 0b4a7b8 commit b7281c0
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 32 deletions.
105 changes: 87 additions & 18 deletions docs/source/tutorials/denoised_laser.ipynb

Large diffs are not rendered by default.

51 changes: 37 additions & 14 deletions examples/example_modal_decomposition_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
TransverseProfileFromData,
)
from lasy.utils.mode_decomposition import hermite_gauss_decomposition
from scipy.constants import epsilon_0,c

# Define the transverse profile of the laser pulse
img_url = "https://user-images.githubusercontent.com/27694869/228038930-d6ab03b1-a726-4b41-a378-5f4a83dc3778.png"
Expand Down Expand Up @@ -67,44 +68,66 @@
)

# Plotting the results
# Plot the original and denoised profiles
# Create a grid for plotting
x = np.linspace(-5 * waist, 5 * waist, 500)
X, Y = np.meshgrid(x, x)

# Determine the figure parameters
fig, ax = plt.subplots(1, 3, figsize=(12, 4), tight_layout=True)
fig.suptitle(
"Hermite-Gauss Reconstruction using m_max = %i, n_max = %i" % (m_max, n_max)
)

pltextent = (np.min(x) * 1e6, np.max(x) * 1e6, np.min(x) * 1e6, np.max(x) * 1e6)
# Plot the original profile
pltextent = np.array([np.min(x), np.max(x), np.min(x), np.max(x)]) * 1e6 # in microns
prof1 = np.abs(profile.evaluate(X, Y, 0)) ** 2
maxInten = np.max(prof1)
prof1 /= maxInten
divider0 = make_axes_locatable(ax[0])
ax0_cb = divider0.append_axes("right", size="5%", pad=0.05)
pl0 = ax[0].imshow(prof1, cmap="magma", extent=pltextent, vmin=0, vmax=np.max(prof1))
cbar0 = fig.colorbar(pl0, cax=ax0_cb)
cbar0.set_label("Intensity (norm.)")
ax[0].set_xlabel("x (micron)")
ax[0].set_ylabel("y (micron)")
ax[0].set_xlabel("x ($ \\mu m $)")
ax[0].set_ylabel("y ($ \\mu m $)")
ax[0].set_title("Original Profile")

# Plot the reconstructed profile
prof2 = np.abs(reconstructedProfile.evaluate(X, Y, 0)) ** 2
prof2 /= maxInten
divider1 = make_axes_locatable(ax[1])
ax1_cb = divider1.append_axes("right", size="5%", pad=0.05)
pl1 = ax[1].imshow(prof2, cmap="magma", extent=pltextent, vmin=0, vmax=np.max(prof1))
cbar1 = fig.colorbar(pl1, cax=ax1_cb)
cbar1.set_label("Intensity (norm.)")
ax[1].set_xlabel("x (micron)")
ax[1].set_ylabel("y (micron)")
ax[1].set_xlabel("x ($ \\mu m $)")
ax[1].set_ylabel("y ($ \\mu m $)")
ax[1].set_title("Reconstructed Profile")


prof3 = (prof1 - prof2) / np.max(prof1)
# Plot the error
prof3 = (prof1 - prof2) / np.max(prof1) # Normalized error
divider2 = make_axes_locatable(ax[2])
ax2_cb = divider2.append_axes("right", size="5%", pad=0.05)
pl2 = ax[2].imshow(100 * np.abs(prof3), cmap="magma", extent=pltextent, vmin=0, vmax=2)
pl2 = ax[2].imshow(100 * np.abs(prof3), cmap="magma", extent=pltextent)
cbar2 = fig.colorbar(pl2, cax=ax2_cb)
cbar2.set_label("|Error| (%)")
ax[2].set_xlabel("x (micron)")
ax[2].set_ylabel("y (micron)")
cbar2.set_label("|Intensity Error| (%)")
ax[2].set_xlabel("x ($ \\mu m $)")
ax[2].set_ylabel("y ($ \\mu m $)")
ax[2].set_title("Error")

fig.suptitle(
"Hermite-Gauss Reconstruction using m_max = %i, n_max = %i" % (m_max, n_max)
)
plt.show()

fig2, ax2 = plt.subplots(2, 1, figsize=(12, 8), tight_layout=True)
ax2[0].plot(x*1e6, prof2[int(len(x)/2),:],label='Reconstructed Profile',color=(1,0.5,0.5),lw=2.5)
ax2[0].plot(x*1e6, prof1[int(len(x)/2),:],label='Original Profile',color=(0.3,0.3,0.3),lw=1.0)
ax2[0].legend()
ax2[0].set_xlim(pltextent[0],pltextent[1])

ax2[1].plot(x*1e6, prof2[int(len(x)/2),:],label='Reconstructed Profile',color=(1,0.5,0.5),lw=2.5)
ax2[1].plot(x*1e6, prof1[int(len(x)/2),:],label='Original Profile',color=(0.3,0.3,0.3),lw=1.0)
ax2[1].legend()
ax2[1].set_xlim(pltextent[0],pltextent[1])
ax2[1].set_yscale('log')

plt.show()

0 comments on commit b7281c0

Please sign in to comment.