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

Added tests for LongitudinalProfileFromData and fix for issue #185 #304

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5045667
Added tests for LongitudinalProfileFromData
Oct 8, 2024
c325c05
Monotonically decreasing spectral data in LongitudinalProfileFromData
Oct 8, 2024
60a6fc6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
d67b2a2
Updated tests
Oct 8, 2024
8dfae34
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
b38e4a4
Minor correction
Oct 8, 2024
7434295
em-archer
Oct 8, 2024
36f7e57
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
ff58c8b
Minor correction
Oct 8, 2024
c4dc18d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 8, 2024
fd0dda1
Syntax
Oct 8, 2024
8667d78
Syntax conflict
Oct 9, 2024
aef6bef
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
293fba0
em-archer
Oct 9, 2024
bb23517
em-archer
Oct 9, 2024
a366342
Should now include phase
Oct 9, 2024
bc0112b
Final commit
Oct 9, 2024
6951008
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
dfbb025
Fixing flipping of arrays
Oct 9, 2024
63854d3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
7e231f1
em-archer
Oct 9, 2024
e2ed172
Assertions also checked with separate notebook
Oct 9, 2024
d05893f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
5186fdd
Increase time resolution
Oct 9, 2024
4b2b40a
Modified to also allow spectral data to be specified with respect to …
Oct 10, 2024
804f5bf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
5e7a93f
Merge branch 'LASY-org:development' into development
em-archer Oct 14, 2024
fb5aabc
Added requirement for user to specify axis type
Oct 14, 2024
39e81a1
Merge branch 'LASY-org:development' into development
em-archer Oct 14, 2024
16e70ee
Merge branch 'development' of https://github.com/em-archer/lasy into …
Oct 14, 2024
07ada48
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2024
51d67b2
Merge branch 'LASY-org:development' into development
em-archer Oct 15, 2024
e6dab5d
Update lasy/profiles/longitudinal/longitudinal_profile_from_data.py
em-archer Oct 16, 2024
1c6f7a3
Update lasy/profiles/longitudinal/longitudinal_profile_from_data.py
em-archer Oct 16, 2024
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
19 changes: 13 additions & 6 deletions lasy/profiles/longitudinal/longitudinal_profile_from_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LongitudinalProfileFromData(LongitudinalProfile):

em-archer marked this conversation as resolved.
Show resolved Hide resolved
axis : ndarrays of floats
The horizontal axis of the pulse duration measurement.
The array must be monotonously increasing.
The array must be monotonically increasing or decreasing.
When datatype is 'spectral' axis is wavelength in meters.
When datatype is 'temporal' axis is time in seconds.

Expand Down Expand Up @@ -62,14 +62,21 @@ def __init__(self, data, lo, hi):
if data["datatype"] == "spectral":
# First find central frequency
wavelength = data["axis"]
assert np.all(
np.diff(wavelength) > 0
), 'data["axis"] must be in monotonously increasing order.'
spectral_intensity = data["intensity"]
assert np.all(np.diff(wavelength) > 0) or np.all(
np.diff(wavelength) < 0
), 'data["axis"] must be in monotonically increasing or decreasing order.'
if np.all(np.diff(wavelength) < 0):
wavelength = wavelength[::-1]
spectral_intensity = data["intensity"][::-1]
else:
spectral_intensity = data["intensity"]
if data.get("phase") is None:
spectral_phase = np.zeros_like(wavelength)
else:
spectral_phase = data["phase"]
if np.all(np.diff(wavelength) < 0):
spectral_phase = data["phase"][::-1]
else:
spectral_phase = data["phase"]
dt = data["dt"]
cwl = np.sum(spectral_intensity * wavelength) / np.sum(spectral_intensity)
cfreq = c / cwl
Expand Down
51 changes: 50 additions & 1 deletion tests/test_laser_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lasy.profiles.longitudinal import (
CosineLongitudinalProfile,
GaussianLongitudinalProfile,
LongitudinalProfileFromData,
SuperGaussianLongitudinalProfile,
)
from lasy.profiles.profile import Profile, ScaledProfile, SummedProfile
Expand Down Expand Up @@ -153,11 +154,14 @@

wavelength = 800e-9
tau_fwhm = 30.0e-15
omega_fwhm = 4 * np.log(2) / tau_fwhm # Assumes fully-compressed
t_peak = 1.0 * tau_fwhm
cep_phase = 0.5 * np.pi
omega_0 = 2.0 * np.pi * c / wavelength
omega0 = 2.0 * np.pi * c / wavelength

t = np.linspace(t_peak - 4 * tau_fwhm, t_peak + 4 * tau_fwhm, npoints)
omega = np.linspace(omega0 - 4 * omega_fwhm, omega0 + 4 * omega_fwhm, npoints)
wavelength_axis = 2.0 * np.pi * c / omega

# GaussianLongitudinalProfile
print("GaussianLongitudinalProfile")
Expand Down Expand Up @@ -234,6 +238,51 @@
print("cep_phase = ", cep_phase_cos)
assert np.abs(cep_phase_cos - cep_phase) / cep_phase < 0.02

# LongitudinalProfileFromData - initially assuming zero phase
print("LongitudinalProfileFromData")
data = {}
data["datatype"] = "spectral"
data["dt"] = np.abs(
t[1] - t[0]
) # Generate spectral data assuming unchirped Gaussian
profile = np.exp(
Fixed Show fixed Hide fixed
tau**2 * ((omega - omega0) ** 2) / 4.0 + +1.0j * (cep_phase + omega * t_peak)
)

print("Case 1: monotonically increasing spectral data")
data["axis"] = wavelength_axis
data["intensity"] = spectral_intensity
profile_data = LongitudinalProfileFromData(data, np.min(t), np.max(t))
field_data = profile_data.evaluate(t)

std_gauss_data = np.sqrt(np.average((t - t_peak) ** 2, weights=np.abs(field_data)))
std_gauss_th = tau / np.sqrt(2.0)
print("std_th = ", std_gauss_th)
print("std = ", std_gauss_data)
assert np.abs(std_gauss_data - std_gauss_th) / std_gauss_th < 0.01

t_peak_gaussian_data = t[np.argmax(np.abs(field_data))]
print("t_peak_th = ", t_peak)
print("t_peak = ", t_peak_gaussian_data)
assert np.abs(t_peak_gaussian_data - t_peak) / t_peak < 0.01

print("Case 2: monotonically decreasing spectral data")
data["axis"] = wavelength_axis[::-1]
data["intensity"] = spectral_intensity[::-1]
profile_data = LongitudinalProfileFromData(data, np.min(t), np.max(t))
field_data = profile_data.evaluate(t)

std_gauss_data = np.sqrt(np.average((t - t_peak) ** 2, weights=np.abs(field_data)))
std_gauss_th = tau / np.sqrt(2.0)
print("std_th = ", std_gauss_th)
print("std = ", std_gauss_data)
assert np.abs(std_gauss_data - std_gauss_th) / std_gauss_th < 0.01

t_peak_gaussian_data = t[np.argmax(np.abs(field_data))]
print("t_peak_th = ", t_peak)
print("t_peak = ", t_peak_gaussian_data)
assert np.abs(t_peak_gaussian_data - t_peak) / t_peak < 0.01


def test_profile_gaussian_3d_cartesian(gaussian):
# - 3D Cartesian case
Expand Down
Loading