fit_resonator package

Submodules

fit_resonator.Sdata module

class fit_resonator.Sdata.ComplexData(freqs: ndarray, complex_s21: ndarray)

Bases: object

Container for normalized data

fit_resonator.Sdata.PlotFit(x, y, x_initial, y_initial, slope, intercept, slope2, intercept2, params, Method, func, error, figurename, x_c, y_c, radius, output_path, conf_array, extract_factor=None, title='Fit', manual_params=None, dfac: int = 10, msizes: list = [12, 7], xstr: str = 'Frequency [GHz]', fsize: float = 16.0)

Plots data and outputs fit parameters to a file

Parameters
  • x – cropped frequency data

  • y – cropped S21 data after normalization

  • x_initial – original frequency data before normalization

  • y_initial – original S21 data before normalization

  • slope – slope of the normalization line for magnitude

  • intercept – intercept of normalization line for magnitude

  • slope2 – slope of the normalization line for phase

  • intercept2 – intercept of normalization line for phase

  • params – parameters generated from fit function

  • Method – Method class instance

  • func – function used to generate data for plotting (DCM/DCM REFLECTION/INV/PHI/CPZM)

  • error – error from Monte Carlo Fit function

  • figurename – name the plot should have

  • x_c – center x coordinate for fit circle

  • y_c – center y coordinate for fit circle

  • radius – radius of fit circle

  • output_path – file path where the plots will be saved

  • conf_array – array with 95% confidence interval values

  • extract_factor – contains starting and ending frequency values

  • title – title the plot will have

  • manual_params – user input manual initial guess parameters for fit

  • dfac – decimation factor on the plotting of points in the resonance circle Im S21 vs. Re S21

  • xstr – x-axis string label

  • fsize – fontsize for axes numbers and labels

Returns

plot output to file

class fit_resonator.Sdata.VNASweep(freqs: ndarray, amps: ndarray, phases: ndarray, linear_amps: ndarray)

Bases: object

A container to hold data from a vna frequency sweep.

classmethod from_columns(freqs, amps, phases)

Load data from columns provided individually.

classmethod from_file(file, fscale=1000000000.0)
fit_resonator.Sdata.background_removal(databg: VNASweep, linear_amps: ndarray, phases: ndarray, output_path: str)
fit_resonator.Sdata.calibrate(x_data: ndarray, z_data: ndarray)

Finds the parameters for normalization of the scattering data. See Sij of port classes for explanation of parameters.

fit_resonator.Sdata.convert_params(from_method, params)
fit_resonator.Sdata.extract_near_res(x_raw: ndarray, y_raw: ndarray, f_res: float, kappa: float, extract_factor: int = 1)

Extracts portions of spectrum of kappa within resonance.

Parameters
  • x_raw – X-values of spectrum to extract from.

  • y_raw – Y-values of spectrum to extract from.

  • f_res – Resonant frequency about which to extract data.

  • kappa – Width about f_res to extract.

  • extract_factor – Multiplier for kappa.

Returns

Extracted spectrum kappa about f_res.

fit_resonator.Sdata.find_circle(x, y)

Given a set of x,y data return a circle that fits data using LeastSquares Circle Fit Randy Bullock (2017)

Parameters
  • x – Array of x position of data in complex plane (real)

  • y – Array of y position of data in complex plane (imaginary)

Returns

x (matrix1) and y (matrix2) center coordinates of the circle, and the radius of the circle “R”

fit_resonator.Sdata.find_initial_guess(x, y1, y2, Method, output_path, plot_extra)

Determines an initial guess for the parameters

Parameters
  • x – frequency data

  • y1 – real part of transmission data

  • y2 – imaginary part of transmission data

  • Method – method class

  • output_path – place to output any plots generated

  • plot_extra – boolean that determines if extra plots will be output

Returns: initial guess for parameters, x coordinate for center of fit circle, y coordinate for center of fit circle, radius of fit circle

fit_resonator.Sdata.find_nearest(array, value)
fit_resonator.Sdata.fit(filename: str, Method, normalize: int, dir: Optional[str] = None, data_array: Optional[ndarray] = None, background: Optional[str] = None, background_array: Optional[ndarray] = None, plot_extra=False, preprocess_method='linear', fscale: float = 1000000000.0)

Function to fit resonator data

