-
Notifications
You must be signed in to change notification settings - Fork 36
Add new get_spectrum
and get_duration
utils
#168
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c76890f
Implement `get_spectrum`
AngelFP 551aee9
Implement `get_duration`
AngelFP 57598cb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4bdd0f5
Fix docstring
AngelFP 07673b3
Fix bug
AngelFP 96c43f3
Low-effort ifs
AngelFP 686ffc8
Improve comments
AngelFP c6ea5a5
Test fft
AngelFP 804f4eb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9ce1bce
Use range only when it's not None
AngelFP 8b30a0b
Divide spectrum by 2 when is envelope
AngelFP 8ab54ae
Merge branch 'new_utils' of https://github.com/AngelFP/lasy into new_…
AngelFP 265fe23
Improve FFT implementation
AngelFP b18861b
Fix description
AngelFP 2888b52
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3fa9c66
Fix docstring
AngelFP 26e5a13
Merge branch 'new_utils' of https://github.com/AngelFP/lasy into new_…
AngelFP f96edfe
Shorten line
AngelFP a56c599
Square spectrum
AngelFP 4e26ba8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 651f401
Implement spectrum "mode" + fixes
AngelFP c8eb2e8
Merge branch 'new_utils' of https://github.com/AngelFP/lasy into new_…
AngelFP d9fce81
Add tests
AngelFP 5fd62e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 629a3a1
Fix codeQL
AngelFP 8054d31
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e9559d9
Change output depending on calculation method
AngelFP 6e485b5
Update test
AngelFP 1b0f5ab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 85e4fc1
Fix bug
AngelFP 7511697
Update lasy/utils/laser_utils.py
AngelFP 07c8f71
Update lasy/utils/laser_utils.py
AngelFP e18c7b4
Update lasy/utils/laser_utils.py
AngelFP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import numpy as np | ||
|
||
from lasy.laser import Laser | ||
from lasy.profiles.gaussian_profile import GaussianProfile | ||
from lasy.utils.laser_utils import get_spectrum, compute_laser_energy, get_duration | ||
|
||
|
||
def get_gaussian_profile(): | ||
# Cases with Gaussian laser | ||
wavelength = 0.8e-6 | ||
pol = (1, 0) | ||
laser_energy = 1.0 # J | ||
t_peak = 0.0e-15 # s | ||
tau = 30.0e-15 # s | ||
w0 = 5.0e-6 # m | ||
profile = GaussianProfile(wavelength, pol, laser_energy, w0, tau, t_peak) | ||
|
||
return profile | ||
|
||
|
||
def get_gaussian_laser(dim): | ||
# - Cylindrical case | ||
if dim == "rt": | ||
lo = (0e-6, -60e-15) | ||
hi = (25e-6, +60e-15) | ||
npoints = (100, 100) | ||
else: # dim == "xyt": | ||
lo = (-25e-6, -25e-6, -60e-15) | ||
hi = (+25e-6, +25e-6, +60e-15) | ||
npoints = (100, 100, 100) | ||
return Laser(dim, lo, hi, npoints, get_gaussian_profile()) | ||
|
||
|
||
|
||
def test_laser_analysis_utils(): | ||
"""Test the different laser analysis utilities in both geometries.""" | ||
for dim in ["xyt", "rt"]: | ||
laser = get_gaussian_laser(dim) | ||
|
||
# Check that energy computed from spectrum agrees with `compute_laser_energy`. | ||
spectrum, omega = get_spectrum( | ||
laser.grid, dim, is_envelope=True, omega0=laser.profile.omega0 | ||
) | ||
d_omega = omega[1] - omega[0] | ||
spectrum_energy = np.sum(spectrum) * d_omega | ||
energy = compute_laser_energy(dim, laser.grid) | ||
np.testing.assert_approx_equal(spectrum_energy, energy, significant=10) | ||
|
||
# Check that laser duration agrees with the given one. | ||
tau_rms = get_duration(laser.grid, dim) | ||
np.testing.assert_approx_equal( | ||
2 * tau_rms, laser.profile.long_profile.tau, significant=3 | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_laser_analysis_utils() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.