toolbox_scs.misc

Submodules

Package Contents

Functions

extractBunchPattern([bp_table, key, runDir])

generate the bunch pattern and number of pulses of a source directly from the

get_sase_pId(run[, loc, run_mnemonics, bpt, merge_with])

Returns the pulse Ids of the specified loc during a run.

npulses_has_changed(run[, loc, run_mnemonics])

Checks if the number of pulses has changed during the run for

pulsePatternInfo(data[, plot])

display general information on the pulse patterns operated by SASE1 and SASE3.

repRate([data, runNB, proposalNB, key])

Calculates the pulse repetition rate (in kHz) in sase

is_sase_3(bpt)

Check for prescence of a SASE3 pulse.

is_sase_1(bpt)

Check for prescence of a SASE1 pulse.

is_ppl(bpt)

Check for prescence of pp-laser pulse.

is_pulse_at(bpt, loc)

Check for prescence of a pulse at the location provided.

degToRelPower(x[, theta0])

converts a half-wave plate position in degrees into relative power

positionToDelay(pos[, origin, invert, reflections])

converts a motor position in mm into optical delay in picosecond

delayToPosition(delay[, origin, invert, reflections])

converts an optical delay in picosecond into a motor position in mm

fluenceCalibration(hwp, power_mW, npulses, w0x[, w0y, ...])

Given a measurement of relative powers or half wave plate angles

align_ol_to_fel_pId(ds[, ol_dim, fel_dim, offset, ...])

Aligns the optical laser (OL) pulse Ids to the FEL pulse Ids.

get_undulator_config(run[, park_pos, plot])

Extract the undulator cells configuration from a given run.

Attributes

__all__

toolbox_scs.misc.extractBunchPattern(bp_table=None, key='sase3', runDir=None)[source]

generate the bunch pattern and number of pulses of a source directly from the bunch pattern table and not using the MDL device BUNCH_DECODER. This is inspired by the euxfel_bunch_pattern package, https://git.xfel.eu/gitlab/karaboDevices/euxfel_bunch_pattern Inputs:

bp_table: DataArray corresponding to the mnemonics “bunchPatternTable”.

If None, the bunch pattern table is loaded using runDir.

key: str, [‘sase1’, ‘sase2’, ‘sase3’, ‘scs_ppl’] runDir: extra-data DataCollection. Required only if bp_table is None.

Outputs:

bunchPattern: DataArray containing indices of the sase/laser pulses for each train npulses: DataArray containing the number of pulses for each train matched: 2-D DataArray mask (trainId x 2700), True where ‘key’ has pulses

toolbox_scs.misc.get_sase_pId(run, loc='sase3', run_mnemonics=None, bpt=None, merge_with=None)[source]

Returns the pulse Ids of the specified loc during a run. If the number of pulses has changed during the run, it loads the bunch pattern table and extract all pulse Ids used.

Parameters:
  • run (extra_data.DataCollection) – DataCollection containing the data.

  • loc (str) – The location where to check: {‘sase1’, ‘sase3’, ‘scs_ppl’}

  • run_mnemonics (dict) – the mnemonics for the run (see menonics_for_run)

  • bpt (2D-array) – The bunch pattern table. Used only if the number of pulses has changed. If None, it is loaded on the fly.

  • merge_with (xarray.Dataset) – dataset that may contain the bunch pattern table to use in case the number of pulses has changed. If merge_with does not contain the bunch pattern table, it is loaded and added as a variable ‘bunchPatternTable’ to merge_with.

Returns:

pulseIds – the pulse ids at the specified location. Returns None if the mnemonic is not in the run.

Return type:

np.array

toolbox_scs.misc.npulses_has_changed(run, loc='sase3', run_mnemonics=None)[source]

Checks if the number of pulses has changed during the run for a specific location loc (=’sase1’, ‘sase3’, ‘scs_ppl’ or ‘laser’) If the source is not found in the run, returns True.

Parameters:
  • run (extra_data.DataCollection) – DataCollection containing the data.

  • loc (str) – The location where to check: {‘sase1’, ‘sase3’, ‘scs_ppl’}

  • run_mnemonics (dict) – the mnemonics for the run (see menonics_for_run)

Returns:

ret – True if the number of pulses has changed or the source was not found, False if the number of pulses did not change.

Return type:

bool

toolbox_scs.misc.pulsePatternInfo(data, plot=False)[source]

display general information on the pulse patterns operated by SASE1 and SASE3. This is useful to track changes of number of pulses or mode of operation of SASE1 and SASE3. It also determines which SASE comes first in the train and the minimum separation between the two SASE sub-trains.

Inputs:

data: xarray Dataset containing pulse pattern info from the bunch decoder MDL: {‘sase1, sase3’, ‘npulses_sase1’, ‘npulses_sase3’} plot: bool enabling/disabling the plotting of the pulse patterns

Outputs:

print of pulse pattern info. If plot==True, plot of the pulse pattern.

toolbox_scs.misc.repRate(data=None, runNB=None, proposalNB=None, key='sase3')[source]

Calculates the pulse repetition rate (in kHz) in sase according to the bunch pattern and assuming a grid of 4.5 MHz.

Inputs:

data: xarray Dataset containing pulse pattern, needed if runNB is none runNB: int or str, run number. Needed if data is None proposal: int or str, proposal where to find the run. Needed if data is None key: str in [sase1, sase2, sase3, scs_ppl], source for which the

