qetpy.core package

qetpy.core._didv module

qetpy.core._didv.didvinitfromdata(tmean, didvmean, didvstd, offset, offset_err, fs, sgfreq, sgamp, rshunt, r0=0.3, r0_err=0.001, rload=0.01, rload_err=0.001, priors=None, invpriorscov=None, add180phase=False, dt0=1e-05)

Function to initialize and process a dIdV dataset without having all of the traces, but just the parameters that are required for fitting. After running, this returns a DIDV class object that is ready for fitting.

Parameters:
tmean : ndarray

The average trace in time domain, units of Amps

didvstd : ndarray

The complex standard deviation of the didv in frequency space for each frequency

didvmean : ndarray

The average trace converted to didv

offset : float

The offset (i.e. baseline value) of the didv trace, in Amps

offset_err : float

The error in the offset of the didv trace, in Amps

fs : float

Sample rate of the data taken, in Hz

sgfreq : float

Frequency of the signal generator, in Hz

sgamp : float

Amplitude of the signal generator, in Amps (equivalent to jitter in the QET bias)

rshunt : float

Shunt resistance in the circuit, Ohms

r0 : float, optional

Resistance of the TES in Ohms

r0_err : float, optional

Error in the resistance of the TES (Ohms)

rload : float, optional

Load resistance of the circuit (rload = rshunt + rparasitic), Ohms

rload_err : float, optional

Error in the load resistance, Ohms

priors : ndarray, optional

Prior known values of Irwin’s TES parameters for the trace. Should be in the order of (rload,r0,beta,l,L,tau0,dt)

invpriorscov : ndarray, optional

Inverse of the covariance matrix of the prior known values of Irwin’s TES parameters for the trace (any values that are set to zero mean that we have no knowledge of that parameter)

add180phase : boolean, optional

If the signal generator is out of phase (i.e. if it looks like –__ instead of __–), then this should be set to True. Adds half a period of the signal generator to the dt0 attribute

dt0 : float, optional

The value of the starting guess for the time offset of the didv when fitting. The best way to use this value if it isn’t converging well is to run the fit multiple times, setting dt0 equal to the fit’s next value, and seeing where the dt0 value converges. The fit can have a difficult time finding the value on the first run if it the initial value is far from the actual value, so a solution is to do this iteratively.

Returns:
didvobj : Object

A DIDV class object that can be used to fit the dIdV and return the fit parameters.

class qetpy.core._didv.DIDV(rawtraces, fs, sgfreq, sgamp, rshunt, tracegain=1.0, r0=0.3, r0_err=0.001, rload=0.01, rload_err=0.001, dutycycle=0.5, add180phase=False, priors=None, invpriorscov=None, dt0=1e-05)

Bases: object

Class for fitting a didv curve for different types of models of the didv. Also gives various other useful values pertaining to the didv. This class supports doing 1, 2, and 3 pole fits, as well as a 2 pole priors fit. This is supported in a way that does one dataset at a time.

Attributes:
rawtraces : ndarray

The array of rawtraces to use when fitting the didv. Should be of shape (number of traces, length of trace in bins). This can be any units, as long as tracegain will convert this to Amps.

fs : float

Sample rate of the data taken, in Hz

sgfreq : float

Frequency of the signal generator, in Hz

sgamp : float

Amplitude of the signal generator, in Amps (equivalent to jitter in the QET bias)

r0 : float

Resistance of the TES in Ohms

r0_err : float

Error in the resistance of the TES (Ohms)

rload : float

Load resistance of the circuit (rload = rshunt + rparasitic), Ohms

rload_err : float

Error in the load resistance, Ohms

rshunt : float

Shunt resistance in the circuit, Ohms

tracegain : float

The factor that the rawtraces should be divided by to convert the units to Amps. If rawtraces already has units of Amps, then this should be set to 1.0

dutycycle : float

The duty cycle of the signal generator, should be a float between 0 and 1. Set to 0.5 by default

add180phase : boolean

If the signal generator is out of phase (i.e. if it looks like –__ instead of __–), then this should be set to True. Adds half a period of the signal generator to the dt0 attribute

priors : ndarray

Prior known values of Irwin’s TES parameters for the trace. Should be in the order of (rload,r0,beta,l,L,tau0,dt)

invpriorscov : ndarray

Inverse of the covariance matrix of the prior known values of Irwin’s TES parameters for the trace (any values that are set to zero mean that we have no knowledge of that parameter)

dt0 : float

The value of the starting guess for the time offset of the didv when fitting. The best way to use this value if it isn’t converging well is to run the fit multiple times, setting dt0 equal to the fit’s next value, and seeing where the dt0 value converges. The fit can have a difficult time finding the value on the first run if it the initial value is far from the actual value, so a solution is to do this iteratively.

freq : ndarray

The frequencies of the didv fit

time : ndarray

The times the didv trace

ntraces : float

The number of traces in the data

traces : ndarray

The traces being used in units of Amps and also truncated so as to include only an integer number of signal generator periods

flatinds : ndarray

The indices where the traces are flat

tmean : ndarray

The average trace in time domain, units of Amps

zeroinds : ndarray

The indices of the didv fit in frequency space where the values should be zero