Parameters
  • filename – name of the file to be fit

  • Method – instance of Method class

  • normalize – number of points on either side to create linear function for normalization process

  • dir – directory where data to be fit is contained

  • data_array – optional way to read in data if the user already has an array of data in memory they want to fit

  • background – file name for optional background removal file

  • background_array – optional way to read in background removal data if the user already has an array of data in memory they want to use

  • plot_extra – boolean to determine if code should output additional plots to show normalization process and other steps

Returns

final minimized parameter values 95% confidence interval values for those parameters main figure output by the plotting function error of Monte Carlo Fit initial guess parameters

fit_resonator.Sdata.fit_delay(xdata: ndarray, ydata: ndarray)

Finds the cable delay by repeatedly centering the “circle” and fitting the slope of the phase response.

fit_resonator.Sdata.fit_phase(f_data, z_data, guesses=None)

Fits the phase response of a strongly overcoupled (Qi >> Qc) resonator in reflection which corresponds to a circle centered around the origin (cf‌. phase_centered()).

Parameters
  • z_data – Scattering data of which the phase should be fit. Data must be distributed around origin (“circle-like”).

  • guesses (opt.) – If not given, initial guesses for the fit parameters will be determined. If given, should contain useful guesses for fit parameters as a tuple (fr, Ql, delay)

Returns

Resonance frequency Ql: Loaded quality factor theta: Offset phase delay: Time delay between output and input signal leading to linearly

frequency dependent phase shift

Return type

fr

fit_resonator.Sdata.get_header(line: str)
fit_resonator.Sdata.min_fit(params, xdata, ydata, Method)

Minimizes parameter values for the given function and transmission data

Parameters
  • params – guess for correct values of the fit parameters

  • xdata – array of frequency data points

  • ydata – array of S21 data points

  • Method – instance of Method class

Returns

minimized parameter values, 95% confidence intervals for those parameter values

fit_resonator.Sdata.monte_carlo_fit(xdata=None, ydata=None, parameter=None, Method=None)
fit_resonator.Sdata.name_folder(dir, strmethod)
fit_resonator.Sdata.name_plot(filename, strmethod, output_path, format='.pdf')
fit_resonator.Sdata.normalize(f_data, z_data, delay, a, alpha)

Transforms scattering data into canonical position with off-resonant point at (1, 0) (does not correct for rotation phi of circle around off-resonant point).

fit_resonator.Sdata.periodic_boundary(angle)

Maps arbitrary angle to interval [-np.pi, np.pi)

fit_resonator.Sdata.phase_centered(f, fr, Ql, theta, delay=0.0)

Yields the phase response of a strongly overcoupled (Qi >> Qc) resonator in reflection which corresponds to a circle centered around the origin. Additionally, a linear background slope is accounted for if needed.

Parameters
  • fr – Resonance frequency

  • Ql – Loaded quality factor (and since Qi >> Qc also Ql = Qc)

  • theta – Offset phase

  • delay (opt.) – Time delay between output and input signal leading to linearly frequency dependent phase shift

Returns

Phase response (float)

fit_resonator.Sdata.phase_dist(angle)

Maps angle [-2pi, +2pi] to phase distance on circle [0, pi]

fit_resonator.Sdata.plot(x, y, name, output_path, x_c=None, y_c=None, r=None, p_x=None, p_y=None)
fit_resonator.Sdata.plot2(x, y, x2, y2, name, output_path)
fit_resonator.Sdata.preprocess_circle(xdata: ndarray, ydata: ndarray, output_path: str, plot_extra)

Data Preprocessing. Use Probst method to get rid of cable delay and normalize phase/magnitude of S21 by circle fit

fit_resonator.Sdata.preprocess_linear(xdata: ndarray, ydata: ndarray, normalize: int, output_path: str, plot_extra)

Data Preprocessing. Get rid of cable delay and normalize phase/magnitude of S21 by linear fit of normalize # of endpoints

fit_resonator.check_data module

fit_resonator.check_data.file(filename)

Check data from a file

Parameters

filename (str) – Relative path to your data file

Returns

None

fit_resonator.check_data.parse(frequency, magnitude, phase, filepath=None, file_flag=False)
fit_resonator.check_data.raw(freq, mag, phase)

Check raw data

Parameters
  • freq (array or array-like) – Monotonically increasing frequency (GHz)

  • mag (array or array-like) – Magnitude of S21 (dB) log mag

  • phase (array or array-like) – Phase of S21 (radians)

Returns

