### F-distribution Explanation and Example Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Explains the F-statistic, its degrees of freedom, and provides an example of drawing samples from the F-distribution and interpreting the results. ```APIDOC ## F-distribution ### Description The F statistic is used to compare in-group variances to between-group variances. Its distribution depends on the sampling and is a function of the respective degrees of freedom. ### Degrees of Freedom - **dfnum**: The number of samples minus one (between-groups degrees of freedom). - **dfden**: The sum of the number of samples in each group minus the number of groups (within-groups degrees of freedom). ### Example Calculation An example from Glantz[1], pp 47-40, involving two groups (children of diabetics and controls) with fasting blood glucose measurements. The F statistic is calculated to test the null hypothesis that parental diabetic status does not affect children's blood glucose levels. ### Draw Samples from the Distribution ```python import numpy as np dfnum = 1. # between group degrees of freedom dfden = 48. # within groups degrees of freedom s = np.random.f(dfnum, dfden, 1000) ``` ### Lower Bound for Top 1% of Samples ```python # Assuming 's' is the array of samples from np.random.f # The lower bound for the top 1% is the 990th element (index 989) if sorted # Or more generally, the 10th element from the end print(np.sort(s)[-10]) # Example output: 7.61988120985 ``` ### Interpretation If the measured F statistic (e.g., 36.01) exceeds the lower bound for the top 1% of samples (e.g., 7.62), the null hypothesis is rejected at the 1% significance level. ``` -------------------------------- ### MethodTM Parameter Setup Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Configures MethodTM to use specific transfer maps for different element types. ```python class MethodTM: """The class creates a transfer map for elements that depend on user-defined parameters ("parameters"). By default, the parameters = {"global": TransferMap}, which means that all elements will have linear transfer maps. You can also specify different transfer maps for any type of element. Example: -------- # use linear matrices for all elements except Sextupole which will have nonlinear kick map (KickTM) method = MethodTM() method.global_method = TransferMap method.params[Sextupole] = KickTM # All elements are assigned matrices of the second order. # For elements for which there are no matrices of the second order are assigned default matrices, e.g. linear matrices. method2 = MethodTM() method2.global_method = SecondTM """ def create_tm(self, element): pass def set_tm(self, element, method): pass ``` -------------------------------- ### MethodTM and SecondTM Initialization Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Demonstrates the initialization of MethodTM and SecondTM classes, setting global methods and default matrices. ```python method2 = MethodTM() method2.global_method = SecondTM ``` -------------------------------- ### Estimate CSR Start Index Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/cpbd/csr/index.rst.txt This method estimates the starting index for CSR calculations to optimize performance by discarding trajectory regions that do not contribute to the effect. It tests a subset of points along the reference trajectory against a minimum threshold. ```python def estimate_start_index(self, i, traj, w_min, beta, i_min=1000, n_test=10): """Estimates the index of the first trajectory point for CSR computation.""" # Logic to test w <= w_min for n_test points if i < i_min: return 0 # Implementation details for index estimation return estimated_index ``` -------------------------------- ### Execute Genesis 1.3 v4 Simulation Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/adaptors/genesis4/index.html Demonstrates how to initialize a launcher and execute a Genesis 1.3 v4 simulation using the Ocelot adaptor. ```python from ocelot.adaptors.genesis4 import get_genesis4_launcher, run_genesis4 # Initialize the launcher launcher = get_genesis4_launcher(launcher_program='genesis4') # Execute simulation with a GenesisInput object # run_genesis4(inp_object, launcher) ``` -------------------------------- ### GET /distributions/zipf Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Draws samples from a Zipf distribution. ```APIDOC ## GET /distributions/zipf ### Description Draws samples from a Zipf distribution (zeta distribution) where frequency is inversely proportional to rank. ### Method GET ### Endpoint /distributions/zipf ### Parameters #### Query Parameters - **a** (float) - Required - The distribution parameter (must be greater than 1). - **size** (int/tuple) - Optional - The output shape of the samples. ### Response #### Success Response (200) - **samples** (ndarray) - An array of drawn samples from the Zipf distribution. ``` -------------------------------- ### POST /ocelot/simulation/prepare Source: https://ocelot-collab-docu.readthedocs.io/en/latest/genindex.html Initializes simulation processes and configures physics processors for beam dynamics and radiation calculations. ```APIDOC ## POST /ocelot/simulation/prepare ### Description Initializes the specified simulation component or physics processor, such as SpaceCharge, CSR, or Wake modules. ### Method POST ### Endpoint /ocelot/simulation/prepare ### Parameters #### Request Body - **component** (string) - Required - The simulation component to prepare (e.g., SpaceCharge, CSR, Wake) - **config** (object) - Optional - Configuration parameters for the processor ### Request Example { "component": "SpaceCharge", "config": { "method": "standard" } } ### Response #### Success Response (200) - **status** (string) - Initialization status - **processor_id** (string) - Unique identifier for the initialized processor #### Response Example { "status": "success", "processor_id": "sc_001" } ``` -------------------------------- ### Generate Power Distribution Samples and Visualize Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Demonstrates generating samples from a power distribution using np.random.power and visualizing the histogram against the theoretical probability density function using Matplotlib. ```python import numpy as np import matplotlib.pyplot as plt a = 5. samples = 1000 s = np.random.power(a, samples) count, bins, ignored = plt.hist(s, bins=30) x = np.linspace(0, 1, 100) y = a*x**(a-1.) normed_y = samples*np.diff(bins)[0]*y plt.plot(x, normed_y) plt.show() ``` -------------------------------- ### GET /distributions/weibull Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Draws samples from a Weibull distribution. ```APIDOC ## GET /distributions/weibull ### Description Draws samples from a 1-parameter Weibull distribution, used for modeling extreme value problems. ### Method GET ### Endpoint /distributions/weibull ### Parameters #### Query Parameters - **a** (float) - Required - The shape parameter of the distribution (must be non-negative). - **size** (int/tuple) - Optional - The output shape of the samples. ### Response #### Success Response (200) - **samples** (ndarray) - An array of drawn samples from the Weibull distribution. ``` -------------------------------- ### GET /get_envelope Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Calculates Twiss parameters from a ParticleArray. ```APIDOC ## GET /get_envelope ### Description Computes Twiss parameters based on the distribution of a ParticleArray. ### Method GET ### Endpoint /get_envelope ### Parameters #### Query Parameters - **p_array** (ParticleArray) - Required - The particle array to analyze. - **tws_i** (Twiss) - Optional - Design Twiss parameters. - **bounds** (list) - Optional - Bounds in units of std(p_array.tau()). ### Response #### Success Response (200) - **twiss** (Twiss) - The calculated Twiss parameters. ``` -------------------------------- ### Apply SmoothBeam process to a lattice Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Demonstrates how to initialize the SmoothBeam process, configure the number of particles per slice, and add it to a Navigator instance for a specific lattice element. ```python navi = Navigator(lat) smooth = SmoothBeam() smooth.mslice = 10000 navi.add_physics_process(smooth, start=elem, stop=elem) ``` -------------------------------- ### Start Background Process in Python Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.common.html Launches a given command as a background process. The command should ideally be provided as a string, preferably enclosed in triple quotes for clarity. ```python from ocelot.common.py_func import background command = "ls -l" # Example command background(command) ``` -------------------------------- ### GET /ocelot/rad/bmrad/noncentral_chisquare Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Draws samples from a noncentral chi-square distribution. ```APIDOC ## GET /ocelot/rad/bmrad/noncentral_chisquare ### Description Draws samples from a noncentral chi-square distribution, which is a generalization of the chi-square distribution. ### Method GET ### Endpoint /ocelot/rad/bmrad/noncentral_chisquare ### Parameters #### Query Parameters - **df** (float) - Required - Degrees of freedom, must be > 0. - **nonc** (float) - Required - Non-centrality, must be non-negative. - **size** (int/tuple) - Optional - Output shape. ### Request Example GET /ocelot/rad/bmrad/noncentral_chisquare?df=3.0&nonc=1.5 ### Response #### Success Response (200) - **out** (ndarray) - Drawn samples from the noncentral chi-square distribution. #### Response Example { "samples": [2.4, 3.1, 1.8] } ``` -------------------------------- ### GET /ocelot.cpbd.high_order.verlet Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Performs a single step of Verlet integration. ```APIDOC ## GET ocelot.cpbd.high_order.verlet ### Description Calculates the next state (q, p) using the Verlet integration method. ### Parameters #### Query Parameters - **vec_x** (array) - Required - Current state vector - **step** (float) - Required - Step size - **h** (float) - Required - Curvature - **k1** (float) - Required - Quadrupole strength - **k2** (float) - Required - Sextupole strength - **beta** (float) - Optional - Beta parameter - **g_inv** (float) - Optional - Inverse g parameter ### Response #### Success Response (200) - **state** (array) - Updated state vector ``` -------------------------------- ### Manage Physics Processes with Navigator Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Shows how to use the Navigator class to add physics processes to a lattice. This allows for the simulation of effects like Wake fields or SpaceCharge between specific elements. ```python from ocelot.cpbd.beam import Navigator # Initialize navigator with a lattice navi = Navigator(lattice) # Add a physics process between two elements navi.add_physics_proc(space_charge_proc, elem_start, elem_end) # Retrieve all active processes procs = navi.get_phys_procs() ``` -------------------------------- ### Initialize SectionLattice and Calculate Twiss Parameters Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.utils.html Demonstrates the initialization of a SectionLattice object and the calculation of Twiss parameters for a given lattice sequence. This is essential for tracking particle beams through defined sections. ```python from ocelot.utils.section_track import SectionLattice # Initialize lattice with sequence and initial Twiss parameters lattice = SectionLattice(sequence=my_sequence, tws0=initial_tws) # Calculate Twiss parameters for the whole lattice twiss_list = lattice.calculate_twiss(tws0=initial_tws) ``` -------------------------------- ### GET /optics/wave/dfldomain_check Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/optics/wave/index.html Utility function to validate wave domains. ```APIDOC ## GET /optics/wave/dfldomain_check ### Description Checks the validity of the provided wave domains. ### Method GET ### Endpoint /optics/wave/dfldomain_check ### Parameters #### Query Parameters - **domains** (object) - Required - The domain configuration to check - **both_req** (boolean) - Optional - Flag to require both domains ### Request Example { "domains": "td", "both_req": false } ### Response #### Success Response (200) - **status** (string) - Validation result ``` -------------------------------- ### Sample Binomial Distribution with NumPy Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Demonstrates how to draw samples from a binomial distribution using NumPy. Includes a basic coin flip simulation and a real-world probability estimation for oil exploration wells. ```python import numpy as np # Basic coin flip simulation: 10 trials, 0.5 probability, 1000 samples n, p = 10, 0.5 s = np.random.binomial(n, p, 1000) # Real-world example: Probability of 0 successes in 9 wells with 0.1 success rate # Running 20,000 trials to estimate probability prob_zero_success = sum(np.random.binomial(9, 0.1, 20000) == 0) / 20000.0 ``` -------------------------------- ### GET /ocelot/get_current Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.html Calculates the beam current from a given ParticleArray. ```APIDOC ## GET /ocelot/get_current ### Description Calculates beam current from a particleArray object. ### Method GET ### Parameters #### Query Parameters - **p_array** (ParticleArray) - Required - The particle array to analyze. - **num_bins** (int) - Optional - Number of bins for calculation, default 200. ### Response #### Success Response (200) - **s** (np.array) - Beam positions in [m]. - **I** (np.array) - Beam currents in [A]. ``` -------------------------------- ### Initialize Ocelot Beamline Elements Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Examples of initializing standard beamline elements such as SBend, Sextupole, and Undulator within the Ocelot framework. ```python from ocelot.cpbd.elements import SBend, Sextupole, Undulator, TDCavity # Initialize a sector bending magnet bend = SBend(l=1.0, angle=0.1, k1=0.5) # Initialize a sextupole sext = Sextupole(l=0.2, k2=10.0) # Initialize an undulator und = Undulator(lperiod=0.02, nperiods=100, Kx=1.5) # Initialize a transverse deflecting cavity td_cav = TDCavity(l=0.5, freq=2.8e9, v=0.05, phi=90.0) ``` -------------------------------- ### GET /twiss Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/cpbd/optics/index.html Calculates Twiss parameters for a given lattice. ```APIDOC ## GET /twiss ### Description Calculates Twiss parameters for the provided lattice. ### Method GET ### Endpoint /twiss ### Parameters #### Query Parameters - **lattice** (object) - Required - The lattice structure - **tws0** (object) - Optional - Initial Twiss parameters - **nPoints** (int) - Optional - Number of points ### Response #### Success Response (200) - **twiss_params** (object) - Calculated Twiss parameters ``` -------------------------------- ### GET /beam/get_current Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/cpbd/beam/index.html Calculates the beam current from a ParticleArray object. ```APIDOC ## GET /beam/get_current ### Description Calculates beam current from particleArray by binning particles. ### Method GET ### Endpoint /beam/get_current ### Parameters #### Query Parameters - **p_array** (object) - Required - The ParticleArray instance. - **num_bins** (int) - Optional - Number of bins for current calculation (default: 200). - **charge** (float) - Optional - Charge of the macro-particle. ### Response #### Success Response (200) - **s** (array) - Beam positions [m]. - **I** (array) - Beam currents [A]. ``` -------------------------------- ### Sample from Laplace Distribution with Python Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Demonstrates how to draw samples from a Laplace distribution and visualize the results against the probability density function and a Gaussian distribution for comparison. ```python import numpy as np import matplotlib.pyplot as plt loc, scale = 0., 1. s = np.random.laplace(loc, scale, 1000) # Histogram and PDF count, bins, ignored = plt.hist(s, 30, density=True) x = np.arange(-8., 8., .01) pdf = np.exp(-abs(x-loc)/scale)/(2.*scale) plt.plot(x, pdf) # Gaussian comparison g = (1/(scale * np.sqrt(2 * np.pi)) * np.exp(-(x - loc)**2 / (2 * scale**2))) plt.plot(x, g) ``` -------------------------------- ### Implement Custom Physics Process Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Demonstrates how to create a custom physics process by inheriting from PhysProc. Users must implement the prepare, apply, and finalize methods to define behavior during tracking. ```python from ocelot.cpbd.physics_proc import PhysProc class MyProcess(PhysProc): def prepare(self, lat): # Initialization logic pass def apply(self, p_array, dz): # Logic applied at every step pass def finalize(self, *args, **kwargs): # Cleanup logic pass ``` -------------------------------- ### GET /distributions/wald Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Draws samples from a Wald (Inverse Gaussian) distribution. ```APIDOC ## GET /distributions/wald ### Description Draws samples from the Wald distribution, often used to model Brownian motion and reliability. ### Method GET ### Endpoint /distributions/wald ### Parameters #### Query Parameters - **mean** (float) - Required - The mean of the distribution. - **scale** (float) - Required - The scale parameter of the distribution. - **size** (int/tuple) - Optional - The output shape of the samples. ### Response #### Success Response (200) - **samples** (ndarray) - An array of drawn samples from the Wald distribution. ``` -------------------------------- ### GET /random/pareto Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Draws samples from a Pareto II (Lomax) distribution. ```APIDOC ## GET /random/pareto ### Description Draws samples from a Pareto II (Lomax) distribution with a specified shape parameter. ### Method GET ### Endpoint /random/pareto ### Parameters #### Query Parameters - **a** (float) - Required - Shape of the distribution (must be positive). - **size** (int/tuple) - Optional - Output shape of the samples. ### Request Example GET /random/pareto?a=3.0&size=10 ### Response #### Success Response (200) - **samples** (array) - Drawn samples from the Pareto distribution. #### Response Example { "samples": [1.2, 0.5, 3.1, ...] } ``` -------------------------------- ### Configure Navigator Physics Processes Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Shows how to add a physics process to a Navigator instance to be applied between specific elements in a lattice. ```python from ocelot.cpbd.elements import Navigator # Assuming 'lattice' and 'physics_proc' are defined navi = Navigator(lattice) navi.add_physics_proc(physics_proc, elem1, elem2) ``` -------------------------------- ### Sample from Logistic Distribution with Python Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Demonstrates how to generate samples from a logistic distribution using specified location and scale parameters and visualize the distribution via a histogram. ```python import numpy as np import matplotlib.pyplot as plt loc, scale = 10, 1 s = np.random.logistic(loc, scale, 10000) count, bins, ignored = plt.hist(s, bins=50) ``` -------------------------------- ### GET /random/normal Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Draws samples from a parameterized normal (Gaussian) distribution. ```APIDOC ## GET /random/normal ### Description Draws samples from a normal (Gaussian) distribution defined by a mean (loc) and standard deviation (scale). ### Method GET ### Endpoint /random/normal ### Parameters #### Query Parameters - **loc** (float) - Required - Mean of the distribution. - **scale** (float) - Required - Standard deviation of the distribution (must be non-negative). - **size** (int/tuple) - Optional - Output shape of the samples. ### Request Example GET /random/normal?loc=0&scale=0.1&size=1000 ### Response #### Success Response (200) - **samples** (array) - Drawn samples from the normal distribution. #### Response Example { "samples": [0.01, -0.05, 0.02, ...] } ``` -------------------------------- ### GET /ocelot.cpbd.high_order.t_nnn Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Calculates the second-order transport matrix for a beam element. ```APIDOC ## GET ocelot.cpbd.high_order.t_nnn ### Description Returns a second-order matrix for beam tracking using variables: x, px/p0, y, py/p0, tau, dE/(p0c). ### Parameters #### Query Parameters - **L** (float) - Required - Length in [m] - **h** (float) - Required - Curvature in [1/m] - **k1** (float) - Required - Quadrupole strength in [1/m^2] - **k2** (float) - Required - Sextupole strength in [1/m^3] - **energy** (float) - Optional - Energy in [GeV] ### Response #### Success Response (200) - **matrix** (numpy.ndarray) - Second order matrix with shape (6, 6, 6) ``` -------------------------------- ### Moga Class Initialization and Parameter Setting (Python) Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/cpbd/moga/index.html Initializes the Moga class with bounds and optional weights, and provides a method to set various genetic algorithm parameters like population size, number of generations, and logging options. ```python class Moga: def __init__(self, bounds, weights=-1.0, -1.0): # ... initialization logic ... pass def set_params(self, n_pop=None, weights=None, elite=None, penalty=None, n_gen=None, seed=None, log_print=None, log_file=False, plt_file=False): # ... parameter setting logic ... pass ``` -------------------------------- ### Sample Hypergeometric Distribution Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Demonstrates how to draw samples from a hypergeometric distribution to simulate selecting items without replacement. The example shows how to configure the number of good and bad items along with the sample size. ```python import numpy as np from matplotlib.pyplot import hist # Define parameters: 100 good, 2 bad, 10 samples ngood, nbad, nsamp = 100, 2, 10 # Draw 1000 samples s = np.random.hypergeometric(ngood, nbad, nsamp, 1000) # Visualize the distribution hist(s) ``` -------------------------------- ### GET /calc_wigner Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/optics/wave/index.html Calculates the Wigner distribution for a given radiation field. ```APIDOC ## GET /calc_wigner ### Description Calculates the Wigner distribution of a radiation field using multi-processing. ### Method GET ### Endpoint /calc_wigner ### Parameters #### Query Parameters - **field** (object) - Required - The radiation field - **method** (string) - Optional - Calculation method (default: 'mp') ### Response #### Success Response (200) - **wigner** (object) - The calculated Wigner distribution. ``` -------------------------------- ### GET /ocelot/gui/genesis_plot/plot_gen_out_evo Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/gui/genesis_plot/index.html Plots the evolution of specified parameters over the undulator length. ```APIDOC ## GET /ocelot/gui/genesis_plot/plot_gen_out_evo ### Description Visualizes the evolution of electron beam and radiation parameters as a function of undulator length. ### Method GET ### Endpoint ocelot.gui.genesis_plot.plot_gen_out_evo ### Parameters #### Path Parameters - **g** (GenesisOutput) - Required - The Genesis output object. #### Query Parameters - **params** (list) - Optional - Parameters to track (e.g., 'el_energy', 'rad_pow_en_log'). - **figsize** (int) - Optional - Figure size. - **legend** (bool) - Optional - Whether to show the legend. ### Request Example plot_gen_out_evo(g=my_genesis_obj, params=['el_energy', 'rad_pow_en_log']) ### Response #### Success Response (200) - **figure** (matplotlib.figure) - The generated evolution plot. ``` -------------------------------- ### Initialize Ocelot Particle and Elements Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/index.html Demonstrates how to instantiate common Ocelot objects such as a Particle, an Undulator, and different types of Bending Magnets. ```python from ocelot import Particle, Undulator, Bend, RBend, SBend # Initialize a particle p = Particle(x=0.0, y=0.0, E=1.0) # Initialize an undulator und = Undulator(lperiod=0.025, nperiods=100, Kx=1.0, Ky=1.0) # Initialize bending magnets bend = Bend(l=1.0, angle=0.1) rbend = RBend(l=1.0, angle=0.1) sbend = SBend(l=1.0, angle=0.1) ``` -------------------------------- ### GET /ocelot/adaptors/genesis/read_out_file_stat Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Reads statistical information from Genesis simulation output files. ```APIDOC ## GET /ocelot/adaptors/genesis/read_out_file_stat ### Description Reads statistical info of Genesis simulations from a standard project directory structure. ### Method GET ### Endpoint ocelot.adaptors.genesis.read_out_file_stat ### Parameters #### Query Parameters - **proj_dir** (str) - Required - Project directory path - **stage** (str) - Required - Stage number - **run_inp** (list) - Optional - List of genesis runs to process - **param_inp** (list) - Optional - List of output parameters to process ### Response #### Success Response (200) - **output** (GenStatOutput) - Statistical output object ``` -------------------------------- ### LocalLauncher Class API Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/utils/launcher/index.rst.txt Documentation for the LocalLauncher class, used for launching simulations locally. ```APIDOC ## LocalLauncher Class ### Description Manages the preparation, launching, and collection of simulations executed on the local machine. ### Method - **prepare(self)** Prepares the local environment for simulation. - **outputfile(self, filename)** Returns the expected output file path for a given filename. - **launch(self)** Launches the simulation locally. - **collect(self, inputDir, outputDir, pattern='*')** Collects simulation output files from a directory. ``` -------------------------------- ### GET /ocelot/rad/bmrad/randint Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Returns random integers from low (inclusive) to high (exclusive). ```APIDOC ## GET /ocelot/rad/bmrad/randint ### Description Return random integers from the discrete uniform distribution in the half-open interval [low, high). ### Method GET ### Endpoint /ocelot/rad/bmrad/randint ### Parameters #### Query Parameters - **low** (int) - Required - Lowest integer to be drawn. - **high** (int) - Optional - One above the largest integer to be drawn. - **size** (tuple) - Optional - Output shape. - **dtype** (string) - Optional - Desired dtype of the result. ### Response #### Success Response (200) - **out** (ndarray) - Array of random integers. ### Response Example { "result": [1, 0, 0, 0, 1] } ``` -------------------------------- ### NewLauncher Class API Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/utils/launcher/index.rst.txt Documentation for the NewLauncher class, potentially used for specific simulation types like MOGA. ```APIDOC ## NewLauncher Class ### Description A launcher class, possibly for MOGA or temporary simulations. ### Methods - **prepare(self)** Prepares the environment for the simulation. - **launch(self)** Launches the simulation. - **collect(self, inputDir, outputDir, pattern='*')** Collects simulation output files from a directory. ``` -------------------------------- ### GET /api/ocelot/current Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Calculates the beam current profile for a specified particle array. ```APIDOC ## GET /api/ocelot/current ### Description Computes the current profile of a particle array object within the Ocelot framework. ### Method GET ### Endpoint /api/ocelot/current ### Parameters #### Query Parameters - **particle_array_id** (string) - Required - The ID of the particle array to process. ### Request Example { "particle_array_id": "pa_882" } ### Response #### Success Response (200) - **current_profile** (array) - List of current values along the longitudinal coordinate. #### Response Example { "current_profile": [0.5, 1.2, 5.0, 1.1], "unit": "Amperes" } ``` -------------------------------- ### Configure MethodTM for Element Transfer Maps Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Demonstrates how to initialize MethodTM to define global or element-specific transfer map strategies. This allows users to mix linear and non-linear (e.g., KickTM) maps within a single lattice simulation. ```python method = MethodTM() method.global_method = TransferMap method.params[Sextupole] = KickTM method2 = MethodTM() method2.global_method = SecondTM ``` -------------------------------- ### GET /ocelot/rad/bmrad/chisquare Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Draws samples from a chi-square distribution based on degrees of freedom. ```APIDOC ## GET /ocelot/rad/bmrad/chisquare ### Description Draws samples from a chi-square distribution. When df independent random variables, each with standard normal distributions, are squared and summed, the resulting distribution is chi-square. ### Method GET ### Endpoint ocelot.rad.bmrad.chisquare(df, size=None) ### Parameters #### Query Parameters - **df** (float) - Required - Number of degrees of freedom, must be > 0. - **size** (int or tuple) - Optional - Output shape of the drawn samples. ### Response #### Success Response (200) - **out** (ndarray or scalar) - Drawn samples from the parameterized chi-square distribution. ### Response Example { "samples": [1.89, 9.00, 3.13, 5.62] } ``` -------------------------------- ### Configure Transfer Map Method Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.html Demonstrates how to instantiate a MethodTM object and customize the tracking method for specific beamline elements, such as assigning a nonlinear KickTM to Sextupole elements while maintaining linear maps for others. ```python from ocelot.cpbd.optics import MethodTM, TransferMap, KickTM from ocelot.cpbd.elements import Sextupole # Use linear matrices for all elements except Sextupole method = MethodTM() method.global_method = TransferMap method.params[Sextupole] = KickTM ``` -------------------------------- ### GET /api/ocelot/envelope Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/index.rst.txt Retrieves the beam envelope parameters for a given lattice configuration. ```APIDOC ## GET /api/ocelot/envelope ### Description Calculates and retrieves the beam envelope based on the provided lattice and beam parameters. ### Method GET ### Endpoint /api/ocelot/envelope ### Parameters #### Query Parameters - **lattice_id** (string) - Required - The identifier of the magnetic lattice to analyze. - **beam_id** (string) - Required - The identifier of the beam object. ### Request Example { "lattice_id": "lattice_001", "beam_id": "beam_001" } ### Response #### Success Response (200) - **envelope_data** (object) - The calculated envelope parameters including sigma_x, sigma_y, and beta functions. #### Response Example { "sigma_x": 0.001, "sigma_y": 0.001, "status": "success" } ``` -------------------------------- ### Sample from Geometric Distribution using NumPy Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Demonstrates how to draw samples from a geometric distribution and calculate the frequency of success in the first trial. ```python import numpy as np z = np.random.geometric(p=0.35, size=10000) success_rate = (z == 1).sum() / 10000. ``` -------------------------------- ### GET /spectrum Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Computes the frequency and Fourier transform of 1D sample data. ```APIDOC ## GET /spectrum ### Description Computes the frequency and Fourier transform of input 1D sample data. ### Method GET ### Endpoint ocelot.cpbd.track.spectrum ### Parameters #### Query Parameters - **data1D** (array) - Required - 1D sample data. ### Response #### Success Response (200) - **result** (tuple) - Returns frequency and Fourier transform. ``` -------------------------------- ### Generate and Visualize Uniform Distribution Samples Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Demonstrates how to draw samples from a uniform distribution within a specified range and visualize the result using a histogram and the probability density function. ```python import numpy as np import matplotlib.pyplot as plt # Draw samples s = np.random.uniform(-1, 0, 1000) # Validate range print(np.all(s >= -1)) print(np.all(s < 0)) # Visualize count, bins, ignored = plt.hist(s, 15, density=True) plt.plot(bins, np.ones_like(bins), linewidth=2, color='r') plt.show() ``` -------------------------------- ### SshMpiLauncher Class API Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/utils/launcher/index.rst.txt Documentation for the SshMpiLauncher class, used for launching MPI simulations over SSH. ```APIDOC ## SshMpiLauncher Class ### Description Manages the launching of MPI simulations remotely via SSH. ### Methods - **prepare(self)** Prepares the environment for the simulation over SSH. - **launch(self)** Launches the MPI simulation via SSH. - **collect(self, inputDir, outputDir, pattern='*')** Collects simulation output files from a remote directory. ``` -------------------------------- ### Get Lattice Map Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Retrieves a map for a given lattice and spatial discretization. ```APIDOC ## POST /api/lattice/get_map ### Description Retrieves a map for a given lattice with specified spatial discretization. ### Method POST ### Endpoint /api/lattice/get_map ### Parameters #### Request Body - **lattice** (MagneticLattice) - Required - The magnetic lattice object. - **dz** (float) - Required - The spatial step size for the map. - **navi** (bool) - Required - Navigation flag (purpose may vary). ### Request Example ```json { "lattice": "lattice_object_representation", "dz": 0.1, "navi": true } ``` ### Response #### Success Response (200) - **lattice_map** (object) - The generated map data for the lattice. #### Response Example ```json { "lattice_map": {"map_data": "..."} } ``` ``` -------------------------------- ### Initialize Navigator with SmoothBeam Physics Process Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.html This snippet demonstrates how to initialize a Navigator object with a SmoothBeam physics process. The SmoothBeam process is configured with a specified mslice and then added to the navigator for a given lattice element. ```python from ocelot.cpbd.navigator import Navigator from ocelot.cpbd.physics_proc import SmoothBeam lat = MagneticLattice() avi = Navigator(lat) smooth = SmoothBeam() smooth.mslice = 10000 avi.add_physics_process(smooth, start=elem, stop=elem) # elem is the lattice element where you want to apply smoothing ``` -------------------------------- ### GET /ocelot.cpbd.high_order.scipy_track_in_field Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Tracks a particle through a magnetic field using scipy integration. ```APIDOC ## GET ocelot.cpbd.high_order.scipy_track_in_field ### Description Tracks a particle through a magnetic field and returns the trajectory coordinates and field values. ### Parameters #### Path Parameters - **y0** (array) - Required - Initial state vector - **l** (float) - Required - Length of tracking - **N** (int) - Required - Number of steps - **energy** (float) - Required - Energy of particle in [GeV] - **mag_field** (function) - Required - Function returning Bx, By, Bz given X, Y, Z ### Response #### Success Response (200) - **result** (array) - Array of length N*9 containing coordinates and magnetic fields [x, x', y, y', z, dE/pc, Bx, By, Bz, ...] ``` -------------------------------- ### GET /ocelot/rad/transfer_function/get_transfer_function Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/rad/transfer_function/index.html Retrieves the transfer function associated with a specific radiation element. ```APIDOC ## GET /ocelot/rad/transfer_function/get_transfer_function ### Description Retrieves the transfer function for a given radiation element. ### Method GET ### Endpoint /ocelot/rad/transfer_function/get_transfer_function ### Parameters #### Query Parameters - **element** (object) - Required - The radiation element object for which to retrieve the transfer function. ### Request Example { "element": "" } ### Response #### Success Response (200) - **transfer_function** (object) - The calculated transfer function for the element. #### Response Example { "transfer_function": "" } ``` -------------------------------- ### Generate and Verify Normal Distribution Samples Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Demonstrates how to draw random samples from a normal distribution using NumPy, verify the statistical properties (mean and standard deviation), and visualize the results with Matplotlib. ```python import numpy as np import matplotlib.pyplot as plt # Draw samples mu, sigma = 0, 0.1 s = np.random.normal(mu, sigma, 1000) # Verify mean and std print(abs(mu - np.mean(s))) print(abs(sigma - np.std(s, ddof=1))) # Plot histogram and PDF count, bins, ignored = plt.hist(s, 30, density=True) plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins - mu)**2 / (2 * sigma**2) ), linewidth=2, color='r') plt.show() ``` -------------------------------- ### Prepare Physics Process (Python) Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.html Method called when a physics process is added to the Navigator class. ```python def prepare(_lat_): """method is called at the moment of Physics Process addition to Navigator class. Parameters lat – Returns """ pass ``` -------------------------------- ### GET /genesis/output/spectrum Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/adaptors/genesis/index.html Calculates and retrieves the on-axis spectrum from Genesis output files. ```APIDOC ## GET /genesis/output/spectrum ### Description Calculates the on-axis spectrum at every position along the undulator using the GenesisOutput object. ### Method GET ### Endpoint /genesis/output/spectrum ### Parameters #### Query Parameters - **mode** (string) - Optional - 'mid' for on-axis power or 'int' for transversely integrated power. - **npad** (integer) - Optional - Padding factor for resolution improvement. ### Response #### Success Response (200) - **spec** (array) - Calculated spectrum data. #### Response Example { "spec": [0.001, 0.005, 0.012] } ``` -------------------------------- ### GET /response-matrix/measure Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/cpbd/orbit_correction/index.html Measures the response matrix for a given orbit and lattice configuration. ```APIDOC ## GET /response-matrix/measure ### Description Computes the response matrix by measuring the effect of correctors on the beam orbit. ### Method GET ### Endpoint /response-matrix/measure ### Parameters #### Query Parameters - **orbit** (object) - Required - The current orbit object. - **lattice** (object) - Required - The magnetic lattice configuration. ### Request Example GET /response-matrix/measure?orbit=current_orbit&lattice=main_lattice ### Response #### Success Response (200) - **matrix** (array) - The calculated response matrix. #### Response Example { "matrix": [[0.1, 0.0], [0.0, 0.1]] } ``` -------------------------------- ### Track List Creation (Python) Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.html Creates a list of Pxy (particle coordinates and momenta) from given arrays. ```python def create_track_list(_x_array_, _y_array_, _p_array_, _energy=0.0): """the function create list of Pxy""" pass ``` -------------------------------- ### OCELOT Launcher Methods Source: https://ocelot-collab-docu.readthedocs.io/en/latest/genindex.html Methods for launching simulation jobs. ```APIDOC ## OCELOT Launcher Methods ### Description Methods for launching simulation jobs, particularly for local execution. ### Method - **outputfile()**: Specifies the output file for a simulation job. - **Class**: `LocalLauncher` - **Module**: `ocelot.utils.launcher` ``` -------------------------------- ### estimate_start_index Method Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.cpbd.html Estimates the starting index for CSR effect computation to optimize performance. ```APIDOC ## Method estimate_start_index ### Description Estimates the index of the first trajectory point from which CSR effects should be computed, optimizing computation time by discarding regions where w <= wmin. ### Parameters - **i** (int): Iteration index. - **traj** (ndarray): Reference trajectory along which CSR forces are calculated. - **w_min** (float): Leftmost edge of the longitudinal bunch binning. - **beta** (float): Relativistic factor. - **i_min** (int, optional): Minimum iteration index. Defaults to 1000. - **n_test** (int, optional): Number of points along the trajectory to test. Defaults to 10. ### Returns - **estimated_start_index** (int): The estimated start index, which is always less than or equal to the real one. ``` -------------------------------- ### prepare Function Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/cpbd/csr/index.html Prepares the trajectory in rectangular coordinates and calculates the CSR start position. ```APIDOC ## prepare Function ### Description Calculates the trajectory in rectangular coordinates and determines the `z_csr_start`. ### Method N/A (Function definition) ### Endpoint N/A (Internal function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Parameters * **lat** (Magnetic Lattice) - The magnetic lattice object used for calculations. ``` -------------------------------- ### Class: SimInfo Source: https://ocelot-collab-docu.readthedocs.io/en/latest/autoapi/ocelot/utils/sim_info/index.html Represents the general simulation configuration settings. ```APIDOC ## CLASS SimInfo ### Description Manages simulation settings and parameters. ### Parameters - **n** (int) - Optional - Number of particles or steps, defaults to 10. ### Usage Example ```python from ocelot.utils.sim_info import SimInfo sim = SimInfo(n=100) ``` ``` -------------------------------- ### Draw and Visualize Gamma Distribution Samples Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.rad.html Shows how to generate samples from a Gamma distribution and visualize the results using Matplotlib and SciPy. ```python import matplotlib.pyplot as plt import scipy.special as sps shape, scale = 2., 2. # mean=4, std=2*sqrt(2) s = np.random.gamma(shape, scale, 1000) count, bins, ignored = plt.hist(s, 50, density=True) y = bins**(shape-1)*(np.exp(-bins/scale) / (sps.gamma(shape)*scale**shape)) plt.plot(bins, y, linewidth=2, color='r') plt.show() ``` -------------------------------- ### GET /ocelot/adaptors/madx/exponential Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/ocelot.adaptors.html Draws samples from an exponential distribution based on a provided scale parameter. ```APIDOC ## GET /ocelot/adaptors/madx/exponential ### Description Draws samples from an exponential distribution with a specified scale parameter. The exponential distribution is a continuous analogue of the geometric distribution. ### Method GET ### Endpoint ocelot.adaptors.madx.exponential ### Parameters #### Query Parameters - **scale** (float) - Optional - The scale parameter (beta), must be non-negative. Default is 1.0. - **size** (int or tuple) - Optional - Output shape of the drawn samples. ### Request Example { "scale": 1.0, "size": [2, 2] } ### Response #### Success Response (200) - **out** (ndarray) - Drawn samples from the parameterized exponential distribution. #### Response Example { "samples": [0.5, 1.2, 0.8, 2.1] } ``` -------------------------------- ### Database Creation Source: https://ocelot-collab-docu.readthedocs.io/en/latest/_sources/autoapi/ocelot/utils/db/index.rst.txt Provides functions for creating and testing new database instances. ```APIDOC ## create_db ### Description Creates a new database file with the specified name. ### Method Function ### Endpoint N/A (Python function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python create_db(dbname='my_database.db') ``` ### Response #### Success Response (200) None (operation is performed in place) #### Response Example None ## test_new_tunings ### Description Tests the functionality of creating new tunings in the database. ### Method Function ### Endpoint N/A (Python function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python test_new_tunings(dbname='my_database.db') ``` ### Response #### Success Response (200) None (operation is performed in place) #### Response Example None ## test_new_action ### Description Tests the functionality of creating new actions in the database. ### Method Function ### Endpoint N/A (Python function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python test_new_action(dbname='my_database.db') ``` ### Response #### Success Response (200) None (operation is performed in place) #### Response Example None ## test_add_action_parameters ### Description Tests the functionality of adding parameters to actions in the database. ### Method Function ### Endpoint N/A (Python function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python test_add_action_parameters(dbname='my_database.db') ``` ### Response #### Success Response (200) None (operation is performed in place) #### Response Example None ```