toolbox_scs.misc.bunch_pattern

Toolbox for SCS.

Various utilities function to quickly process data measured at the SCS instruments.

Copyright (2019) SCS Team.

Module Contents

Functions

npulses_has_changed(run[, loc, run_mnemonics])

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

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

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

extractBunchPattern([bp_table, key, runDir])

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

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

toolbox_scs.misc.bunch_pattern.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.bunch_pattern.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.bunch_pattern.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.bunch_pattern.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.bunch_pattern.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