Skip to content

Commit

Permalink
Correcting the mode_decomposition utility code and documentation (#318)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Parth Ramakant Patil <[email protected]>
Co-authored-by: Maxence Thévenet <[email protected]>
  • Loading branch information
4 people authored Nov 12, 2024
1 parent 31381ad commit 802fe00
Showing 1 changed file with 8 additions and 23 deletions.
31 changes: 8 additions & 23 deletions lasy/utils/mode_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@
HermiteGaussianTransverseProfile,
)
from lasy.profiles.transverse.transverse_profile import TransverseProfile
from lasy.profiles.transverse.transverse_profile_from_data import (
TransverseProfileFromData,
)
from lasy.utils.exp_data_utils import find_d4sigma


def hermite_gauss_decomposition(laserProfile, n_x_max=12, n_y_max=12, res=1e-6):
"""
Decomposes a laser profile into a set of hermite-gaussian modes.
The function takes either an instance of `TransverseProfile` or an
instance of `Laser` (that is, either a transverse profile or the
full 3D laser profile defined on a grid). In the case that an
instance of `Laser` is passed then the intensity of this profile
is projected onto an x-y plane for the decomposition.
The function takes an instance of `TransverseProfile`.
Parameters
----------
Expand All @@ -45,27 +38,19 @@ def hermite_gauss_decomposition(laserProfile, n_x_max=12, n_y_max=12, res=1e-6):
waist : Beam waist for which the decomposition is calculated.
It is computed as the waist for which the weight of order 0 is maximum.
"""
# Check if the provided laserProfile is a full laser profile or a
# transverse profile.

# Check if the provided laserProfile is a transverse profile.
assert isinstance(
laserProfile, TransverseProfile
), "laserProfile must be an instance of TransverseProfile"

# Get the field, sensible spatial bounds for the profile
lo = [None, None]
hi = [None, None]
if isinstance(laserProfile, TransverseProfileFromData):
lo[0] = laserProfile.field_interp.grid[0].min() + laserProfile.x_offset
lo[1] = laserProfile.field_interp.grid[1].min() + laserProfile.x_offset
hi[0] = laserProfile.field_interp.grid[0].max() + laserProfile.y_offset
hi[1] = laserProfile.field_interp.grid[1].max() + laserProfile.y_offset

else:
lo[0] = -laserProfile.w0 * 5 + laserProfile.x_offset
lo[1] = -laserProfile.w0 * 5 + laserProfile.x_offset
hi[0] = laserProfile.w0 * 5 + laserProfile.x_offset
hi[1] = laserProfile.w0 * 5 + laserProfile.x_offset

lo[0] = laserProfile.field_interp.grid[0].min() + laserProfile.x_offset
lo[1] = laserProfile.field_interp.grid[1].min() + laserProfile.x_offset
hi[0] = laserProfile.field_interp.grid[0].max() + laserProfile.y_offset
hi[1] = laserProfile.field_interp.grid[1].max() + laserProfile.y_offset

Nx = int((hi[0] - lo[0]) // (2 * res) * 2) + 2
Ny = int((hi[1] - lo[1]) // (2 * res) * 2) + 2
Expand Down Expand Up @@ -151,5 +136,5 @@ def estimate_best_HG_waist(x, y, field):
coeffTest[i] = np.real(np.sum(profile * field))
w0 = waistTest[np.argmax(coeffTest)]

print("Estimated w0 = %.2f microns" % (w0Est * 1e6))
print("Estimated w0 = %.2f microns (1/e^2 width)" % (w0Est * 1e6))
return w0

0 comments on commit 802fe00

Please sign in to comment.