didvstd : ndarray

The complex standard deviation of the didv in frequency space for each frequency

didvmean : ndarray

The average trace converted to didv

offset : float

The offset (i.e. baseline value) of the didv trace, in Amps

offset_err : float

The error in the offset of the didv trace, in Amps

fitparams1 : ndarray

The fit parameters of the 1-pole fit, in order of (A, tau2, dt)

fitcov1 : ndarray

The corresponding covariance for the 1-pole fit parameters

fitcost1 : float

The cost of the 1-pole fit

irwinparams1 : ndarray

The Irwin parameters of the 1-pole fit, in order of (rtot, L , r0, rload, dt)

irwincov1 : ndarray

The corresponding covariance for the Irwin parameters for the 1-pole fit

falltimes1 : ndarray

The fall times of the 1-pole fit, same as tau2, in s

didvfit1_timedomain : ndarray

The 1-pole fit in time domain

didvfit1_freqdomain : ndarray

The 1-pole fit in frequency domain

fitparams2 : ndarray

The fit parameters of the 2-pole fit, in order of (A, B, tau1, tau2, dt)

fitcov2 : ndarray

The corresponding covariance for the 2-pole fit parameters

fitcost2 : float

The cost of the 2-pole fit

irwinparams2 : ndarray

The Irwin parameters of the 2-pole fit, in order of (rload, r0, beta, l, L, tau0, dt)

irwincov2 : ndarray

The corresponding covariance for the Irwin parameters for the 2-pole fit

falltimes2 : ndarray

The fall times of the 2-pole fit, tau_plus and tau_minus, in s

didvfit2_timedomain : ndarray

The 2-pole fit in time domain

didvfit2_freqdomain : ndarray

The 2-pole fit in frequency domain

fitparams3 : ndarray

The fit parameters of the 3-pole fit, in order of (A, B, C, tau1, tau2, tau3, dt)

fitcov3 : ndarray

The corresponding covariance for the 3-pole fit parameters

fitcost3 : float

The cost of the 3-pole fit

irwinparams3 : NoneType

The Irwin parameters of the 3-pole fit, this returns None now, as there is no model that we convert to

irwincov3 : NoneType

The corresponding covariance for the Irwin parameters for the 3-pole fit, also returns None

falltimes3 : ndarray

The fall times of the 3-pole fit in s

didvfit3_timedomain : ndarray

The 3-pole fit in time domain

didvfit3_freqdomain : ndarray

The 3-pole fit in frequency domain

fitparams2priors : ndarray

The fit parameters of the 2-pole priors fit, in order of (A, B, tau1, tau2, dt), converted from the Irwin parameters

fitcov2priors : ndarray

The corresponding covariance for the 2-pole priors fit parameters

fitcost2priors : float

The cost of the 2-pole priors fit

irwinparams2priors : ndarray

The Irwin parameters of the 2-pole priors fit, in order of (rload, r0, beta, l, L, tau0, dt)

irwincov2priors : ndarray

The corresponding covariance for the Irwin parameters for the 2-pole priors fit

falltimes2priors : ndarray

The fall times of the 2-pole priors fit, tau_plus and tau_minus, in s

didvfit2priors_timedomain : ndarray

The 2-pole priors fit in time domain

didvfit2priors_freqdomain : ndarray

The 2-pole priors fit in frequency domain

Methods

doallfits() This module does all of the fits consecutively.
dofit(poles) This method does the fit that is specified by the variable poles.
dopriorsfit() This module runs the priorsfit, assuming that the priors and invpriorscov attributes have been set to the proper values.
get_irwinparams_dict(poles[, lgcpriors]) Returns a dictionary with the irwin fit parameters for a given number of poles
plot_didv_flipped([poles, plotpriors, …]) Module to plot the flipped trace in time domain.
plot_full_trace([poles, plotpriors, …]) Module to plot the entire trace in time domain
plot_re_im_didv([poles, plotpriors, …]) Module to plot the real and imaginary parts of the didv in frequency space.
plot_single_period_of_trace([poles, …]) Module to plot a single period of the trace in time domain
plot_zoomed_in_trace([poles, zoomfactor, …]) Module to plot a zoomed in portion of the trace in time domain.
processtraces() This method processes the traces loaded to the DIDV class object.
doallfits()

This module does all of the fits consecutively. The priors fit is not done if the attributes priors and invpriorscov have not yet been set.

dofit(poles)

This method does the fit that is specified by the variable poles. If the processtraces module has not been run yet, then this module will run that first. This module does not do the priors fit.

Parameters:
poles : int

The fit that should be run. Should be 1, 2, or 3.

dopriorsfit()

This module runs the priorsfit, assuming that the priors and invpriorscov attributes have been set to the proper values.

get_irwinparams_dict(poles, lgcpriors=False)

Returns a dictionary with the irwin fit parameters for a given number of poles

Parameters:
poles: int

The number of poles used for the fit

lgcpriors: bool, optional

If true, the values from the priors fit are returned

Returns:
return_dict: dictionary

The irwim parameters stored in a dictionary

