Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utility to denoise laser profile and adding a test for the same #315

Open
wants to merge 45 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7ff5913
D1: Utility to denoise laser profile
Paaaaarth Oct 23, 2024
04d4e34
trial change
Paaaaarth Nov 7, 2024
f20666f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 7, 2024
59457f5
Merge branch 'LASY-org:development' into utility
Paaaaarth Nov 7, 2024
b4e5490
Merge branch 'LASY-org:development' into utility
Paaaaarth Nov 12, 2024
3f9d979
Changes to mode_decomposition code and documentation
Nov 7, 2024
f4dd7c8
D2: Utility to denoise laser profile
Nov 12, 2024
92b662a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2024
ecf3cb0
Fixing accidental commits
Nov 12, 2024
829e9e6
Merge branch 'development' into utility
Paaaaarth Nov 12, 2024
2670372
minor changes
Paaaaarth Nov 12, 2024
285973a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2024
0859fd6
minor changes
Paaaaarth Nov 12, 2024
9e0cf03
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 12, 2024
eff919b
minor changes
Paaaaarth Nov 12, 2024
51a7269
D1_test_denoise
Nov 19, 2024
1379fb4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
f01c74b
D2_test_denoise
Nov 19, 2024
e410bce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
f996b4d
D3: Utility to denoise laser profile
Nov 19, 2024
e7fe531
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
be798e3
Minor change
Paaaaarth Nov 20, 2024
2bd3392
D3: Adding additional user-defined parameters.
Nov 21, 2024
aa01d24
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
a42264c
Merge branch 'LASY-org:development' into utility
Paaaaarth Nov 21, 2024
24dc4d5
D4: adding capability to add an img file as input.
Paaaaarth Nov 22, 2024
bbba42d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 22, 2024
5d24d74
D5: Minor changes
Paaaaarth Nov 22, 2024
4506458
D6: Changes to if else statement
Paaaaarth Nov 22, 2024
0f4bf4e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 22, 2024
bf128c6
Minor changes
Paaaaarth Nov 22, 2024
d7a0237
parameter order as per #326
Paaaaarth Dec 2, 2024
3377eef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 2, 2024
f0827ce
D7:utility:denoise:remove skimage package
Paaaaarth Dec 3, 2024
f811464
Minor changes
Paaaaarth Dec 3, 2024
117f069
Merge branch 'LASY-org:development' into utility
Paaaaarth Dec 5, 2024
ba87f81
Requested changes implemented
Jan 2, 2025
9d371ac
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 2, 2025
111cf2a
Removing unnecessary outputs(new laser energy)
Paaaaarth Jan 2, 2025
c66c567
Minor changes
Paaaaarth Jan 2, 2025
1bd7d3a
Minor Changes
Paaaaarth Jan 2, 2025
e87b2dc
Minor changes
Paaaaarth Jan 2, 2025
41a1ceb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 2, 2025
b796669
Minor change
Paaaaarth Jan 2, 2025
5357182
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changes to mode_decomposition code and documentation
Parth Ramakant Patil committed Nov 12, 2024
commit 3f9d97914bb9c60c6787b0f622ef4df400d2eb0f
146 changes: 126 additions & 20 deletions docs/source/tutorials/denoised_laser.ipynb

Large diffs are not rendered by default.

66 changes: 62 additions & 4 deletions lasy/utils/denoise.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from lasy.utils.mode_decomposition import hermite_gauss_decomposition


<<<<<<< Updated upstream
def denoise_laser(parameters, n_modes_x=2, n_modes_y=2):
transverse_profile = parameters["transverse_profile"]
longitudinal_profile = parameters["longitudinal_profile"]
@@ -25,12 +26,39 @@ def denoise_laser(parameters, n_modes_x=2, n_modes_y=2):
resolution = 0.2e-6
else:
resolution = parameters["resolution"]
=======
class DenoisedLaser:
def denoise_lg_modes(parameters, n_modes_x = 2, n_modes_y = 2):
transverse_profile = parameters["transverse_profile"]
longitudinal_profile = parameters["longitudinal_profile"]
polarization = parameters["polarization"]
laser_energy_new = 0

if parameters.get("wavelength") is None:
try:
wavelength = transverse_profile.lambda0
except AttributeError:
raise ValueError("The wavelength must be specified.")
else:
wavelength = parameters["wavelength"]

if parameters.get("laser_energy") is None:
laser_energy = 1 # In joules
else:
laser_energy = parameters["laser_energy"]

if parameters.get("resolution") is None:
resolution = 0.2e-6
else:
resolution = parameters["resolution"]
>>>>>>> Stashed changes

# Calculate the decomposition and waist of the laser pulse
modeCoeffs, waist = hermite_gauss_decomposition(
transverse_profile, n_modes_x, n_modes_y, resolution
)
# Calculate the decomposition and waist of the laser pulse
modeCoeffs, waist = hermite_gauss_decomposition(
transverse_profile, n_modes_x, n_modes_y, resolution
)

<<<<<<< Updated upstream
# Denosing the laser profile
for i, mode_key in enumerate(list(modeCoeffs)):
tmp_transverse_profile = HermiteGaussianTransverseProfile(
@@ -42,23 +70,53 @@ def denoise_laser(parameters, n_modes_x=2, n_modes_y=2):
laser_profile_cleaned = modeCoeffs[
mode_key
] * CombinedLongitudinalTransverseProfile(
=======
# Denosing the laser profile
for i, mode_key in enumerate(list(modeCoeffs)):
tmp_transverse_profile = HermiteGaussianTransverseProfile(
waist, mode_key[0], mode_key[1]
)
print(f"Mode {i}: {mode_key} with coefficient {modeCoeffs[mode_key]}")
laser_energy_new += modeCoeffs[mode_key] ** 2 # Energy fraction of the mode
if i == 0: # First mode (0,0)
laser_profile_cleaned = modeCoeffs[
mode_key
] * CombinedLongitudinalTransverseProfile(
>>>>>>> Stashed changes
wavelength,
polarization,
laser_energy,
longitudinal_profile,
tmp_transverse_profile,
)
<<<<<<< Updated upstream
else: # All other modes
laser_profile_cleaned += modeCoeffs[
mode_key
] * CombinedLongitudinalTransverseProfile(
=======
else: # All other modes
laser_profile_cleaned += modeCoeffs[
mode_key
] * CombinedLongitudinalTransverseProfile(
>>>>>>> Stashed changes
wavelength,
polarization,
laser_energy,
longitudinal_profile,
tmp_transverse_profile,
)
<<<<<<< Updated upstream
# Energy loss due to decomposition
energy_loss = 1 - laser_energy_new
print(f"Energy loss: {energy_loss * 100:.2f}%")
return laser_profile_cleaned, laser_energy_new
=======
# Energy loss due to decomposition
energy_loss = 1 - laser_energy_new
print(f"Energy loss: {energy_loss * 100:.2f}%")
return laser_profile_cleaned, laser_energy_new

def help():
print("Please refer to the following tutorial: https://lasydoc.readthedocs.io/en/latest/tutorials/denoised_laser.html")
>>>>>>> Stashed changes
30 changes: 8 additions & 22 deletions lasy/utils/mode_decomposition.py
Original file line number Diff line number Diff line change
@@ -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 only takes an instance of `TransverseProfile`.

Parameters
----------
@@ -45,8 +38,7 @@ 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
@@ -55,17 +47,11 @@ def hermite_gauss_decomposition(laserProfile, n_x_max=12, n_y_max=12, res=1e-6):
# 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
@@ -151,5 +137,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