Skip to content

Commit

Permalink
Add show method to visualize the laser
Browse files Browse the repository at this point in the history
  • Loading branch information
RemiLehe committed Oct 26, 2023
1 parent 46ce6fd commit a641a0c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
30 changes: 29 additions & 1 deletion docs/source/tutorials/gaussian_laser.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@
"laser = Laser(dimensions,lo,hi,num_points,laser_profile)"
]
},
{
"cell_type": "markdown",
"id": "8ac8f985-4a09-4b9a-a9ff-11ce2ef94caa",
"metadata": {},
"source": [
"The laser pulse can be visualized with the `show` method."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb8dc634-b3c4-4448-834b-fe9acb6c9645",
"metadata": {},
"outputs": [],
"source": [
"laser.show()"
]
},
{
"cell_type": "markdown",
"id": "292c6e63-0480-4fb9-b1ad-6b679a3472d0",
Expand All @@ -97,6 +115,16 @@
"laser.propagate(-z_R) # Propagate the pulse upstream of the focal plane"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3158e51d-e331-438d-90c1-5f8c63bf9841",
"metadata": {},
"outputs": [],
"source": [
"laser.show()"
]
},
{
"cell_type": "markdown",
"id": "8df816dc-9b47-4cb0-8716-600352fafb72",
Expand Down Expand Up @@ -143,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
31 changes: 31 additions & 0 deletions lasy/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,34 @@ def write_to_file(
self.profile.pol,
save_as_vector_potential,
)


def show( self, **kw ):
"""
Show a 2D image of the laser amplitude
Parameters:
----------
**kw: additional arguments to be passed to matplotlib's imshow command
"""
if self.dim == "rt":
# Show field above and below axis, with proper sign
E = [
np.concatenate( ( (-1)**m * self.grid.field[0,::-1], self.grid.field[0] ) ) \
for m in self.grid.azimuthal_modes
]
E = sum(E)
extent = [self.grid.lo[-1], self.grid.hi[-1], -self.grid.hi[0], self.grid.hi[0]]

else:
# In 3D show an image in the xt plane
i_slice = int(self.grid.field.shape[1]//2)
E = self.grid.field[:,i_slice,:]
extent=[self.grid.lo[-1], self.grid.hi[-1], self.grid.lo[0], self.grid.hi[0]]

import matplotlib.pyplot as plt
plt.imshow( abs(E), extent=extent, aspect='auto', origin='lower', **kw )
cb = plt.colorbar()
cb.set_label('$|E_{envelope}|$ (V/m)')
plt.xlabel('t (s)')
plt.ylabel('x (m)')

0 comments on commit a641a0c

Please sign in to comment.