plot_didv_flipped(poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')

Module to plot the flipped trace in time domain. This function should be used to test if there are nonlinearities in the didv

Parameters:
poles : int, string, array_like, optional

The pole fits that we want to plot. If set to “all”, then plots all of the fits. Can also be set to just one of the fits. Can be set as an array of different fits, e.g. [1, 2]

plotpriors : boolean, optional

Boolean value on whether or not the priors fit should be plotted.

lgcsave : boolean, optional

Boolean value on whether or not the figure should be saved

savepath : string, optional

Where the figure should be saved. Saved in the current directory by default.

savename : string, optional

A string to append to the end of the file name if saving. Empty string by default.

plot_full_trace(poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')

Module to plot the entire trace in time domain

Parameters:
poles : int, string, array_like, optional

The pole fits that we want to plot. If set to “all”, then plots all of the fits. Can also be set to just one of the fits. Can be set as an array of different fits, e.g. [1, 2]

plotpriors : boolean, optional

Boolean value on whether or not the priors fit should be plotted.

lgcsave : boolean, optional

Boolean value on whether or not the figure should be saved

savepath : string, optional

Where the figure should be saved. Saved in the current directory by default.

savename : string, optional

A string to append to the end of the file name if saving. Empty string by default.

plot_re_im_didv(poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')

Module to plot the real and imaginary parts of the didv in frequency space. Currently creates two different plots.

Parameters:
poles : int, string, array_like, optional

The pole fits that we want to plot. If set to “all”, then plots all of the fits. Can also be set to just one of the fits. Can be set as an array of different fits, e.g. [1, 2]

plotpriors : boolean, optional

Boolean value on whether or not the priors fit should be plotted.

lgcsave : boolean, optional

Boolean value on whether or not the figure should be saved

savepath : string, optional

Where the figure should be saved. Saved in the current directory by default.

savename : string, optional

A string to append to the end of the file name if saving. Empty string by default.

plot_single_period_of_trace(poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')

Module to plot a single period of the trace in time domain

Parameters:
poles : int, string, array_like, optional

The pole fits that we want to plot. If set to “all”, then plots all of the fits. Can also be set to just one of the fits. Can be set as an array of different fits, e.g. [1, 2]

plotpriors : boolean, optional

Boolean value on whether or not the priors fit should be plotted.

lgcsave : boolean, optional

Boolean value on whether or not the figure should be saved

savepath : string, optional

Where the figure should be saved. Saved in the current directory by default.

savename : string, optional

A string to append to the end of the file name if saving. Empty string by default.

plot_zoomed_in_trace(poles='all', zoomfactor=0.1, plotpriors=True, lgcsave=False, savepath='', savename='')

Module to plot a zoomed in portion of the trace in time domain. This plot zooms in on the overshoot of the didv.

Parameters:
poles : int, string, array_like, optional

The pole fits that we want to plot. If set to “all”, then plots all of the fits. Can also be set to just one of the fits. Can be set as an array of different fits, e.g. [1, 2]

zoomfactor : float, optional, optional

Number between zero and 1 to show different amounts of the zoomed in trace.

plotpriors : boolean, optional

Boolean value on whether or not the priors fit should be plotted.

lgcsave : boolean, optional

Boolean value on whether or not the figure should be saved

savepath : string, optional

Where the figure should be saved. Saved in the current directory by default.

savename : string, optional

A string to append to the end of the file name if saving. Empty string by default.

processtraces()

This method processes the traces loaded to the DIDV class object. This sets up the object for fitting.

qetpy.core._fitting module

qetpy.core._fitting.ofamp(signal, template, psd, fs, withdelay=True, coupling='AC', lgcsigma=False, nconstrain=None, lgcoutsidewindow=False, integralnorm=False)

Function for calculating the optimum amplitude of a pulse in data. Supports optimum filtering with and without time delay.

Parameters:
signal : ndarray

The signal that we want to apply the optimum filter to (units should be Amps). Can be an array of traces.

template : ndarray

The pulse template to be used for the optimum filter (should be normalized beforehand).

psd : ndarray

The two-sided psd that will be used to describe the noise in the signal (in Amps^2/Hz)

fs : float

The sample rate of the data being taken (in Hz).

withdelay : bool, optional

Determines whether or not the optimum amplitude should be calculate with (True) or without (False) using a time delay. With the time delay, the pulse is assumed to be at any time in the trace. Without the time delay, the pulse is assumed to be directly in the middle of the trace. Default is True.

coupling : str, optional

String that determines if the zero frequency bin of the psd should be ignored (i.e. set to infinity) when calculating the optimum amplitude. If set to ‘AC’, then ths zero frequency bin is ignored. If set to anything else, then the zero frequency bin is kept. Default is ‘AC’.

lgcsigma : Boolean, optional

If True, the estimated optimal filter energy resolution will be calculated and returned.

nconstrain : int, NoneType, optional

The length of the window (in bins) to constrain the possible t0 values to, centered on the unshifted trigger. If left as None, then t0 is uncontrained. If nconstrain is larger than nbins, then the function sets nconstrain to nbins, as this is the maximum number of values that t0 can vary over.

lgcoutsidewindow : bool, optional

Boolean flag that is used to specify whether ofamp should look inside nconstrain or outside it. If False, ofamp will minimize the chi^2 in the bins specified by nconstrain, which is the default behavior. If True, then ofamp will minimize the chi^2 in the bins that do not contain the constrained window.

integralnorm : bool, optional

If set to True, then ofamp will normalize the template to an integral of 1, and ofamp will instead return the optimal integral in units of Coulombs. If lgcsigma is set to True, then it will be returned in units of Coulombs as well. If set to False, then the usual optimal filter amplitude will be returned (in units of Amps).

Returns:
amp : float

The optimum amplitude calculated for the trace (in Amps).

t0 : float

The time shift calculated for the pulse (in s). Set to zero if withdelay is False.

chi2 : float

The chi^2 value calculated from the optimum filter.

sigma : float, optional

The optimal filter energy resolution (in Amps)

qetpy.core._fitting.ofamp_pileup(signal, template, psd, fs, a1=None, t1=None, coupling='AC', nconstrain1=None, nconstrain2=None, lgcoutsidewindow=True)

Function for calculating the optimum amplitude of a pileup pulse in data. Supports inputted the values of a previously known pulse for increased computational speed, but can be used on its own.

Parameters:
signal : ndarray

The signal that we want to apply the optimum filter to (units should be Amps).

template : ndarray

The pulse template to be used for the optimum filter (should be normalized beforehand).

psd : ndarray

The two-sided psd that will be used to describe the noise in the signal (in Amps^2/Hz)

fs : float

The sample rate of the data being taken (in Hz).

a1 : float, optional

The OF amplitude (in Amps) to use for the “main” pulse, e.g. the triggered pulse. This should be calculated beforehand using ofamp. This is only used if t1 is also inputted.

t1 : float, optional

The corresponding time offset (in seconds) to use for the “main” pulse, e.g. the triggered pulse. As with a1, this should be calculated beforehand using ofamp. This is only used if a1 is also inputted.

coupling : str, optional

String that determines if the zero frequency bin of the psd should be ignored (i.e. set to infinity) when calculating the optimum amplitude. If set to ‘AC’, then ths zero frequency bin is ignored. If set to anything else, then the zero frequency bin is kept. Default is ‘AC’.

nconstrain1 : int, NoneType, optional

If t1 is left as None, this is the length of the window (in bins) to constrain the possible t1 values to for the first pulse, centered on the unshifted trigger. If left as None, then t1 is uncontrained. If nconstrain1 is larger than nbins, then the function sets nconstrain1 to nbins, as this is the maximum number of values that t1 can vary over. This is only used if a1 or t1 is not given.

nconstrain2 : int, NoneType, optional

This is the length of the window (in bins) out of which to constrain the possible t2 values to for the pileup pulse, centered on the unshifted trigger. If left as None, then t2 is uncontrained. The value of nconstrain2 should be less than nbins.

lgcoutsidewindow : bool, optional

Boolean flag that is used to specify whether ofamp_pileup should look for the pileup pulse inside the bins specified by nconstrain2 or outside them. If True, ofamp will minimize the chi^2 in the bins ouside the range specified by nconstrain2, which is the default behavior. If False, then ofamp will minimize the chi^2 in the bins inside the constrained window specified by nconstrain2.

Returns:
a1 : float

The optimum amplitude (in Amps) calculated for the first pulse that was found, which is generally the triggered pulse.

t1 : float

The time shift calculated for the first pulse that was found (in s)

a2 : float

The optimum amplitude calculated for the pileup pulse (in Amps).

t2 : float

The time shift calculated for the pileup pulse (in s)

chi2 : float

The chi^2 value calculated for the pileup optimum filter.

qetpy.core._fitting.ofamp_pileup_stationary(signal, template, psd, fs, coupling='AC', nconstrain=None, lgcoutsidewindow=False)

Function for calculating the optimum amplitude of a pileup pulse in data, with the assumption that the triggered pulse is centered in the trace.

Parameters:
signal : ndarray

The signal that we want to apply the optimum filter to (units should be Amps).

template : ndarray

The pulse template to be used for the optimum filter (should be normalized beforehand).

psd : ndarray

The two-sided psd that will be used to describe the noise in the signal (in Amps^2/Hz)

fs : float

The sample rate of the data being taken (in Hz).

coupling : str, optional

String that determines if the zero frequency bin of the psd should be ignored (i.e. set to infinity) when calculating the optimum amplitude. If set to ‘AC’, then ths zero frequency bin is ignored. If set to anything else, then the zero frequency bin is kept. Default is ‘AC’.

nconstrain : int, NoneType, optional

This is the length of the window (in bins) out of which to constrain the possible t2 values to for the pileup pulse, centered on the unshifted trigger. If left as None, then t2 is uncontrained. The value of nconstrain should be less than nbins.

lgcoutsidewindow : bool, optional

Boolean flag that is used to specify whether the function should look for the pileup pulse inside the bins specified by nconstrain or outside them. If True, ofamp will minimize the chi^2 in the bins ouside the range specified by nconstrain, which is the default behavior. If False, then ofamp will minimize the chi^2 in the bins inside the constrained window specified by nconstrain.

Returns:
a1 : float

The optimum amplitude (in Amps) calculated for the first pulse that was found, which is the triggered pulse.

a2 : float

The optimum amplitude calculated for the pileup pulse (in Amps).

t2 : float

The time shift calculated for the pileup pulse (in s)

chi2 : float

The reduced chi^2 value of the fit.

qetpy.core._fitting.chi2lowfreq(signal, template, amp, t0, psd, fs, fcutoff=10000)

Function for calculating the low frequency chi^2 of the optimum filter, given some cut off frequency. This function does not calculate the optimum amplitude - it requires that ofamp has been run, and the fit has been loaded to this function.

Parameters:
signal : ndarray

The signal that we want to calculate the low frequency chi^2 of (units should be Amps).

template : ndarray

The pulse template to be used for the low frequency chi^2 calculation (should be normalized beforehand).

amp : float

The optimum amplitude calculated for the trace (in Amps).

t0 : float

The time shift calculated for the pulse (in s).

psd : ndarray

The two-sided psd that will be used to describe the noise in the signal (in Amps^2/Hz).

fs : float

The sample rate of the data being taken (in Hz).

fcutoff : float, optional

The frequency (in Hz) that we should cut off the chi^2 when calculating the low frequency chi^2.

Returns:
chi2low : float

The low frequency chi^2 value (cut off at fcutoff) for the inputted values.

qetpy.core._fitting.chi2_nopulse(signal, psd, fs, coupling='AC')

Function for calculating the chi^2 of a trace with the assumption that there is no pulse.

Parameters:
signal : ndarray

The signal that we want to calculate the no pulse chi^2 of (units should be Amps).

psd : ndarray

The two-sided psd that will be used to describe the noise in the signal (in Amps^2/Hz).

fs : float

The sample rate of the data being taken (in Hz).

coupling : str, optional

String that determines if the zero frequency bin of the psd should be ignored (i.e. set to infinity) when calculating the no pulse chi^2 . If set to ‘AC’, then the zero frequency bin is ignored. If set to anything else, then the zero frequency bin is kept. Default is ‘AC’.

Returns:
chi2_0 : float

The chi^2 value for there being no pulse.

class qetpy.core._fitting.OFnonlin(psd, fs, template=None)

Bases: object

This class provides the user with a non-linear optimum filter to estimate the amplitude, rise time (optional), fall time, and time offset of a pulse.

Methods

calcchi2(model) Function to calculate the reduced chi square
fit_falltimes(pulse[, lgcdouble, errscale, …]) Function to do the fit
onepole(A, tau_f, t0) Functional form of pulse in time domain with the amplitude, fall time, and time offset allowed to float, and the rise time held constant
residuals(params) Function ot calculate the weighted residuals to be minimized
twopole(A, tau_r, tau_f, t0) Functional form of pulse in frequency domain with the amplitude, rise time, fall time, and time offset allowed to float.
twopoletime(A, tau_r, tau_f, t0) Functional form of pulse in time domain with the amplitude, rise time, fall time, and time offset allowed to float
calcchi2(model)

Function to calculate the reduced chi square

Parameters:
model : ndarray

Array corresponding to pulse function (twopole or onepole) evaluated at the optimum values

Returns:
chi2 : float

The reduced chi squared statistic

fit_falltimes(pulse, lgcdouble=False, errscale=1, guess=None, taurise=None, lgcfullrtn=False, lgcplot=False)

Function to do the fit

Parameters:
pulse : ndarray

Time series traces to be fit

lgcdouble : bool, optional

If False, the twopole fit is done, if True, the one pole fit it done. Note, if True, the user must provide the value of taurise.

errscale : float or int, optional

A scale factor for the psd. Ex: if fitting an average, the errscale should be set to the number of traces used in the average

guess : tuple, optional

Guess of initial values for fit, must be the same size as the model being used for fit. If lgcdouble is True, then the order should be (ampguess, tauriseguess, taufallguess, t0guess). If lgcdouble is False, then the order should be (ampguess, taufallguess, t0guess).

taurise : float, optional

The value of the rise time of the pulse if the single pole function is being use for fit

lgcfullrtn : bool, optional

If False, only the best fit parameters are returned. If True, the errors in the fit parameters, the covariance matrix, and chi squared statistic are returned as well.

lgcplot : bool, optional

If True, diagnostic plots are returned.

Returns:
variables : tuple

The best fit parameters

errors : tuple

The corresponding fit errors for the best fit parameters

cov : ndarray

The convariance matrix returned from the fit

chi2 : float

The reduced chi squared statistic evaluated at the optimum point of the fit

Raises:
ValueError

if length of guess does not match the number of parameters needed in fit

onepole(A, tau_f, t0)

Functional form of pulse in time domain with the amplitude, fall time, and time offset allowed to float, and the rise time held constant

Parameters:
A : float

Amplitude of pulse

tau_f : float

Fall time of two-pole pulse

t0 : float

Time offset of two pole pulse

Returns:
pulse : ndarray, complex

Array of amplitude values as a function of freuqncy

residuals(params)

Function ot calculate the weighted residuals to be minimized

Parameters:
params : tuple

Tuple containing fit parameters

Returns:
z1d : ndarray

Array containing residuals per frequency bin. The complex data is flatted into single array

twopole(A, tau_r, tau_f, t0)

Functional form of pulse in frequency domain with the amplitude, rise time, fall time, and time offset allowed to float. This is meant to be a private function

Parameters:
A : float

Amplitude of pulse

tau_r : float

Rise time of two-pole pulse

tau_f : float

Fall time of two-pole pulse

t0 : float

Time offset of two pole pulse

Returns:
pulse : ndarray, complex

Array of amplitude values as a function of frequency

twopoletime(A, tau_r, tau_f, t0)

Functional form of pulse in time domain with the amplitude, rise time, fall time, and time offset allowed to float

Parameters:
A : float

Amplitude of pulse

tau_r : float

Rise time of two-pole pulse

tau_f : float

Fall time of two-pole pulse

t0 : float

Time offset of two pole pulse

Returns:
pulse : ndarray

Array of amplitude values as a function of time

class qetpy.core._fitting.MuonTailFit(psd, fs)

Bases: object

This class provides the user with a fitting routine to estimate the thermal muon tail fall time.

Methods

calcchi2(model) Function to calculate the chi square
fitmuontail(signal[, lgcfullrtn, errscale]) Function to do the fit
muontailfcn(A, tau) Functional form of a thermal muon tail in time domain with the amplitude and fall time allowed to float.
residuals(params) Function to calculate the weighted residuals to be minimized.
calcchi2(model)

Function to calculate the chi square

Parameters:
model : ndarray

Array corresponding to pulse function evaluated at the fitted values

Returns:
chi2 : float

The chi squared statistic

fitmuontail(signal, lgcfullrtn=False, errscale=1)

Function to do the fit

Parameters:
signal: ndarray

Time series traces to be fit

lgcfullrtn : bool, optional

If False, only the best fit parameters are returned. If True, the errors in the fit parameters, the covariance matrix, and chi squared statistic are returned as well.

errscale : float or int, optional

A scale factor for the psd. Ex: if fitting an average, the errscale should be set to the number of traces used in the average

Returns:
variables : tuple

The best fit parameters

errors : tuple

The corresponding fit errors for the best fit parameters

cov : ndarray

The convariance matrix returned from the fit

chi2 : float

The chi squared statistic evaluated at the fit

muontailfcn(A, tau)

Functional form of a thermal muon tail in time domain with the amplitude and fall time allowed to float.

Parameters:
A : float

Amplitude of pulse

tau : float

Fall time of muon tail

Returns:
pulse : ndarray

Array of amplitude values as a function of time

residuals(params)

Function to calculate the weighted residuals to be minimized.

Parameters:
params : tuple

Tuple containing fit parameters

Returns:
z1d : ndarray

Array containing residuals per frequency bin. The complex data is flatted into single array.

qetpy.core._iv module

class qetpy.core._iv.IV(dites, dites_err, vb, vb_err, rload, rload_err, chan_names, normalinds=None)

Bases: object

Class for creating the IV curve and calculating various values, such as the normal resistance, the resistance of the TES, the power, etc., as well as the corresponding errors. This class supports data for multple bath temperatures, multiple channels, and multiple bias points.

Note: If different bath temperatures have different numbers of bias points (iters), then the user should pad the end of the arrays with NaN so that the data can be put into an ndarray and loaded into this class.

Attributes:
dites : ndarray

The current read out by the electronics

dites_err : ndarray

The error in the current read out by the electronics

vb : ndarray

The bias voltage (vb = qet bias * rshunt)

vb_err : ndarray

The corresponding error in the bias voltage

rload : scalar, ndarray

The load resistance, this can be scalar if using the same rload for all values. If 1-dimensional, then this should be the load resistance for each channel. If 2-dimensional, this should be the load resistance for each bath temperature and each bias point, where the shape is (ntemps, nch). If 3-dimensional, then this should be with shape (ntemps, nch, niters)

rload_err : scalar, ndarray

The corresponding error in the load resistance, should be the same type as rload

chan_names : array_like

Array of strings corresponding to the names of each channel in the data. Should have the same length as the nch axis in dites

ioff : ndarray

The current offset calculated from the fit, shape (ntemps, nch)

ioff_err : ndarray

The corresponding error in the current offset

rfit : ndarray

The total resistance (rnorm + rload) from the fit, shape (ntemps, nch)

rfit_err : ndarray

The corresponding error in the fit resistance

rnorm : ndarray

The normal resistance of the TES, using the fit, shape (ntemps, nch)

rnorm_err : ndarray

The corresponding error in the normal resistance

ites : ndarray

The calculated current through the TES, shape (ntemps, nch, niters)

ites_err : ndarray

The corresponding error in the current through the TES

r0 : ndarray

The calculated resistance of the TES, shape (ntemps, nch, niters)

r0_err : ndarray

The corresponding error in the resistance of the TES

ptes : ndarray

The calculated power of the TES, shape (ntemps, nch, niters)

ptes_err : ndarray

The corresponding error in the power of the TES

Methods

calc_iv() Method to calculate the IV curve for the intialized object.
plot_all_curves([temps, chans, showfit, …]) Function to plot the IV, resistance, and power curves for the data in an IV object.
plot_iv([temps, chans, showfit, lgcsave, …]) Function to plot the IV curves for the data in an IV object.
plot_pv([temps, chans, lgcsave, savepath, …]) Function to plot the power curves for the data in an IV object.
plot_rv([temps, chans, lgcsave, savepath, …]) Function to plot the resistance curves for the data in an IV object.
calc_iv()

Method to calculate the IV curve for the intialized object. Calculates the power and resistance of each bias point, as well as saving the fit parameters from the fit to the normal points and the calculated normal reistance from these points.

plot_all_curves(temps='all', chans='all', showfit=True, lgcsave=False, savepath='', savename='')

Function to plot the IV, resistance, and power curves for the data in an IV object.

Parameters:
temps : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

chans : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

showfit : boolean, optional

Boolean flag to also plot the linear fit to the normal data

lgcsave : boolean, optional

Boolean flag to save the plot

savepath : string, optional

Path to save the plot to, saves it to the current directory by default

savename : string, optional

Name to append to the plot file name, if saving

plot_iv(temps='all', chans='all', showfit=True, lgcsave=False, savepath='', savename='')

Function to plot the IV curves for the data in an IV object.

Parameters:
temps : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

chans : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

showfit : boolean, optional

Boolean flag to also plot the linear fit to the normal data

lgcsave : boolean, optional

Boolean flag to save the plot

savepath : string, optional

Path to save the plot to, saves it to the current directory by default

savename : string, optional

Name to append to the plot file name, if saving

plot_pv(temps='all', chans='all', lgcsave=False, savepath='', savename='')

Function to plot the power curves for the data in an IV object.

Parameters:
temps : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

chans : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

lgcsave : boolean, optional

Boolean flag to save the plot

savepath : string, optional

Path to save the plot to, saves it to the current directory by default

savename : string, optional

Name to append to the plot file name, if saving

plot_rv(temps='all', chans='all', lgcsave=False, savepath='', savename='')

Function to plot the resistance curves for the data in an IV object.

Parameters:
temps : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

chans : string, array_like, int, optional

Which bath temperatures to plot. Setting to “all” plots all of them. Can also set to a subset of bath temperatures, or just one

lgcsave : boolean, optional

Boolean flag to save the plot

savepath : string, optional

Path to save the plot to, saves it to the current directory by default

savename : string, optional

Name to append to the plot file name, if saving

qetpy.core._noise module

qetpy.core._noise.foldpsd(psd, fs)

Return the one-sided version of the inputted two-sided psd.

Parameters:
psd : ndarray

A two-sided psd to be converted to one-sided

fs : float

The sample rate used for the psd

Returns:
f : ndarray

The frequencies corresponding to the outputted one-sided psd

psd_folded : ndarray

The one-sided (folded over) psd corresponding to the inputted two-sided psd

qetpy.core._noise.calc_psd(x, fs=1.0, folded_over=True)

Return the PSD of an n-dimensional array, assuming that we want the PSD of the last axis.

Parameters:
x : array_like

Array to calculate PSD of.

fs : float, optional

Sample rate of the data being taken, assumed to be in units of Hz.

folded_over : bool, optional

Boolean value specifying whether or not the PSD should be folded over. If True, then the symmetric values of the PSD are multiplied by two, and we keep only the positive frequencies. If False, then the entire PSD is saved, including positive and negative frequencies. Default is to fold over the PSD.

Returns:
f : ndarray

Array of sample frequencies

psd : ndarray

Power spectral density of ‘x’

qetpy.core._noise.gen_noise(psd, fs=1.0, ntraces=1)

Function to generate noise traces with random phase from a given PSD. The PSD calculated from the generated noise traces should be the equivalent to the inputted PSD as the number of traces goes to infinity.

Parameters:
psd : ndarray

The two-sided power spectral density that will be used to generate the noise.

fs : float, optional

Sample rate of the data being taken, assumed to be in units of Hz.

ntraces : int, optional

The number of noise traces that should be generated. Default is 1.

Returns:
noise : ndarray

An array containing all of the generated noise traces from the inputted PSD. Has shape (ntraces, len(psd)).

class qetpy.core._noise.Noise(traces, fs, channames, tracegain=1.0, fname=None, time=None)

Bases: object

This class allows the user to calculate the power spectral densities of signals from detectors, study correlations, and decouple the intrinsic noise from cross channel correlated noise.

Attributes:
traces : ndarray

Array of the traces to use in the noise analysis. Should be shape (# of traces, # of channels, # of bins)

fs : float

The digitization rate of the data in Hz.

channames : list

A list of strings that name each of the channels.

time : ndarray

The time values for each bin in each trace.

fname : str

The file name of the data, this will be used when saving the file.

tracegain : float

The factor that traces should be divided by to convert the units to Amps. If rawtraces already has units of Amps, then this should be set to 1.0

freqs : ndarray

The frequencies that correspond to each value in the spectral densities

psd : ndarray

The power spectral density of the data in A^2/Hz

realpsd : ndarray

The real power spectral density of the data in A^2/Hz

imagpsd : ndarray

The imaginary power spectral density of the data in A^2/Hz

corrcoeff : ndarray

The array of the correlation coefficients between each of the channels

uncorrnoise : ndarray

The uncorrelated noise psd in A^2/Hz

corrnoise : ndarray

The correlated noise psd in A^2/Hz

realcsd : ndarray

The real part of the cross spectral density in A^2/Hz

imagcsd : ndarray

The imaginary part of the cross spectral density in A^2/Hz

realcsdstd : ndarray

The standard deviation of the real part of the cross spectral density at each frequency

imagcsdstd : ndarray

The standard deviation of the imaginary part of the cross spectral density at each frequency

csd : ndarray

The cross spectral density of the traces

chandict : dict

A dictionary that stores the channel number for each channel name.

Methods

calculate_corrcoeff() Calculates the correlations between channels as a function of frequency.
calculate_csd() Calculates the csd for each channel in traces.
calculate_psd() Calculates the psd for each channel in traces.
calculate_uncorr_noise() Calculates the uncorrelated and correlated total noise.
plot_corrcoeff([lgcsmooth, nwindow, …]) Function to plot the cross channel correlation coefficients.
plot_csd([whichcsd, lgcreal, lgcsave, savepath]) Function to plot the cross channel noise spectrum referenced to the TES line in units of Amperes^2/Hz
plot_decorrelatednoise([lgcoverlay, …]) Function to plot the de-correlated noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz) from fitted parameters calculated calculate_deCorrelated_noise
plot_psd([lgcoverlay, lgcsave, savepath]) Function to plot the noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz).
plot_reim_psd([lgcsave, savepath]) Function to plot the real vs imaginary noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz).
remove_trace_slope() Function to remove the slope from each trace.
save(path) Saves the noise object as a pickle file
calculate_corrcoeff()

Calculates the correlations between channels as a function of frequency. Stores results in self.corrcoeff

calculate_csd()

Calculates the csd for each channel in traces. Stores csd in self.csd

calculate_psd()

Calculates the psd for each channel in traces. Stores psd in self.psd

calculate_uncorr_noise()

Calculates the uncorrelated and correlated total noise.

plot_corrcoeff(lgcsmooth=True, nwindow=7, lgcsave=False, savepath=None)

Function to plot the cross channel correlation coefficients. Since there are typically few traces, the correlations are often noisy. a savgol_filter is used to smooth out some of the noise

Parameters:
lgcsmooth : boolean, optional

If True, a savgol_filter will be used when plotting.

nwindow : int, optional

the number of bins used for the window in the savgol_filter

lgcsave : boolean, optional

If True, the figure is saved in the user provided directory

savepath : str, optional

Absolute path for the figure to be saved

plot_csd(whichcsd=['01'], lgcreal=True, lgcsave=False, savepath=None)

Function to plot the cross channel noise spectrum referenced to the TES line in units of Amperes^2/Hz

Parameters:
whichcsd : list, optional

a list of strings, where each element of the list refers to the pair of indices of the desired csd plot

lgcreal : boolean, optional

If True, the Re(csd) is plotted. If False, the Im(csd) is plotted

lgcsave : boolean, optional

If True, the figure is saved in the user provided directory

savepath : str, optional

Absolute path for the figure to be saved

plot_decorrelatednoise(lgcoverlay=False, lgcdata=True, lgcuncorrnoise=True, lgccorrelated=False, lgcsum=False, lgcsave=False, savepath=None)

Function to plot the de-correlated noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz) from fitted parameters calculated calculate_deCorrelated_noise

Parameters:
lgcoverlay : boolean, optional

If True, de-correlated for all channels are overlayed in a single plot, If False, the noise for each channel is plotted in a seperate subplot

lgcdata : boolean, optional

Only applies when lgcoverlay = False. If True, the csd data is plotted

lgcuncorrnoise : boolean, optional

Only applies when lgcoverlay = False. If True, the de-correlated noise is plotted

lgccorrelated : boolean, optional

Only applies when lgcoverlay = False. If True, the correlated component of the fitted noise is plotted

lgcsum : boolean, optional

Only applies when lgcoverlay = False. If True, the sum of the fitted de-correlated noise and and correlated noise is plotted

lgcsave : boolean, optional

If True, the figure is saved in the user provided directory

savepath : str, optional

Absolute path for the figure to be saved

plot_psd(lgcoverlay=True, lgcsave=False, savepath=None)

Function to plot the noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz).

Parameters:
lgcoverlay : boolean, optional

If True, psd’s for all channels are overlayed in a single plot, If False, each psd for each channel is plotted in a seperate subplot

lgcsave : boolean, optional

If True, the figure is saved in the user provided directory

savepath : str, optional

Absolute path for the figure to be saved

plot_reim_psd(lgcsave=False, savepath=None)

Function to plot the real vs imaginary noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz). This is done to check for thermal muon tails making it passed the quality cuts

Parameters:
lgcsave : boolean, optional

If True, the figure is saved in the user provided directory

savepath : str, optional

Absolute path for the figure to be saved

remove_trace_slope()

Function to remove the slope from each trace. self.traces is changed to be the slope subtracted traces.

save(path)

Saves the noise object as a pickle file

Parameters:
path : str

Path where the noise object should be saved.