levisim.core.utils

General helpers: pickling, time arrays and slices, filtering, and generating and finding kicks

levisim.core.utils.save_variable_to_pickle(variable, save_name='default.pickle')[source]

Save any given python variable to a binary file

levisim.core.utils.load_variable_from_pickle(save_name)[source]

Load any previously saved python variable from a binary file

levisim.core.utils.generate_time_array(start_time, end_time, num_samples)[source]

Returns a num_samples + 1 length array of time values, i.e. including end_time

levisim.core.utils.time_slice(array, start_time, end_time, Δt)[source]

Returns a slice of a time series array (of resolution Δt) from a given start_time to end_time

levisim.core.utils.apply_filter(signal, Nyquist_freq, centre_freq, filter_type, bandwidth, plot=True)[source]

Zero-phase (forward-backward) band-pass filtering of a signal filter_type: ‘butter’ (5th-order Butterworth band-pass of the given bandwidth) or ‘iirpeak’ (2nd-order IIR peak of quality factor centre_freq / bandwidth) The filter is applied as second-order sections (scipy.signal.sosfiltfilt), which avoids the round-off problems of the transfer-function (b, a) form for high orders or narrow bands. [units of signal]

levisim.core.utils.calculate_contrast(data)[source]

Calculates the ratio of the maximum to the root-mean-square of given data

levisim.core.utils.kick_data_path(gain, run_choice)[source]

Returns the data path

levisim.core.utils.generate_kick_list(num_kicks=None, starts=None, durations=None, strengths=None, angles=None)[source]

Provides a list of Kicks that can be assigned to the kicks attribute of a Trap instance

levisim.core.utils.cross_check_kick_indices(indices_a, indices_b, tolerance=10)[source]

Indices of indices_a that have a partner in indices_b within ±tolerance samples (sorted) Used by find_kicks to flag detections that only one of its two methods finds. [samples]

levisim.core.utils.find_kicks(kick_trace, number_of_kicks_to_look_for, plot=True, tolerance=10)[source]

Finds the times of the n largest kicks in a kick-monitor trace, by two methods: 1. the n largest values, and 2. the n steepest rises (largest positive sample-to-sample steps) and logs a warning if the two disagree (see cross_check_kick_indices, ±tolerance samples). Returns (kick_times, kick_times_2, kick_voltages) for methods 1 and 2. [s, s, units of the trace]