pyLaserPulse.utils¶
Created on Mon Jul 25 00:35:01 2022
@author: james feehan
General functions.
Functions
Calculate V, mode_ref_index, D, beta_2 for hexagonal-lattice PCF. |
|
|
Calculate the refractive index as a function of wavelength for fused silica |
|
Check that all items in key_list are keys in dict d. |
|
Use the convolution theorem to do faster convolutions. |
|
Find the value in 'container' which is closest to 'search_value' |
|
Calculate the energy spectral density and the power spectral density from real-valued spectrum. |
|
Return the full width at 1/e^2 of the maximum pulse duration. |
|
Return the width of a distribution in array data. |
|
Interpolate single-column data from a text file onto a grid axis. |
|
Load parallel and perpendicular Raman contributions from text files and interpolate onto the time-domain grid. |
|
Load active dopant cross-section data. |
|
Load a file containing some target power spectral density. |
|
Swap the halves of an even-element array over a given axis. |
- pyLaserPulse.utils.check_dict_keys(key_list, d, param_name)¶
Check that all items in key_list are keys in dict d.
- Parameters:
key_list (list) – keys (string) that are expected in dict d.
d (dict)
param_name (string) – Name assigned to dictionary d in caller.
- Raises:
KeyError – Raised if an item in key_list is not in dict d.
- pyLaserPulse.utils.find_nearest(search_value, container)¶
Find the value in ‘container’ which is closest to ‘search_value’
- Parameters:
search_value – Value to look for in container
container – Iterable of numeric values
- Returns:
int – Index in container of value nearest to search_value
int, float, etc. – Value in container closest to search_value
- pyLaserPulse.utils.get_width(axis, data, meas_point=0.5)¶
Return the width of a distribution in array data.
- Parameters:
axis (int) – Axis of data over which the width measurement is taken
data (numpy array) – Distribution whose width is being measured
meas_point (float) – Fraction of maximum value of data at which the width is measured. E.g., meas_point = 0.5 gives FWHM.
- Returns:
Width of the distribution in data measured at meas_point.
- Return type:
float, float64
- pyLaserPulse.utils.get_FWe2M(axis, data)¶
Return the full width at 1/e^2 of the maximum pulse duration.
- Parameters:
axis (int) – Axis of data over which the width measurement is taken
data (numpy array) – Distribution whose width is being measured.
- Returns:
Full-width at 1/e^2 of the distribution in data.
- Return type:
float, float64
- pyLaserPulse.utils.swap_halves(arr, axis=-1)¶
Swap the halves of an even-element array over a given axis. E.g., over the 0th axis of a 1-D array:
- Parameters:
arr (numpy array)
axis (int)
- Returns:
arr, but the halves are swapped: arr[half1:half2] –> arr[half2:half1]
- Return type:
numpy array
- pyLaserPulse.utils.interpolate_data_from_file(filename, axis, axis_scale, data_scale, interp_kind='linear', fill_value='extrapolate', input_log=False, return_log=False)¶
Interpolate single-column data from a text file onto a grid axis.
- Parameters:
filename (string) – Absolute path to the data file
axis (numpy array) – New axis to interpolate onto
axis_scale (float) – Scaling for the new axis
data_scale (float) – Scaling of the data
interp_kind – Specifies the kind of interpolation as a string or as an integer specifying the order of the spline interpolator to use. See documentation for scipy.interpolate.interp1d.
fill_value – if an ndarray (or float), this value will be used to fill in for requested points outside of the data range. Default NaN if not provided If a two-element tuple, the first value is used as a fill value for x_new < x[0] and the second element is usd for x_new > x[-1]. If ‘extrapolate’, then points outside the data range will be extrpolated. This is the default.
input_log (bool) – Needs to be True if the data in the data file has units of dB.
return_log (bool) – If True, returns -1 * np.log(10**(-1 * data / 10))
Returns
array (numpy) – data from filename inteprolated onto axis.
- pyLaserPulse.utils.load_Raman(filename, time_window, dt)¶
Load parallel and perpendicular Raman contributions from text files and interpolate onto the time-domain grid.
- Parameters:
filename (string) – Absolute path to the Raman data file.
time_window (numpy array) – pyLaserPulse.grid.grid.time_window
dt (float) – Resolution of time_window (pyLaserPulse.grid.grid.dt)
Returns
array (numpy) – Raman data from filename interpolated onto time_window.
- pyLaserPulse.utils.load_cross_sections(filename, delimiter, axis, axis_scale, interp_kind='linear')¶
Load active dopant cross-section data.
- Parameters:
filename (string) – Absolute path to the cross section data file
delimiter (string) – Delimiter used in the cross section data file
axis (numpy array) – New wavelength axis to interpolate the data onto. See pyLaserPulse.grid.grid.lambda_window
axis_scale (float) – Scaling for the interpolation axis
interp_kind – See documentation for scipy.interpolate.interp1d
- Returns:
numpy array – absorption cross section data interpolated onto axis
numpy array – emission cross section data interpolated onto axis
list – [min_wavelength, max_wavelength]
Notes
- Expects three-column text file of data formatted as follows:
Wavelength delimiter Emission delimiter Absorption
- pyLaserPulse.utils.load_target_power_spectral_density(energy, repetition_rate, filename, axis, d_axis, axis_scale, background, PSD_scale, interp_kind='linear', fill_value=0, input_log=False)¶
Load a file containing some target power spectral density. use PSD_scale to convert from W/m to mW/nm, etc.
- Parameters:
energy (float) – Energy in Joules
repetition_rate (float)
filename (string) – Absolute path to the data file containing the power spectral density
axis (numpy array) – Axis onto which the data in filename is interpolated. If the data is given as a function of wavelength in the data file, use pyLaserPulse.grid.grid.lambda_window If the data is given as a function of angular frequency in the data file, use pyLaserPulse.grid.grid.omega_window.
d_axis (numpy array) – Resolution of axis
axis_scale (float) – Scaling for axis
background (float) – Background value to subtract
PSD_scale (float) – Scaling for the power spectral density
interp_kind (See scipy.interpolate.interp1d documentation.)
fill_value (See scipy.interpolate.interp1d documentation. Default 0)
input_log (bool) – Needs to be True if the data in filename is logarithmic.
- Returns:
Target power spectral density interpolated onto axis.
- Return type:
numpy array
- pyLaserPulse.utils.get_ESD_and_PSD(lambda_window, spectrum, repetition_rate)¶
Calculate the energy spectral density and the power spectral density from real-valued spectrum. The PSD is normalized to mW/nm.
- Parameters:
lambda_window (numpy array) – Wavelength grid in m. See pyLaserPulse.grid.grid.lambda_window
spectrum (numpy array) – Spectral data
repetition_rate (float) – Repetition rate of the pulse source.
- Returns:
numpy array – Energy spectral density in J/m
numpy array – Power spectral density in W/nm
- pyLaserPulse.utils.Sellmeier(lambda_window, f)¶
Calculate the refractive index as a function of wavelength for fused silica
- Parameters:
lambda_window (numpy array) – Wavelength grid in m. See pyLaserPulse.grid.grid.lambda_window
f (string) – Absolute path to file containing Sellmeier coefficients.
- Returns:
Refractive index as a function of wavelength.
- Return type:
numpy array
- pyLaserPulse.utils.fft_convolve(arr1, arr2)¶
Use the convolution theorem to do faster convolutions.
- Parameters:
arr1 (numpy array)
arr2 (numpy array)
- Returns:
The convolution of arr1 and arr2
- Return type:
numpy array
Notes
arr1 and arr2 must have the same shape
- pyLaserPulse.utils.PCF_propagation_parameters_K_Saitoh(lambda_window, grid_midpoint, omega_window, a, b, c, d, hole_pitch, hole_diam_over_pitch, core_radius, Sellmeier_file)¶
Calculate V, mode_ref_index, D, beta_2 for hexagonal-lattice PCF.
- Parameters:
lambda_window (numpy array) – Wavelength grid in m. See pyLaserPulse.grid.grid.lambda_window
grid_midpoint (int) – Middle index of the time-frequency grid. See pyLaserPulse.grid.grid.midpoint
omega_window (numpy array) – Angular frequency grid in rad Hz. See pyLaserPulse.grid.grid.omega_window
a (numpy array) – 4x4 array. See reference in notes (K. Saitoh)
b (numpy array) – 4x4 array. See reference in notes (K. Saitoh)
c (numpy array) – 4x4 array. See reference in notes (K. Saitoh)
d (numpy array) – 4x4 array. See reference in notes (K. Saitoh)
hole_pitch (float) – Separation of neighbouring air holes in the hexagonal-lattice PCF structure.
hole_diam_over_pitch (float) – Ratio of the air hole diameter to the hole pitch.
core_radius (float) – Appriximate core radius in m
Sellmeier_file (string) – Absolute path to the Sellmeier coefficients. See pyLaserPulse.data.paths.materials.Sellmeier_coefficients.
- Returns:
numpy array – V-number as a function of wavelength
numpy array – Refractive index as a function of wavelength
numpy array – Fibre dispersion in ps / (nm km)
numpy array – Fibre dispersion in s^2 / m
Notes
K. Saitoh et al., “Empirical relations for simple design of photonic crystal fibres”,Opt. Express 13(1), 267–274 (2005).
- pyLaserPulse.utils.Taylor_expansion(coeffs, axis, axis_centre=0)¶
Taylor expansion.
- Parameters:
coeffs (iterable of floats (list, tuple, numpy array)) – Taylor coefficients. Can be obtained from curve data using, e.g., numpy.polyfit.
axis (numpy array) – Axis over which the Taylor expansion is the be calculated.
axis_centre (float) – Centre of axis. Default is zero. The Taylor expansion will be calculated over axis - axis_centre.
Notes
For retrieving Taylor coefficients for dispersion curves, see pyLaserPulse.utils.get_Taylor_coeffs_from_beta2.
- pyLaserPulse.utils.get_Taylor_coeffs_from_beta2(beta_2, grid)¶
Calculate the Taylor coefficients which describe the propagation constant calculated using, e.g., Gloge, Saitoh (depending on what is being simulated).
- Parameters:
beta_2 (numpy array) – Dispersion curve in s^2 / m
grid (pyLaserPulse.grid.grid object)
- Returns:
beta – Complex part of the propagation constant.
- Return type:
numpy array
Notes
Second-order gradient of beta with respect to omega will give the dispersion curve to within the accuracy of the Taylor expansion.
This function could be used for retrieving the Taylor coefficients for, e.g., grating compressors, but analytic formulae should be used instead where available.