Closed bnash closed 2 years ago
I've been working on a refactor with @bruhwiler that changes the LaserPulse and LaserPulseSlice classes to just take a PKDict with all the params as input. No more default parameters or **kwargs. I think this will solve part of this issue.
I'll include more documentation of the LaserPulseClass.
Thoughts?
See issue #40 and it's associated pr #42
This looks great @gurhar1133. I'll try to catch up with your developments soon and offer further comments.
The bug associated with sig_s and related variables must still be addressed.
Sorry I missed that. To clarify, instances of sigs in the __init_\ function of the LaserPulseSlice should actually be tau_fwhm and tau_fwhm should be the input to LaserPulseSlice in place of sig_s?
i.e. in the snippet below, we should be using slice_params.tau_fwhm
instead of slice_params.sig_s
?
ds = 2*numsig*params.slice_params.sig_s/(params.nslice - 1)
self._pulse_pos = -numsig*params.slice_params.sig_s+slice_index*ds
GsnBm.z = params.slice_params.propLen + self._pulse_pos #Longitudinal Position of Waist [m]
GsnBm.xp = 0 #Average Angles of Gaussian Beam at Waist [rad]
GsnBm.yp = 0
GsnBm.avgPhotEn = self.phE #Photon Energy [eV]
GsnBm.pulseEn = params.slice_params.pulseE*np.exp(-self._pulse_pos**2/(2*params.slice_params.sig_s**2))
Also, I will change numsig to be an input param
Assuming a normal (aka Gaussian) longitudinal profile for the laser pulse, the full width at half maximum (FWHM) is larger than the root mean square (RMS) by the factor 2sqrt(2log(2)) = 2.355
Also tau_fwhm is a time quantity with units of seconds, while sig_s is a spatial quantity, presumably with units of meters.
Hence, we have sig_s = slice_params.tau_fwhm * const.c / 2.355
Ok, so calculate sig_s using slice_params.tau_fwhm as you've shown above, then use that value for sigs in the __init_\ ?
tau_fwhm lives in the input_params (aka params) instance of PKDict sig_s lives in the params.slice_params instance of PKDict
You need to make sure that it's impossible for these two values to be set inconsistently. I can imagine a couple of different solutions, but I defer to your judgement.
Minor point: it seems that params = input_params.copy() is unnecessary. Can this be removed?
Maybe we should have a constants module in pykern for things like 2sqrt(2log(2)). What would be its name?
How about sig_s no longer living in the input at all? The user will specify tau_fwhm and sig_s can be calculated from that. Then we avoid inconsistency. And I think you are right that the .copy() can be removed
@robnagler -- this is a good idea. I started to address this problem some time ago in rsbeams. https://github.com/radiasoft/rsbeams/blob/master/rsbeams/rsphysics/rsconst.py
Not wanting to create a dependency on rsbeams, I started to duplicate the solution here, https://github.com/radiasoft/rslaser/blob/master/rslaser/utils/constants.py
Obviously not a good approach on my part, so I think doing it once in pykern is a good idea. One suggested name for 2sqrt(2log(2)) would be TWO_RT_TWO_LN_TWO
@gurhar -- I agree that sig_s could be removed from the input parameters.
These changes have broken a few notebooks that instantiate the LaserPulse class. I'll fix them.
I fixed two example python scripts and several notebooks.
In the LaserPulseSlice init function that creates a Gaussian laser pulse with SRW wavefront objects, the pulse length is given by the parameter sig_s.
However in example notebooks such as here and here, the parameter tau_fwhm is specificed for the pulse length/duration.
Thus, as of now, the default value of sig_s is being used rather than the specified value. This should be converted, and we should document the expected parameters in the laser pulse init function. As of now, the parameters are given by kwargs and not specified. The list of required kwargs should be given in the documentation of the LaserPulse class.
Also, the s location of each slice is rather obscure, depending on numsig which is hardcoded to 3.: ds = 2numsig sig_s/(nslice - 1) Such that s = slice_index * ds
numsig should be pulled out as input parameter to the LaserPulse class.