None if no changes made (freq, mag, phase) tuple if changes from raw are made

fit_resonator.fit_multiple module

fit_resonator.functions module

Analytic fit functions

fit_resonator.functions.cavity_CPZM(x, Qi, Qic, w1, Qia)
fit_resonator.functions.cavity_DCM(x, Q, Qc, w1, phi)
fit_resonator.functions.cavity_DCM_REFLECTION(x, Q, Qc, w1, phi)
fit_resonator.functions.cavity_inverse(x, Qi, Qc, w1, phi)
fit_resonator.functions.fit_raw_compare(x, y, params, method)
fit_resonator.functions.min_one_Cavity_CPZM(parameter, x, data=None)
fit_resonator.functions.min_one_Cavity_DCM_REFLECTION(parameter, x, data=None)
fit_resonator.functions.min_one_Cavity_dip(parameter, x, data=None)
fit_resonator.functions.min_one_Cavity_inverse(parameter, x, data=None)
fit_resonator.functions.one_cavity_peak_abs(x, Q, Qc, w1)
fit_resonator.functions.one_cavity_peak_abs_REFLECTION(x, Q, Qc, w1)

fit_resonator.resonator module

Adapted from @mullinski and @hung93

class fit_resonator.resonator.CPZMparams(params, chi)

Bases: object

class fit_resonator.resonator.DCMparams(params, chi)

Bases: object

class fit_resonator.resonator.FitMethod(method: str, MC_iteration: int = 5, MC_rounds: int = 100, MC_weight: str = 'no', MC_weightvalue: int = 2, MC_fix: list = [], MC_step_const: float = 0.6, manual_init: Optional[list] = None, vary: Optional[bool] = None)

Bases: object

method: str

“DCM” or ‘INV’ or ‘CPZM’

fitting range:

number -> number * FW2M (Full width at half twice min). if not =1, changes the FW2M fitting range list -> from list[0] to list[1] ‘all’ -> all

MC_iteration: int

Number of iteration of 1) least square fit + 2) Monte Carlo

MC_rounds: int

in each MC iteration, number of rounds of randomly choose parameter

MC_weigh: str

‘no’ or ‘yes’, weight the extract_factor fitting range, yes uses 1/|S21| weight, which we call iDCM

MC_weightvalue: int

multiplication factor for weighing, such as 2 for twice the 1/|S21| weight.

MC_fix: list of str

‘Amp’,’w1’,’theta’,’phi’,’Qc’, ‘Q’ for DCM, ‘Qi’ for INV

MC_step_const: int

randomly choose number in range MC_step_const*[-0.5~0.5] for fitting. Exp(0.5)=1.6, and this is used for Qi,… . However, the res. frequency, theta, amplitude are usually fixed during Monte Carlo.

find_circle: bool

true=> find initial guess from circle (better) or false if find from linewidth

manual_init: None or list of 6 float number

manual input initial guesses DCM: [amplitude, Q, Qc, freq, phi, theta] INV: [amplitude, Qi, Qc, freq, phi, theta]

vary: None or list of 6 booleans

vary parameter in least square fit (which parameters change = true)

change_method(method)
class fit_resonator.resonator.INVparams(params, chi)

Bases: object

class fit_resonator.resonator.Resonator(freq: ndarray, S21: ndarray, name: str = '', date: Optional[datetime] = None, temp: Optional[float] = None, bias: Optional[float] = None)

Bases: object

Object for representing a resonator fit.

Parameters
  • freq – list of frequencies (units of GHz).

  • S21 – complex S21 for each frequency.

  • name (optional) – name of scan.

  • date (optional) – date of scan.

  • temp (optional) – temperature of scan (in Kelvin).

  • bias (optional) – bias present during scan (in volts?).

fit(**kwargs)
load_params(method: str, params: list, chi: any)

Loads model parameters for a corresponding fit technique.

Parameters
  • method – One of DCM, PHI, DCM REFLECTION, INV, CPZM. Described in the readme.

  • params – model fit parameters.

  • chi – TODO(mutus) desicribe this argument. What is this?

power_calibrate(p)
reload_params(method: str, params: list, chi: any)

Reloads model parameters for a corresponding fit technique.

Parameters
  • method – One of DCM, PHI, DCM REFLECTION, INV, CPZM. Described in the readme.

  • params – model fit parameters.

  • chi – TODO(mutus) desicribe this argument. What is this?

Module contents