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

Longitudinal profile from data: need check to avoid NaN values #253

Open
n01r opened this issue Jul 11, 2024 · 4 comments
Open

Longitudinal profile from data: need check to avoid NaN values #253

n01r opened this issue Jul 11, 2024 · 4 comments

Comments

@n01r
Copy link

n01r commented Jul 11, 2024

I was playing around with the laser creation to check something about the noise level / lowest intensity based on wavelength bandwidth and number of samples in time. I found that specific combinations just give warnings and produce NaN values.
A proper check with a user-facing error message would probably be helpful to avoid that someone accidentally hits such a combination.

(Click tab below to expand function definition)

create_laser
import lasy
from lasy.laser import Laser
from lasy.profiles import CombinedLongitudinalTransverseProfile
from lasy.profiles.longitudinal import LongitudinalProfileFromData, GaussianLongitudinalProfile
from lasy.profiles.transverse import GaussianTransverseProfile
import numpy as np
from scipy.constants import c

def create_laser(third_order_dispersion_kfs3,lambda_bw_nm=200,time_window_fs=1000,time_points=3000):
    """
    """
    
    wavelength     = 815e-9  # Laser wavelength in meters
    pol            = (1,0)   # Linearly polarized in the x direction
    laser_energy   = 20      # Energy of the laser pulse in joules
    waist          = 2.12e-6 # Waist of the laser pulse in meters
    tau            = 29.8e-15 # Pulse duration of the laser in seconds (i.e. 35 fs FWHM, tau=FWHM_I/1.1741)
    t_peak         = 0.0     # Location of the peak of the laser pulse in time
    TOD            = third_order_dispersion_kfs3*1e3*(1e-15)**3 # 80k fs^3

    dimensions     = 'rt'              # Use cylindrical geometry
    #lo             = (0,-15*tau)        # Lower bounds of the simulation box
    #hi             = (5*waist,15*tau)  # Upper bounds of the simulation box
    lo             = (0,-time_window_fs/2*1e-15)        # Lower bounds of the simulation box
    hi             = (5*waist,time_window_fs/2*1e-15)  # Upper bounds of the simulation box
    num_points     = (300,time_points)        # Number of points in each dimension

    # Generate laser spectral intensity, including TOD, with numpy
    #lambd = np.linspace(765e-9, 865e-9, num_points[-1])
    lambda_half_bw = lambda_bw_nm*1e-9/2
    lambd = np.linspace(wavelength-lambda_half_bw, wavelength+lambda_half_bw, num_points[-1])
    omega = 2*np.pi*c/lambd
    omega0 = 2*np.pi*c/wavelength
    intensity = np.exp( -(omega-omega0)**2*tau**2/2 )
    phase = TOD*(omega-omega0)**3/6 # From the definition of the TOD

    # Create corresponding laser profile, by combining
    # a longitudinal defined by the above spectral info
    # and a transverse Gaussian profile
    long_profile = LongitudinalProfileFromData(
        {'datatype': 'spectral',
         'axis': lambd,
         'intensity': intensity,
         'phase': phase, 
         'dt': (hi[-1] - lo[-1])/num_points[-1]},
        lo=lo[-1], 
        hi=hi[-1])
    #   focal distance from calculation below
    #trans_profile = GaussianTransverseProfile(waist, wavelength=wavelength, z_foc=22.205039999826518e-6)
    trans_profile = GaussianTransverseProfile(waist, wavelength=wavelength, z_foc=0)
    laser_profile = CombinedLongitudinalTransverseProfile(wavelength, pol, laser_energy, long_profile, trans_profile)

    # Define laser on a grid
    laser = Laser(dimensions,lo,hi,num_points,laser_profile)
    
    return laser
points_in_t = [1499,1500,1501]
TOD_kfs3 = 0
lambda_bw_nm = 1000

fig, ax = plt.subplots(1,1)

for i in np.arange(len(points_in_t)):
    
    laser = create_laser(
        third_order_dispersion_kfs3=TOD_kfs3,
        time_window_fs=2000,
        time_points=points_in_t[i],
        lambda_bw_nm=lambda_bw_nm
    )
    
    ax.plot(
        laser.profile.long_profile.time,
        laser.profile.long_profile.temporal_intensity,
        label=f"{points_in_t[i]}"
    )
    
ax.set_yscale("log")
ax.set_xlabel(r'Time (fs)')
ax.set_ylabel(r'Intensity Contrast $I/I_0$')
ax.set_title(f'TOD = {TOD_kfs3}k fs³  |  bw(λ) = {lambda_bw_nm} nm')

ax.legend(loc="best")

image
The orange line with 1500 sample points is missing

Warning

/global/homes/m/mgarten/.conda/envs/warpx-pm-postproc/lib/python3.12/site-packages/lasy/profiles/longitudinal/longitudinal_profile_from_data.py:90: RuntimeWarning: invalid value encountered in sqrt
freq_amplitude = np.sqrt(freq_intensity)

freq_amplitude = np.sqrt(freq_intensity)

@koesterf
Copy link

Hi @n01r,

I have a question: you constructed the laser pulse using spectral information, is it possible to get the temporal information of the pulse directly from LASY and vice versa ?

@n01r
Copy link
Author

n01r commented Aug 19, 2024

Hi @koesterf,

Since spectral information is often what is directly measured in experiments I was playing around with the method to construct a pulse from such information. Are you asking if, in general, one can extract temporal information of a laser pulse from a LASY Laser object?

I was pointing out here in this issue that one could run into parameter combinations that create only NaNs and the user might not know why.

@koesterf
Copy link

Hi @n01r

Are you asking if, in general, one can extract temporal information of a laser pulse from a LASY Laser object?

Yes, I want to know if one make a longitudinal profile using spectral method, then is it possible to get the temporal information after full pulse construction directly from LASY internal utility. And similarly, if the laser pulse longitudinal profile is constructed with temporal information is it possible to get spectral information directly using LASY internal utility.

I saw something like "get_spectral_field()" unitility spectral and "get_temporal_field" utility temporal

@n01r
Copy link
Author

n01r commented Aug 19, 2024

@koesterf, I'd suggest we move this over to the issue you already opened #286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants