<jupyter_start><jupyter_text>Tutorial: Using the SPB-SFX ModuleThis tutorial demonstrates the use of the [SPB-SFX instance](https://github.com/twguest/FELpy/blob/master/felpy/model/beamlines/exfel_spb/exfel_spb.py) of the [felpy.model.instrument](https://github.com/twguest/FELpy/blob/master/felpy/model/core/instrument.py) class in the design and analysis of a virtual diagnostic experiment.In this tutorial we will demonstrate:1. Loading an instance of the SPB-SFX module2. Modification of the beamline3. Propagation of a wpg.wavefront in .h5 file format (i.e. from Genesis or otherwise)4. Simple analysis of the wavefront using native properties of the [FELpy wavefront](https://github.com/twguest/FELpy/blob/master/felpy/model/core/wavefront.py) class  Loading the SPB-SFX ModuleThe [SPB-SFX methods](https://github.com/twguest/FELpy/blob/master/felpy/model/beamlines/exfel_spb/methods.py) module contains functionality to load the SPB-SFX model.Given that we may wish to load/save different configurations of the instrumennt, the setup_spb module initilisases due to a parameter.json file.An example parameters file is located in the [/data/](https://github.com/twguest/FELpy/blob/master/felpy/data/params/exfel_spb.json) folder.The setup_spb function allows an easy way to setup the beamline based on numerous typical parameters relativing to mirrors, etc.:<jupyter_code>from felpy.model.beamlines.exfel_spb.methods import setup_spb

spb = setup_spb(parameter_file = "/gpfs/exfel/data/user/guestt/FELpy/felpy/data/params/spb-sfx_nkb_GM_4.98.json",
                theta_KB = 5e-03, ### KB mirror angle                
                theta_HOM = 5.0e-03, ### tunnel mirror angle
                crop = ['HOM1', 'NVE']) ### crop b/w two elements

## pprint(spb.params)<jupyter_output>Initialising Single Particle Beamline<jupyter_text>Beamline Modification<jupyter_code>from felpy.model.tools import propagation_parameters

spb.elements

spb.edit_propagation_parameters("d1", propagation_parameters(1,1,1,1, mode = 'quadratic'))

bl = spb.bl<jupyter_output>List of Elements: ['d1', 'HOM1', 'd2', 'HOM2', 'd3', 'NKB_PSlit', 'd4', 'NHE_error', 'NHE', 'd5', 'NVE_error', 'NVE']<jupyter_text>Propagating a WPG Wavefront  Loading a Wavefront<jupyter_code>from felpy.model.wavefront import Wavefront
from wpg.wpg_uti_wf import plot_intensity_map
h5_file_location = "/gpfs/exfel/data/group/wp72/SPP/source_to_wavefront/scripts/14_1_Sase1.WPG.h5"  ## an example file

wfr = Wavefront()
wfr.load_hdf5(h5_file_location)

wfr.set_electric_field_representation('frequency')
plot_intensity_map(wfr)
print(wfr)<jupyter_output>The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.<jupyter_text>Propagating a Wavefront<jupyter_code>from felpy.model.beamline import Beamline
from wpg.optical_elements import Drift
from felpy.model.tools import propagation_parameters

bl = Beamline()
bl.append(Drift(1), propagation_parameters(1,1,1,1, mode = 'fresnel'))
bl.propagate(wfr)

plot_intensity_map(wfr)
#bl.propagate_sequential(wfr)<jupyter_output><empty_output><jupyter_text>Simple Analysis using [FELpy.wavefront](https://github.com/twguest/FELpy/blob/master/felpy/model/core/wavefront.py)<jupyter_code>from felpy.utils.vis_utils import Grids
grid = Grids(scale = 2, global_aspect = 2.5)
grid.create_grid(n = 2, m = 2, sharex = True, sharey = False)
grid.set_fontsize(18)
grid.add_global_colorbar("intensity")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11009697661152311, 'fraction_numerical': 0.01426126640045636, 'mean_word_length': 5.68, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '516542', 'license': 'Apache-2.0', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1219, 'n_words': 267, 'path': 'docs/source/examples/tutorial_spb-sfx/tutorial_spb-sfx.ipynb', 'repo_name': 'twguest/FELPy', 'size': '3506'}