repetition rate is calculated

Output:

f: repetition rate in kHz

toolbox_scs.misc.is_sase_3(bpt)[source]

Check for prescence of a SASE3 pulse.

Parameters:

bpt (numpy array, xarray DataArray) – The bunch pattern data.

Returns:

boolean – true if SASE3 pulse is present.

Return type:

numpy array, xarray DataArray

toolbox_scs.misc.is_sase_1(bpt)[source]

Check for prescence of a SASE1 pulse.

Parameters:

bpt (numpy array, xarray DataArray) – The bunch pattern data.

Returns:

boolean – true if SASE1 pulse is present.

Return type:

numpy array, xarray DataArray

toolbox_scs.misc.is_ppl(bpt)[source]

Check for prescence of pp-laser pulse.

Parameters:

bpt (numpy array, xarray DataArray) – The bunch pattern data.

Returns:

boolean – true if pp-laser pulse is present.

Return type:

numpy array, xarray DataArray

toolbox_scs.misc.is_pulse_at(bpt, loc)[source]

Check for prescence of a pulse at the location provided.

Parameters:
  • bpt (numpy array, xarray DataArray) – The bunch pattern data.

  • loc (str) – The location where to check: {‘sase1’, ‘sase3’, ‘scs_ppl’}

Returns:

boolean – true if a pulse is present at loc.

Return type:

numpy array, xarray DataArray

toolbox_scs.misc.degToRelPower(x, theta0=0)[source]

converts a half-wave plate position in degrees into relative power between 0 and 1. Inputs:

x: array-like positions of half-wave plate, in degrees theta0: position for which relative power is zero

Output:

array-like relative power

toolbox_scs.misc.positionToDelay(pos, origin=0, invert=True, reflections=1)[source]

converts a motor position in mm into optical delay in picosecond Inputs:

pos: array-like delay stage motor position origin: motor position of time zero in mm invert: bool, inverts the sign of delay if True reflections: number of bounces in the delay stage

Output:

delay in picosecond

toolbox_scs.misc.delayToPosition(delay, origin=0, invert=True, reflections=1)[source]

converts an optical delay in picosecond into a motor position in mm Inputs:

delay: array-like delay in ps origin: motor position of time zero in mm invert: bool, inverts the sign of delay if True reflections: number of bounces in the delay stage

Output:

delay in picosecond

toolbox_scs.misc.fluenceCalibration(hwp, power_mW, npulses, w0x, w0y=None, train_rep_rate=10, fit_order=1, plot=True, xlabel='HWP [%]')[source]

Given a measurement of relative powers or half wave plate angles and averaged powers in mW, this routine calculates the corresponding fluence and fits a polynomial to the data.

Parameters:
  • hwp (array-like (N)) – angle or relative power from the half wave plate

  • power_mW (array-like (N)) – measured power in mW by powermeter

  • npulses (int) – number of pulses per train during power measurement

  • w0x (float) – radius at 1/e^2 in x-axis in meter

  • w0y (float, optional) – radius at 1/e^2 in y-axis in meter. If None, w0y=w0x is assumed.

  • train_rep_rate (float) – repetition rate of the FEL, by default equals to 10 Hz.

  • fit_order (int) – order of the polynomial fit

  • plot (bool) – Plot the results if True

  • xlabel (str) – xlabel for the plot

  • Output

  • ------

  • F (ndarray (N)) – fluence in mJ/cm^2

  • fit_F (ndarray) – coefficients of the fluence polynomial fit

  • E (ndarray (N)) – pulse energy in microJ

  • fit_E (ndarray) – coefficients of the fluence polynomial fit

toolbox_scs.misc.align_ol_to_fel_pId(ds, ol_dim='ol_pId', fel_dim='sa3_pId', offset=0, fill_value=np.nan)[source]

Aligns the optical laser (OL) pulse Ids to the FEL pulse Ids. The new OL coordinates are calculated as ds[ol_dim] + ds[fel_dim][0] + offset. The ol_dim is then removed, and if the number of OL and FEL pulses are different, the missing values are replaced by fill_value (NaN by default).

Parameters:
  • ds (xarray.Dataset) – Dataset containing both OL and FEL dimensions

  • ol_dim (str) – name of the OL dimension

  • fel_dim (str) – name of the FEL dimension

  • offset (int) – offset added to the OL pulse Ids.

  • fill_value ((scalar or dict-like, optional)) – Value to use for newly missing values. If a dict-like, maps variable names to fill values. Use a data array’s name to refer to its values.

  • Output

  • ------

  • ds – The newly aligned dataset

toolbox_scs.misc.get_undulator_config(run, park_pos=62.0, plot=True)[source]

Extract the undulator cells configuration from a given run. The gap size and K factor as well as the magnetic chicane delay and photon energy of colors 1, 2 and 3 are compiled into an xarray Dataset.

Note: This function looks at run control values, it does not reflect any change of values during the run. Do not use to extract configuration when scanning the undulator.

Parameters:
  • run (EXtra-Data DataCollection) – The run containing the undulator information

  • park_pos (float, optional) – The parked position of a cell (i.e. when fully opened)

  • plot (bool, optional) – If True, plot the undulator cells configuration

Returns:

cells – The resulting dataset of the undulator configuration

Return type:

xarray Dataset

toolbox_scs.misc.__all__[source]