Main Entrypoints¶
Harmonic Analysis¶
Entrypoint Hole in One¶
Entrypoint Measure Optics¶
Created on 11/07/18
author: | Lukas Malina |
---|
Top-level script, which computes various lattice optics parameters from frequency spectra
-
class
measure_optics.
InputFiles
(files_to_analyse)[source]¶ Stores the input files, provides methods to gather quantity specific data
- Public methods:
- get_dpps(plane) get_joined_frame(plane, columns, zero_dpp=False, how=’inner’) get_columns(frame, column) get_data(frame, column)
-
dpps
(plane)[source]¶ Gathers measured DPPs from input files corresponding to given plane :param plane: “X” or “Y”
Returns: numpy array of DPPs
-
static
get_columns
(frame, column)[source]¶ Returns list of columns of frame corresponding to column in original files :param frame: joined frame :param column: name of column in original files
Returns: list of columns
-
get_data
(frame, column)[source]¶ Returns data in columns of frame corresponding to column in original files :param frame: joined frame :param column: name of column in original files
Returns: data in numpy array corresponding to column in original files
-
joined_frame
(plane, columns, zero_dpp=False, how='inner')[source]¶ Constructs merged DataFrame from InputFiles :param plane: “X” or “Y” :param columns: list of columns from input files :param zero_dpp: if True merges only zero-dpp files, default is False :param how: way of merging: ‘inner’ (intersection) or ‘outer’ (union), default is ‘inner’
Returns: merged DataFrame from InputFiles
-
measure_optics.
measure_optics
(input_files, measure_input)[source]¶ Main function to compute various lattice optics parameters from frequency spectra :param input_files: InputFiles object containing frequency spectra files (linx/y) :param measure_input: OpticsInput object containing analysis settings
Returns:
Amplitude Detuning¶
Entrypoint Amplitude Detuning Analysis¶
Entrypoint for amplitude detuning analysis.
This module provides functionality to run amplitude detuning analysis with additionally getting BBQ data from timber, averaging and filtering this data and subtracting it from the measurement data.
Furthermore, the orthogonal distance regression is utilized to get a linear fit from the measurements.
Also, plotting functionality is integrated, for the amplitude detuning as well as for the bbq data.
author: | Joschua Dilly |
---|
-
amplitude_detuning_analysis.
analyse_with_bbq_corrections
(*args, **kwargs)[source]¶ Create amplitude detuning analysis with BBQ correction from timber data.
Keyword Arguments: - Required --
- beam (int) -- Which beam to use. Flags: --beam
- kickac_path (str) -- Location of the kickac file Flags: --kickac
- plane (str) -- Plane of the kicks. ‘X’ or ‘Y’. Flags: --plane Choices: XY
- Optional --
- ampdet_plot_out (str) -- Save the amplitude detuning plot here. Flags: --ampdetplot
- ampdet_plot_show -- Show the amplitude detuning plot.
Flags: --ampdetplotshow
Action:
store_true
- ampdet_plot_xmax (float) -- Maximum action (x-axis) in amplitude detuning plot. Flags: --ampdetplotxmax
- ampdet_plot_xmin (float) -- Minimum action (x-axis) in amplitude detuning plot. Flags: --ampdetplotxmin
- ampdet_plot_ymax (float) -- Maximum tune (y-axis) in amplitude detuning plot. Flags: --ampdetplotymax
- ampdet_plot_ymin (float) -- Minimum tune (y-axis) in amplitude detuning plot. Flags: --ampdetplotymin
- bbq_out (str) -- Output location to save bbq data as tfs-file Flags: --bbqout
- bbq_plot_full -- Plot the full bqq data with interval as lines.
Flags: --bbqplotfull
Action:
store_true
- bbq_plot_out (str) -- Save the bbq plot here. Flags: --bbqplot
- bbq_plot_show -- Show the bbq plot.
Flags: --bbqplotshow
Action:
store_true
- bbq_plot_two -- Two plots for the bbq plot.
Flags: --bbqplottwo
Action:
store_true
- debug -- Activates Debug mode
Flags: --debug
Action:
store_true
- fine_cut (float) -- Cut (i.e. tolerance) of the tune for the fine cleaning. Flags: --finecut
- fine_window (int) -- Length of the moving average window. (# data points) Flags: --finewindow
- kickac_out (str) -- If given, writes out the modified kickac file Flags: --kickacout
- label (str) -- Label to identify this run. Flags: --label
- logfile (str) -- Logfile if debug mode is active. Flags: --logfile
- timber_in -- Fill number of desired data or path to presaved tfs-file Flags: --timberin
- timber_out (str) -- Output location to save fill as tfs-file Flags: --timberout
- tune_cut (float) -- Cuts for the tune. For BBQ cleaning. Flags: --tunecut
- tune_x (float) -- Horizontal Tune. For BBQ cleaning. Flags: --tunex
- tune_x_max (float) -- Horizontal Tune minimum. For BBQ cleaning. Flags: --tunexmax
- tune_x_min (float) -- Horizontal Tune minimum. For BBQ cleaning. Flags: --tunexmin
- tune_y (float) -- Vertical Tune. For BBQ cleaning. Flags: --tuney
- tune_y_max (float) -- Vertical Tune minimum. For BBQ cleaning. Flags: --tuneymax
- tune_y_min (float) -- Vertical Tune minimum. For BBQ cleaning. Flags: --tuneymin
- window_length (int) -- Length of the moving average window. (# data points)
Flags: --window
Default:
20
-
amplitude_detuning_analysis.
plot_bbq_data
(*args, **kwargs)[source]¶ Plot BBQ wrapper.
Keyword Arguments: - Required --
- input -- BBQ data as data frame or tfs file. Flags: --in
- Optional --
- interval (str) -- x_axis interval that was used in calculations. Flags: --interval
- output (str) -- Save figure to this location. Flags: --out
- show -- Show plot.
Flags: --show
Action:
store_true
- two_plots -- Plot two axis into the figure.
Flags: --two
Action:
store_true
- xmax (str) -- Upper x-axis limit. (yyyy-mm-dd HH:mm:ss.mmm) Flags: --xmax
- xmin (str) -- Lower x-axis limit. (yyyy-mm-dd HH:mm:ss.mmm) Flags: --xmin
- ymax (float) -- Upper y-axis limit. Flags: --ymax
- ymin (float) -- Lower y-axis limit. Flags: --ymin
Fullresponse Creation¶
Entrypoint Fullresponse Pandas¶
Provides a response generation wrapper. The response matrices can be either created by response_madx or analytically via TwissResponse.
author: | Joschua Dillys |
---|
-
generate_fullresponse_pandas.
create_response
(*args, **kwargs)[source]¶ Entry point for creating pandas-based response matrices.
The response matrices can be either created by response_madx or TwissResponse.
Keyword Arguments: - Required --
- model_dir (str) -- Path to the model directory. Flags: [‘-m’, ‘--model_dir’]
- outfile_path (str) -- Name of fullresponse file. Flags: [‘-o’, ‘--outfile’]
- Optional --
- creator (str) -- Create either with madx or analytically from twiss file.
Flags: --creator
Choices: (‘madx’, ‘twiss’)
Default:
madx
- debug -- Print debug information.
Flags: --debug
Action:
store_true
- delta_k (float) -- Delta K1L to be applied to quads for sensitivity matrix (madx-only).
Flags: [‘-k’, ‘--deltak’]
Default:
2e-05
- optics_params (str) -- List of parameters to correct upon (e.g. BBX BBY; twiss-only). Flags: --optics_params
- variable_categories -- List of the variables classes to use.
Flags: --variables
Default:
['MQM', 'MQT', 'MQTL', 'MQY']
Correction¶
Entrypoint Correct Iterative¶
Iterative Correction Scheme.
The response matrices \(R_{O}\) for the observables \(O\) (e.g. BBX, MUX, …) are loaded from a file and then the equation
is being solved for \(\delta var\) via a chosen method (at the moment only numpys pinv, which creates a pseudo-inverse via svd is used).
The response matrices are hereby merged into one matrix for all observables to solve vor all \(\delta var\) at the same time.
To normalize the observables to another weigths
(W) can be applied.
Furthermore, an errorcut
, specifying the maximum errorbar for a BPM to be used, and
modelcut
, specifying the maximum distance between measurement and model for a BPM to be used,
can be defined. Data from BPMs outside of those cut-values will be discarded.
These cuts are defined for each observable separately.
After each iteration the model variables are changed by \(-\delta var\) and the observables are recalculated by Mad-X. (1) is then solved again.
author: | Lukas Malina, Joschua Dilly |
---|
- Possible problems and notes:
- do we need error cut, when we use error-based weights? probably not anymore
- error-based weights default? likely - but be carefull with low tune errors vs
- svd cut in pseudoinverse
- manual creation of pd.DataFrame varslist, deltas? maybe
- tunes in tfs_pandas single value or a column?
- Minimal strength removed
- Check the output files and when they are written
- There should be some summation/renaming for iterations
- For two beam correction
- The two beams can be treated separately until the calcultation of correction
- Values missing in the response (i.e. correctors of the other beam) shall be
- treated as zeros
- Missing a part that treats the output from LSA
-
global_correct_iterative.
global_correction
(*args, **kwargs)[source]¶ Do the global correction. Iteratively.
Keyword Arguments: - Required --
- meas_dir -- Path to the directory containing the measurement files. Flags: --meas_dir
- model_dir -- Path to the dir containing the model (twiss.dat or twiss_elements.dat) to use. Flags: --model_dir
- Optional --
- beta_file_name -- Prefix of the beta file to use. E.g.: getkmodbeta
Flags: --beta_file_name
Default:
getbeta
- debug -- Print debug information.
Flags: --debug
Action:
store_true
- eps (float) -- (Not implemented yet) Convergence criterion.
If \(<|\Delta(PARAM \cdot WEIGHT)|> < \epsilon\), stop iteration.
Flags: --eps
Default:
None
- errorcut (float) -- Reject BPMs whose error bar is higher than the corresponding input. Input in order of optics_params. Flags: --error_cut
- fullresponse_path -- Path to the fullresponse binary file. If not given, calculates the response analytically. Flags: --fullresponse
- max_iter (int) -- Maximum number of correction re-iterations to perform.
A value of 0 means the correction is calculated once
(like in the old days).
Flags: --max_iter
Default:
3
- method (str) -- Optimization method to use.
Flags: --method
Choices: [‘pinv’, ‘omp’]
Default:
pinv
- min_corrector_strength (float) -- Minimum (absolute) strength of correctors.
Flags: --min_corrector_strength
Default:
0.
- modelcut (float) -- Reject BPMs whose deviation to the model is higher than the correspoding input. Input in order of optics_params. Flags: --model_cut
- n_correctors (int) -- Maximum number of correctors to use. (Method: ‘omp’) Flags: --n_correctors
- optics_file -- Path to the optics file to use, usually modifiers.madx. If not present will default to model_path/modifiers.madx Flags: --optics_file
- optics_params (str) -- List of parameters to correct upon (e.g. BBX BBY)
Flags: --optics_params
Default:
['MUX', 'MUY', 'BBX', 'BBY', 'NDX', 'Q']
- output_path -- Path to the directory where to write the output files,
will default to the --meas input path.
Flags: --output_dir
Default:
None
- svd_cut (float) -- Cutoff for small singular values of the pseudo inverse. (Method: ‘pinv’)
Singular values smaller than
\(rcond \cdot largest_singular_value\) are set to zero
Flags: --svd_cut
Default:
0.01
- use_errorbars -- If True, it will take into account the measured errorbars in the correction.
Flags: --use_errorbars
Action:
store_true
- variable_categories -- List of names of the variables classes to use.
Flags: --variables
Default:
['MQM', 'MQT', 'MQTL', 'MQY']
- virt_flag -- If true, it will use virtual correctors.
Flags: --virt_flag
Action:
store_true
- weights (float) -- Weights to apply to each measured quantity. Input in order of optics_params. Flags: --weights
Cleaning¶
Entrypoint Isolation Forest¶
Created on May 4, 2018 Application of Isolation Forest algorithm for the diagnostics of BPM signal. Original paper: Liu, Fei Tony, Ting, Kai Ming and Zhou, Zhi-Hua. “Isolation forest.” Data Mining, 2008. ICDM‘08. Eighth IEEE International Conference.
@author: Elena Fol
-
iforest_for_bpms.
remove_bpms_from_file
(paths, bad_bpm_names, plane)[source]¶ Writes a backup of the original .lin files (e.g .linx --> .linx.notcleaned) and removes the BPNs identified by iForest as bad. :param paths: original lin files :param bad_bpm_names: list of the names of bad BPMs identified by iForest
MADX¶
Entrypoint Madx Wrapper¶
module: | madx.madx_wrapper |
---|
Runs MADX with a file or a string as an input, it processes @required macros. If defined, writes the processed MADX script and logging output into files. TODO: write tests
-
madx_wrapper.
resolve_and_run_file
(input_file, output_file=None, log_file=None, madx_path='/home/travis/build/pylhc/Beta-Beat.src/madx/bin/madx-linux64-gnu', cwd=None)[source]¶ Runs MADX in a subprocess.
-
madx_wrapper.
input_file
¶ MADX input file
-
madx_wrapper.
output_file
¶ If given writes resolved MADX script.
-
madx_wrapper.
log_file
¶ If given writes MADX logging output.
-
madx_wrapper.
madx_path
¶ Path to MADX executable
-
-
madx_wrapper.
resolve_and_run_string
(input_string, output_file=None, log_file=None, madx_path='/home/travis/build/pylhc/Beta-Beat.src/madx/bin/madx-linux64-gnu', cwd=None)[source]¶ Runs MADX in a subprocess.
-
madx_wrapper.
input_string
¶ MADX input string
-
madx_wrapper.
output_file
If given writes resolved MADX script.
-
madx_wrapper.
log_file
If given writes MADX logging output.
-
madx_wrapper.
madx_path
Path to MADX executable
-