def get_params(): """ Parameters defined with EntryPointArguments (which is a dict *cough*) """ args = EntryPointParameters() args.add_parameter( name="accel", flags=["-a", "--accel"], help="Which accelerator: LHCB1 LHCB2 LHCB4? SPS RHIC TEVATRON", choices=["LHCB1", "LHCB2", "LHCB5"], required=True, ) args.add_parameter( name="anint", flags=["-i", "--int"], help="Just a number.", type=int, required=True, ) args.add_parameter( name="alist", flags=["-l", "--lint"], help="Just a number.", type=int, nargs="+", ) args.add_parameter( name="anotherlist", flags=["-k", "--alint"], help="list.", type=str, nargs=3, default=["a", "c", "f"], choices=["a", "b", "c", "d", "e", "f"], ), return args
def _get_params(): params = EntryPointParameters() params.add_parameter( name="accel", required=True, choices=list(ACCELS.keys()), help="Choose the accelerator to use.Can be the class already.") return params
def get_other_params(): """ For testing the create_param_help()""" args = EntryPointParameters({ "arg1": dict( flags="--arg1", help="A help.", default=1, ), "arg2": dict( flags="--arg2", help="More help.", default=2, ), "arg3": dict( flags="--arg3", help="Even more...", default=3, ), "arg4": dict( flags="--arg4", help="...heeeeeeeeelp.", default=4, ), }) return args
def get_params(): return EntryPointParameters( files=dict( required=True, type=PathOrStr, nargs='+', help="List of paths to the lin-files, including suffix.", ), # restore backup restore=dict( action="store_true", help=("Restore the latest backup of the files. " "If this parameter is given, no cleaning is performed."), ), # for actual cleaning columns=dict( nargs='+', type=str, help="Columns to clean on.", ), limit=dict( type=float, help= "Do not clean data-points deviating less than this limit from the average.", default=0.0, ), backup=dict( action="store_true", help=("Create a backup of the files before overwriting. " "The backups are numbered, with the highest number being " "the latest backup.")), )
def test_string_with_break_cfg(tmp_path): @entrypoint(EntryPointParameters(dict(name={'type': str})), strict=True) def fun(opt): return opt opt = fun(name="this is\nmystring") cfg_file = tmp_path / "config.ini" save_options_to_config(cfg_file, opt) opt_load = fun(entry_cfg=cfg_file) assert opt_load.name == opt.name
def test_path_cfg(tmp_path): @entrypoint(EntryPointParameters(dict(path={'type': Path})), strict=True) def fun(opt): return opt cfg_file = tmp_path / "config.ini" opt = fun(path=tmp_path) save_options_to_config(cfg_file, opt) opt_load = fun(entry_cfg=cfg_file) _assert_dicts_equal(opt, opt_load)
def hole_in_one_params(): params = EntryPointParameters() params.add_parameter(name="harpy", action="store_true", help="Runs frequency analysis") params.add_parameter(name="optics", action="store_true", help="Measures the lattice optics") return params
def _get_params(): params = EntryPointParameters() params.add_parameter( name="twissfile", required=True, help="Path to twissfile with observationspoint in the NAME column.") params.add_parameter(name="outputdir", required=True, help=f"Directory where the {OBS_POINTS} will be put.") return params
def test_list_cfg(tmp_path): @entrypoint(EntryPointParameters(dict(lst={ 'type': int, 'nargs': "*" })), strict=True) def fun(opt): return opt cfg_file = tmp_path / "config.ini" opt = fun(lst=[1, 2, 3, 4]) save_options_to_config(cfg_file, opt) opt_load = fun(entry_cfg=cfg_file) _assert_dicts_equal(opt, opt_load)
def converter_params(): params = EntryPointParameters() params.add_parameter(name="inputdir", required=True, type=str, help="Directory with BetaBeat.src output files.") params.add_parameter(name="outputdir", required=True, type=str, help="Output directory for converted files.") params.add_parameter( name="suffix", type=str, default="_free", choices=("", "_free", "_free2"), help= "AC dipole compensation suffix used in the provided BetaBeat.src output ('_free' " "for compensation by equation, '_free2' by model. Defaults to '_free'.", ) return params
def test_string_cfg(tmp_path): @entrypoint(EntryPointParameters(dict(name={'type': str})), strict=True) def fun(opt): return opt cfg_quotes = tmp_path / "config_quotes.ini" with open(cfg_quotes, "w") as f: f.write("[Section]\nname = 'My String with Spaces'") cfg_doublequotes = tmp_path / "config_doublequotes.ini" with open(cfg_doublequotes, "w") as f: f.write('[Section]\nname = "My String with Spaces"') cfg_noquotes = tmp_path / "config_noquotes.ini" with open(cfg_noquotes, "w") as f: f.write('[Section]\nname = My String with Spaces') opt_quotes = fun(entry_cfg=cfg_quotes) opt_doublequotes = fun(entry_cfg=cfg_doublequotes) opt_noquotes = fun(entry_cfg=cfg_noquotes) assert opt_quotes.name == opt_doublequotes.name assert opt_quotes.name == opt_noquotes.name
def _get_params(): return EntryPointParameters( beam=dict( help="Which beam to use.", required=True, type=int, ), kick=dict( help="Location of the kick files (parent folder).", type=str, required=True, ), plane=dict( help="Plane of the kicks. 'X' or 'Y'.", required=True, choices=PLANES, type=str, ), label=dict( help="Label to identify this run.", type=str, ), bbq_in=dict( help=("Fill number of desired data to extract from timber " "or path to presaved bbq-tfs-file. Use the string 'kick' to " "use the timestamps in the kickfile for timber extraction. " "Not giving this parameter skips bbq compensation."), ), detuning_order=dict( help="Order of the detuning as int. Basically just the order of the applied fit.", type=int, default=1, ), output=dict( help="Output directory for the modified kickfile and bbq data.", type=str, ), window_length=dict( help="Length of the moving average window. (# data points)", type=int, default=20, ), bbq_filtering_method=dict( help="Filtering method for the bbq to use. 'cut' cuts around a given tune, " "'minmax' lets you specify the limits and 'outliers' uses the outlier filtering " "from utils.", type=str, choices=["cut", "minmax", "outliers"], default="outliers", ), # Filtering method outliers outlier_limit=dict( help="Limit, i.e. cut, on outliers (Method 'outliers')", type=float, default=2e-4, ), # Filtering method tune-cut tunes=dict( help="Tunes for BBQ cleaning (Method 'cut').", type=float, nargs=2, ), tune_cut=dict( help="Cuts for the tune. For BBQ cleaning (Method 'cut').", type=float, ), # Filtering method tune-minmax tunes_minmax=dict( help=("Tunes minima and maxima in the order x_min, x_max, y_min, y_max. " "For BBQ cleaning (Method 'minmax')."), type=float, nargs=4, ), # Fine Cleaning fine_window=dict( help="Length of the moving average window, i.e # data points (fine cleaning for 'minmax' or 'cut').", type=int, ), fine_cut=dict( help="Cut, i.e. tolerance, of the tune (fine cleaning for 'minmax' or 'cut').", type=float, ), # Debug debug=dict( help="Activates Debug mode", action="store_true", ), logfile=dict( help="Logfile if debug mode is active.", type=str, ), )
def get_params(): params = EntryPointParameters() params.add_parameter(name="files", required=True, nargs='+', help=("List of paths to the spectrum files. The files need to be given" " without their '.lin'/'.amps[xy]','.freqs[xy]' endings. " " (So usually the path of the TbT-Data file.)")) params.add_parameter(name="output_dir", type=str, help='Directory to write results to. If no option is given, plots will not be saved.') params.add_parameter(name="bpms", nargs='+', help='List of BPMs for which spectra will be plotted. If not given all BPMs are used.') params.add_parameter(name="amp_limit", type=float, default=0., help='All amplitudes <= limit are filtered. ' 'This value needs to be at least 0 to filter non-found frequencies.') params.add_parameter(name="rescale", action="store_true", help='Flag to rescale plots amplitude to max-line = 1') params.add_parameter(name="plot_type", nargs="+", choices=['stem', 'waterfall'], default=['stem'], help='Choose plot type (Multiple choices possible).') params.add_parameter(name="combine_by", nargs="*", choices=['bpms', 'files'], default=[], help='Choose how to combine the data into figures.') params.add_parameter(name="waterfall_line_width", default=DEFAULTS.waterfall_line_width, help='Line width of the waterfall frequency lines. "auto" fills them up until the next one.') params.add_parameter(name="waterfall_cmap", type=str, default=DEFAULTS.waterfall_cmap, help="Colormap to use for waterfall plot.") params.add_parameter(name="waterfall_common_plane_colors", action="store_true", help="Same colorbar scale for both planes in waterfall plots.") params.add_parameter(name="show_plots", action="store_true", help='Flag to show plots') params.add_parameter(name="lines_tunes", nargs="*", type=tuple, default=[(1, 0), (0, 1)], help='list of tune lines to plot') params.add_parameter(name="lines_nattunes", nargs="*", type=tuple, default=[(1, 0), (0, 1)], help='List of natural tune lines to plot') params.add_parameter(name="lines_manual", nargs="*", default=[], type=DictAsString, help='List of manual lines to plot. Need to contain arguments for axvline, and may contain ' 'the additional keys "text" and "loc" which is one of ' f'{list(VERTICAL_LINES_TEXT_LOCATIONS.keys())} and places the text at the given location.' ) params.add_parameter(name="xlim", nargs=2, type=float, default=DEFAULTS.xlim, help='Limits on the x axis (Tupel)') params.add_parameter(name="ylim", nargs=2, type=float, default=DEFAULTS.ylim, help='Limits on the y axis (Tupel)') params.add_parameter(name="ncol_legend", type=int, default=NCOL_LEGEND, help='Number of bpm legend-columns. If < 1 no legend is shown.') params.add_parameter(name="filetype", type=str, default=DEFAULTS.filetype, help='Filetype to save plots as (i.e. extension without ".")') params.add_parameter(name="manual_style", type=DictAsString, default={}, help='Additional Style parameters which update the set of predefined ones.') return params
def get_parameters(): params = EntryPointParameters() params.add_parameter( name="model_dir", type=str, help= "Path to model directory; loads tunes and excitation from model!") params.add_parameter( name="nat_tunes", type=float, nargs=2, help="Natural tunes without integer part.", ) params.add_parameter( name="drv_tunes", type=float, nargs=2, help="Driven tunes without integer part.", ) params.add_parameter( name="driven_excitation", type=str, choices=("acd", "adt"), help="Denotes driven excitation by AC-dipole (acd) or by ADT (adt)", ) params.add_parameter( name="dpp", default=0.0, type=float, help="Delta p/p to use.", ) params.add_parameter( name="energy", type=float, help="Energy in Tev.", ) params.add_parameter( name="modifiers", type=str, help="Path to the optics file to use (modifiers file).") params.add_parameter( name="fullresponse", action="store_true", help="If True, outputs also fullresponse madx file.", ) params.add_parameter( name="xing", action="store_true", help="If True, x-ing angles will be applied to model") return params
def optics_params(): params = EntryPointParameters() params.add_parameter(name="files", required=True, nargs='+', help="Files for analysis") params.add_parameter(name="outputdir", required=True, help="Output directory") params.add_parameter(name="calibrationdir", type=str, help="Path to calibration files directory.") params.add_parameter( name="coupling_method", type=int, choices=(0, 1, 2), default=OPTICS_DEFAULTS["coupling_method"], help="Analysis option for coupling: disabled, 1 BPM or 2 BPMs method") params.add_parameter(name="range_of_bpms", type=int, choices=(5, 7, 9, 11, 13, 15), default=OPTICS_DEFAULTS["range_of_bpms"], help="Range of BPMs for beta from phase calculation") params.add_parameter( name="union", action="store_true", help="If present, the phase advances are calculate for union of BPMs " "with at least 3 valid measurements, instead of intersection .") params.add_parameter(name="nonlinear", nargs='*', default=[], choices=('rdt', 'crdt'), help="Choose which rdt analysis is conducted.") params.add_parameter(name="three_bpm_method", action="store_true", help="Use 3 BPM method in beta from phase") params.add_parameter(name="only_coupling", action="store_true", help="Calculate only coupling. ") params.add_parameter( name="compensation", type=str, default=OPTICS_DEFAULTS["compensation"], choices=("model", "equation", "none"), help= "Mode of compensation for the analysis after driven beam excitation") params.add_parameter(name="three_d_excitation", action="store_true", help="Use 3D kicks to calculate dispersion") params.add_parameter(name="isolation_forest", action="store_true", help="Remove outlying BPMs with isolation forest") params.add_parameter(name="second_order_dispersion", action="store_true", help="Calculate second order dispersion") params.add_parameter( name="chromatic_beating", action="store_true", help="Calculate chromatic beatings: W, PHI and coupling") return params
def harpy_params(): params = EntryPointParameters() params.add_parameter(name="files", required=True, nargs='+', help="TbT files to analyse") params.add_parameter(name="outputdir", required=True, help="Output directory.") params.add_parameter(name="model", help="Model for BPM locations") params.add_parameter( name="unit", type=str, default=HARPY_DEFAULTS["unit"], choices=("m", "cm", "mm", "um"), help=f"A unit of TbT BPM orbit data. All cuts and output are in 'm'.") params.add_parameter( name="turns", type=int, nargs=2, default=HARPY_DEFAULTS["turns"], help="Turn index to start and first turn index to be ignored.") params.add_parameter(name="to_write", nargs='+', default=HARPY_DEFAULTS["to_write"], choices=('lin', 'spectra', 'full_spectra', 'bpm_summary'), help="Choose the type of output.") params.add_parameter(name="tbt_datatype", default=HARPY_DEFAULTS["tbt_datatype"], choices=list(tbt.handler.DATA_READERS.keys()), help="Choose the datatype from which to import. ") # Cleaning parameters params.add_parameter(name="clean", action="store_true", help="If present, the data are first cleaned.") params.add_parameter(name="sing_val", type=int, default=HARPY_DEFAULTS["sing_val"], help="Keep this amount of largest singular values.") params.add_parameter( name="peak_to_peak", type=float, default=HARPY_DEFAULTS["peak_to_peak"], help="Peak to peak amplitude cut. This removes BPMs, " "where abs(max(turn values) - min(turn values)) <= threshold.") params.add_parameter(name="max_peak", type=float, default=HARPY_DEFAULTS["max_peak"], help="Removes BPMs where the maximum orbit > limit.") params.add_parameter(name="svd_dominance_limit", type=float, default=HARPY_DEFAULTS["svd_dominance_limit"], help="Limit for single BPM dominating a mode.") params.add_parameter( name="num_svd_iterations", type=int, default=HARPY_DEFAULTS["num_svd_iterations"], help="Maximal number of iterations of U matrix elements removal " "and renormalisation in iterative SVD cleaning of dominant BPMs." " This is also equal to maximal number of BPMs removed per SVD mode.") params.add_parameter(name="bad_bpms", nargs='*', help="Bad BPMs to clean.") params.add_parameter(name="wrong_polarity_bpms", nargs='*', help="BPMs with swapped polarity in both planes.") params.add_parameter( name="keep_exact_zeros", action="store_true", help="If present, will not remove BPMs with exact zeros in TbT data.") params.add_parameter(name="first_bpm", type=str, help="First BPM in the measurement. " "Used to resynchronise the TbT data with model.") params.add_parameter( name="opposite_direction", action="store_true", help="If present, beam in the opposite direction to model" " is assumed for resynchronisation of BPMs.") # Harmonic analysis parameters params.add_parameter( name="tunes", type=float, nargs=3, help= "Guess for the main tunes [x, y, z]. Tunez is disabled when set to 0") params.add_parameter( name="nattunes", type=float, nargs=3, help="Guess for the natural tunes (x, y, z). Disabled when set to 0.") params.add_parameter( name="natdeltas", type=float, nargs=3, help="Guess for the offsets of natural tunes from the driven tunes" " (x, y, z). Disabled when set to 0.") params.add_parameter( name="autotunes", type=str, choices=("all", "transverse"), help="The main tunes are guessed as " "the strongest line in SV^T matrix frequency spectrum: " "Synchrotron tune below ~0.03, betatron tunes above ~0.03.") params.add_parameter( name="tune_clean_limit", type=float, default=HARPY_DEFAULTS["tune_clean_limit"], help= "The tune cleaning wont remove BPMs because of measured tune outliers" " closer to the average tune than this limit.") params.add_parameter( name="tolerance", type=float, default=HARPY_DEFAULTS["tolerance"], help= "Tolerance specifying an interval in frequency domain, where to look " "for the tunes.") params.add_parameter( name="is_free_kick", action="store_true", help="If present, it will perform the free kick phase correction") params.add_parameter( name="window", type=str, default=HARPY_DEFAULTS["window"], choices=("rectangle", "hann", "triangle", "welch", "hamming", "nuttal3", "nuttal4"), help="Windowing function to be used for frequency analysis.") params.add_parameter( name="turn_bits", type=int, default=HARPY_DEFAULTS["turn_bits"], help="Number (frequency, complex coefficient) pairs in the calculation" " is 2 ** turn_bits, i.e. the difference between " "two neighbouring frequencies is 2 ** (- turn_bits - 1).") params.add_parameter( name="output_bits", type=int, default=HARPY_DEFAULTS["output_bits"], help="Number (frequency, complex coefficient) pairs in the output " "is up to 2 ** output_bits (maximal in case full spectra is output). " "There is one pair (with maximal amplitude of complex coefficient) " "per interval of size 2 ** (- output_bits - 1).") return params
def response_params(): params = EntryPointParameters() params.add_parameter( name="creator", type=str, choices=("madx", "twiss"), default="madx", help="Create either with madx or analytically from twiss file.") params.add_parameter(name="variable_categories", nargs="+", default=CORRECTION_DEFAULTS["variable_categories"], help="List of the variables classes to use.") params.add_parameter(name="outfile_path", type=PathOrStr, help="Name of fullresponse file.") params.add_parameter( name="delta_k", type=float, default=0.00002, help= "Delta K1 to be applied to quads for sensitivity matrix (madx-only).") params.add_parameter( name="optics_params", type=str, nargs="+", choices=OPTICS_PARAMS_CHOICES, help="List of parameters to correct upon (e.g. BBX BBY; twiss-only).", ) params.add_parameter( help="Print debug information.", name="debug", action="store_true", ) return params
def correction_params(): params = EntryPointParameters() params.add_parameter( name="meas_dir", required=True, help="Path to the directory containing the measurement files.", ) params.add_parameter( name="output_dir", required=True, help="Path to the directory where to write the output files.", ) params.add_parameter( name="fullresponse_path", help="Path to the fullresponse binary file.If not given, " "calculates the response analytically.", ) params.add_parameter( name="optics_params", type=str, nargs="+", default=list(CORRECTION_DEFAULTS["optics_params"]), choices=OPTICS_PARAMS_CHOICES, help=f"List of parameters to correct upon (e.g. {BETA}X {BETA}Y)", ) params.add_parameter( name="output_filename", default=CORRECTION_DEFAULTS["output_filename"], help="Identifier of the output files.", ) params.add_parameter( name="min_corrector_strength", type=float, default=0., help="Minimum (absolute) strength of correctors.", ) params.add_parameter( name="modelcut", nargs="+", type=float, help="Reject BPMs whose deviation to the model is higher " "than the correspoding input. Input in order of optics_params.", ) params.add_parameter( name="errorcut", nargs="+", type=float, help="Reject BPMs whose error bar is higher than the corresponding " "input. Input in order of optics_params.", ) params.add_parameter( name="weights", nargs="+", type=float, help="Weight to apply to each measured quantity. " "Input in order of optics_params.", ) params.add_parameter( name="variable_categories", nargs="+", default=CORRECTION_DEFAULTS["variable_categories"], help="List of names of the variables classes to use.", ) params.add_parameter( name="beta_file_name", default=CORRECTION_DEFAULTS["beta_file_name"], help="Prefix of the beta file to use. E.g.: getkmodbeta", ) params.add_parameter( name="method", type=str, choices=("pinv", "omp"), default=CORRECTION_DEFAULTS["method"], help="Optimization method to use.", ) params.add_parameter( name="svd_cut", type=float, default=CORRECTION_DEFAULTS["svd_cut"], help="Cutoff for small singular values of the pseudo inverse. " "(Method: 'pinv')Singular values smaller than " "rcond*largest_singular_value are set to zero", ) params.add_parameter( name="n_correctors", type=int, help="Maximum number of correctors to use. (Method: 'omp')") params.add_parameter( name="max_iter", type=int, default=CORRECTION_DEFAULTS["max_iter"], help="Maximum number of correction re-iterations to perform. " "A value of `0` means the correction is calculated once.", ) params.add_parameter( name="use_errorbars", action="store_true", help="Take into account the measured errorbars in the correction.", ) params.add_parameter( name="update_response", action="store_true", help="Update the (analytical) response per iteration.", ) return params
def converter_params(): params = EntryPointParameters() params.add_parameter(name="files", required=True, nargs='+', help="TbT files to analyse") params.add_parameter(name="outputdir", required=True, help="Output directory.") params.add_parameter(name="tbt_datatype", type=str, default="lhc", choices=list(tbt.handler.DATA_READERS.keys()), help="Choose the datatype from which to import. ") params.add_parameter(name="realizations", type=int, default=1, help="Number of copies with added noise") params.add_parameter(name="noise_levels", nargs='+', help="Sigma of added Gaussian noise") params.add_parameter(name="use_average", action="store_true", help="If set, returned sdds only contains the average over all particle/bunches.") return params