Welcome to the QETpy documentation¶
QETpy (Quasiparticle-trap-assisted Electrothermal-feedback Transition-edge sensors) provides tools for TES based detector calibration and analysis. It contains submodules for noise modeling, IV analysis, complex impedance fitting, non-linear optimum filter pulse fitting, and many other useful detector R&D analysis tools.
Descriptions of all the functions can be found below, as well as examples of how to use most of the functionality of QETpy.
This code is available on GitHub: https://github.com/ucbpylegroup/QETpy
Installation¶
For the most recent stable release, at the command line:
pip install qetpy
Or, if you want to work with the lastest development version. Clone the repository from: https://github.com/berkeleycdms/qetpy.git. Then within the repository, from the command line:
python setup.py clean
python setpy.py install --user
Note, you can check what version is available on PyPi by looking at the badge on the README on the GitHub homepage.
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
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.
qetpy.cut package¶
-
qetpy.cut._cut.
removeoutliers
(x, maxiter=20, skewtarget=0.05)¶ Function to return indices of inlying points, removing points by minimizing the skewness
Parameters: - x : ndarray
Array of real-valued variables from which to remove outliers.
- maxiter : float, optional
Maximum number of iterations to continue to minimize skewness. Default is 20.
- skewtarget : float, optional
Desired residual skewness of distribution. Default is 0.05.
Returns: - inds : ndarray
Boolean indices indicating which values to select/reject, same length as x.
-
qetpy.cut._cut.
iterstat
(data, cut=3, precision=1000.0)¶ Function to iteratively remove outliers based on how many standard deviations they are from the mean, where the mean and standard deviation are recalculated after each cut.
Parameters: - data : ndarray
Array of data that we want to remove outliers from
- cut : float, optional
Number of standard deviations from the mean to be used for outlier rejection
- precision : float, optional
Threshold for change in mean or standard deviation such that we stop iterating. The threshold is determined by np.std(data)/precision. This means that a higher number for precision means a lower threshold (i.e. more iterations).
Returns: - datamean : float
Mean of the data after outliers have been removed.
- datastd : float
Standard deviation of the data after outliers have been removed
- datamask : ndarray
Boolean array indicating which values to keep or reject in data, same length as data.
-
qetpy.cut._cut.
autocuts
(traces, fs=625000.0, is_didv=False, sgfreq=200.0, symmetrizeflag=False, outlieralgo='removeoutliers', lgcpileup1=True, lgcslope=True, lgcbaseline=True, lgcpileup2=True, lgcchi2=True, nsigpileup1=2, nsigslope=2, nsigbaseline=2, nsigpileup2=2, nsigchi2=3)¶ Function to automatically cut out bad traces based on the optimum filter amplitude, slope, baseline, and chi^2 of the traces.
Parameters: - traces : ndarray
2-dimensional array of traces to do cuts on
- fs : float, optional
Sample rate that the data was taken at
- is_didv : bool, optional
Boolean flag on whether or not the trace is a dIdV curve
- sgfreq : float, optional
If is_didv is True, then the sgfreq is used to know where the flat parts of the traces should be
- symmetrizeflag : bool, optional
Flag for whether or not the slopes should be forced to have an average value of zero. Should be used if most of the traces have a slope
- outlieralgo : string, optional
Which outlier algorithm to use. If set to “removeoutliers”, uses the removeoutliers algorithm that removes data based on the skewness of the dataset. If set to “iterstat”, uses the iterstat algorithm to remove data based on being outside a certain number of standard deviations from the mean
- lgcpileup1 : boolean, optional
Boolean value on whether or not do the pileup1 cut (this is the initial pileup cut that is always done whether or not we have dIdV data). Default is True.
- lgcslope : boolean, optional
Boolean value on whether or not do the slope cut. Default is True.
- lgcbaseline : boolean, optional
Boolean value on whether or not do the baseline cut. Default is True.
- lgcpileup2 : boolean, optional
Boolean value on whether or not do the pileup2 cut (this cut is only done when is_didv is also True). Default is True.
- lgcchi2 : boolean, optional
Boolean value on whether or not do the chi2 cut. Default is True.
- nsigpileup1 : float, optional
If outlieralgo is “iterstat”, this can be used to tune the number of standard deviations from the mean to cut outliers from the data when using iterstat on the optimum filter amplitudes. Default is 2.
- nsigslope : float, optional
If outlieralgo is “iterstat”, this can be used to tune the number of standard deviations from the mean to cut outliers from the data when using iterstat on the slopes. Default is 2.
- nsigbaseline : float, optional
If outlieralgo is “iterstat”, this can be used to tune the number of standard deviations from the mean to cut outliers from the data when using iterstat on the baselines. Default is 2.
- nsigpileup2 : float, optional
If outlieralgo is “iterstat”, this can be used to tune the number of standard deviations from the mean to cut outliers from the data when using iterstat on the optimum filter amplitudes after the mean has been subtracted. (only used if is_didv is True). Default is 2.
- nsigchi2 : float, optional
This can be used to tune the number of standard deviations from the mean to cut outliers from the data when using iterstat on the chi^2 values. Default is 3. This is always used, as iterstat is always used for the chi^2 cut.
Returns: - ctot : ndarray
Boolean array giving which indices to keep or throw out based on the autocuts algorithm
-
qetpy.cut._cut.
get_muon_cut
(traces, thresh_pct=0.95, nsatbins=600)¶ Function to help identify saturated muons from array of time series traces.
*Traces must have POSITIVE going pulses*
Note, for best results, only large amplitude traces should based to this function. The user may need to play around with the thresh_pct and nsatbins parameters to achive the desired result.
Parameters: - traces: array
Array of time series traces of shape (#number of traces, #bins per trace).
- thresh_pct: float, optional
The percentage of the maximum amplitude that the pulse must remain above for nsatbins in order to be considered `saturated’.
- nsatbins: int, optional
The minimum number of bins that a muon should be saturated for.
Returns: - muon_cut: array
Boolean array corresponding to saturated muon events
qetpy.plotting package¶
-
qetpy.plotting._plotting.
plot_psd
(noise, lgcoverlay=True, lgcsave=False, savepath=None)¶ Function to plot the noise spectrum referenced to the TES line in units of Amperes/sqrt(Hz).
Parameters: - noise : Object
Noise object to be plotted
- 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
-
qetpy.plotting._plotting.
plot_reim_psd
(noise, 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: - noise : Object
Noise object to be 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
-
qetpy.plotting._plotting.
plot_corrcoeff
(noise, 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: - noise : Object
noise object to be plotted
- 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
-
qetpy.plotting._plotting.
plot_csd
(noise, 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: - noise : Object
Noise object to be plotted
- 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
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: - noise : Object
Noise object to be plotted
- 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
-
qetpy.plotting._plotting.
compare_noise
(arr, channels, lgcdecorrelatednoise=False, lgcsave=False, savepath=None)¶ Function to plot multiple psd’s from different noise objects on the same figure. Each channel will be plotted in its own figure.
Parameters: - arr : array_like
Array of noise objects
- channels : list
List of strings, each string is a channel to plot. ex [‘PSA1’,’PAS2’]
- lgcdecorrelatednoise : boolean, optional
If False, the psd is for each channel is plotted. If True, the calculated de-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
-
qetpy.plotting._plotting.
plot_noise_sim
(f, psd, noise_sim, istype, figsize=(12, 8), lgcsave=False, savepath='')¶ Plots psd with simulated noise model
Parameters: - f : array_like
Frequency bins for psd
- psd : array_like
Power spectral density
- istype : str
Must be ‘current’ or ‘power’ If ‘current’ the noise is plotted referenced to TES current If ‘power’ the noise is plotted referenced to TES power
- figsize : tuple, optional
Desired size of figure
- lgcsave : boolean, optional
If True, plot is saved
- savepath : str, optional
Directory to save trace
Returns: - fig : Object
fig object from matplotlib.pyplot
- ax : Object
ax object from matplotlib.pyplot
-
qetpy.plotting._plotting.
plot_full_trace
(didv, poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')¶ Function to plot the entire trace in time domain
Parameters: - didv : class
The DIDV class object that the data is stored in
- 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.
-
qetpy.plotting._plotting.
plot_single_period_of_trace
(didv, poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')¶ Function to plot a single period of the trace in time domain
Parameters: - didv : class
The DIDV class object that the data is stored in
- 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.
-
qetpy.plotting._plotting.
plot_zoomed_in_trace
(didv, poles='all', zoomfactor=0.1, plotpriors=True, lgcsave=False, savepath='', savename='')¶ Function to plot a zoomed in portion of the trace in time domain. This plot zooms in on the overshoot of the didv.
Parameters: - didv : class
The DIDV class object that the data is stored in
- 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.
-
qetpy.plotting._plotting.
plot_didv_flipped
(didv, poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')¶ Function to plot the flipped trace in time domain. This function should be used to test if there are nonlinearities in the didv
Parameters: - didv : class
The DIDV class object that the data is stored in
- 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.
-
qetpy.plotting._plotting.
plot_re_im_didv
(didv, poles='all', plotpriors=True, lgcsave=False, savepath='', savename='')¶ Function to plot the real and imaginary parts of the didv in frequency space. Currently creates two different plots.
Parameters: - didv : class
The DIDV class object that the data is stored in
- 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.
-
qetpy.plotting._plotting.
plot_iv
(IVobject, temps='all', chans='all', showfit=True, lgcsave=False, savepath='', savename='')¶ Function to plot the IV curves for the data in an IV object.
Parameters: - IVobject : class
The IV class object that the data is stored in.
- 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
-
qetpy.plotting._plotting.
plot_rv
(IVobject, temps='all', chans='all', lgcsave=False, savepath='', savename='')¶ Function to plot the resistance curves for the data in an IV object.
Parameters: - IVobject : class
The IV class object that the data is stored in.
- 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.plotting._plotting.
plot_pv
(IVobject, temps='all', chans='all', lgcsave=False, savepath='', savename='')¶ Function to plot the power curves for the data in an IV object.
Parameters: - IVobject : class
The IV class object that the data is stored in.
- 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.plotting._plotting.
plot_all_curves
(IVobject, 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: - IVobject : class
The IV class object that the data is stored in.
- 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
-
qetpy.plotting._plotting.
plotnonlin
(OFnonlinOBJ, pulse, params, errors)¶ Diagnostic plotting of non-linear pulse fitting
Parameters: - OFnonlinOBJ: OFnonlin object
The OFnonlin fit object to be plotted
- pulse: ndarray
The raw trace to be fit
- params: tuple
Tuple containing best fit paramters
qetpy.utils package¶
-
qetpy.utils._utils.
calc_offset
(x, fs=1.0, sgfreq=100.0, is_didv=False)¶ Calculates the DC offset of time series trace.
Parameters: - x : ndarray
Array to calculate offsets of.
- fs : float, optional
Sample rate of the data being taken, assumed to be in units of Hz.
- sgfreq : float, optional
The frequency of signal generator (if is_didv is True. If False, then this is ignored).
- is_didv : bool, optional
If False, average of full trace is returned. If True, then the average of n Periods is returned (where n is the max number of full periods present in a trace).
Returns: - offset : ndarray
Array of offsets with same shape as input x minus the last dimension
- std : ndarray
Array of std with same shape as offset
-
qetpy.utils._utils.
lowpassfilter
(traces, cut_off_freq=100000, fs=625000.0, order=1)¶ Applies a low pass filter to the inputted time series traces
Parameters: - traces : ndarray
An array of shape (# traces, # bins per trace).
- cut_off_freq : float, int, optional
The cut off 3dB frequency for the low pass filter, defaults to 100kHz.
- fs : float, int, optional
Digitization rate of data, defaults to 625e3 Hz.
- order : int, optional
The order of the low pass filter, defaults to 1.
Returns: - filt_traces : ndarray
Array of low pass filtered traces with the same shape as inputted traces.
-
qetpy.utils._utils.
align_traces
(traces, lgcjustshifts=False, n_cut=5000, cut_off_freq=5000.0, fs=625000.0)¶ Function to align dIdV traces if each trace does not trigger at the same point. Uses a convolution of the traces to find the time offset.
Parameters: - traces : ndarray
Array of shape (# traces, # bins per trace).
- lgcjustshifts : boolean, optional
If False, the aligned traces and the phase shifts are returned. If True, just the phase shifts are returned. Default is False.
- n_cut : int, optional
The number of bins to use to do the convolution. Just need enough information to see the periodic signal. Default is 5000.
- cut_off_freq : float or int, optional
3dB cut off frequency for filter. Default is 5000 Hz.
- fs : float or int, optional
Sample rate of data in Hz. Default is 625e3 Hz.
Returns: - shifts : ndarray
Array of phase shifts for each trace in units of bins.
- masked_aligned : masked ndarray, optional
Array of time shift corrected traces, same shape as input traces. The masked array masks the np.NaN values in the time shifted traces so that normal numpy functions will ignore the nan’s in computations.
-
qetpy.utils._utils.
get_offset_from_muon
(avemuon, qetbias, rn, rload, rsh=0.005, nbaseline=6000, lgcfullrtn=True)¶ Function to calculate the offset in the measured TES current using an average muon.
Parameters: - avemuon : array
An average of ‘good’ muons in time domain, referenced to TES current
- qetbias : float
Applied QET bias current
- rn : float
Normal resistance of the TES
- rload : float
Load resistance of TES circuit (rp + rsh)
- rsh : float, optional
Value of the shunt resistor for the TES circuit
- nbaseline : int, optional
The number of bins to use to calculate the baseline, i.e. [0:nbaseline]
- lgcfullrtn : bool, optional
If True, the offset, r0, i0, and bias power is returned, If False, just the offset is returned
Returns: - ioffset : float
The offset in the measured TES current
- r0 : float
The resistance of the TES
- i0 : float
The quiescent current through the TES
- p0 : float
The quiescent bias power of the TES
-
qetpy.utils._utils.
powertrace_simple
(trace, ioffset, qetbias, rload, rsh)¶ Function to convert time series trace from units of TES current to units of power.
The function takes into account the second order depenace on current, but assumes the infinite irwin loop gain approximation.
Parameters: - trace : array
Time series trace, referenced to TES current
- ioffset : float
The offset in the measured TES current
- qetbias : float
Applied QET bias current
- rload : float
Load resistance of TES circuit (rp + rsh)
- rsh : float, optional
Value of the shunt resistor for the TES circuit
Returns: - trace_p : array
Time series trace, in units of power referenced to the TES
-
qetpy.utils._utils.
integrate_powertrace_simple
(trace, time, nbasepre, nbasepost, ioffset, qetbias, rload, rsh)¶ Function to calculate the energy collected by the TESs by integrating the power in the TES as a function of time.
Parameters: - trace : array
Time series trace, referenced to TES current
- time : array
Array of time values corresponding to the trace array
- nbasepre : int
The bin number corresponding to the pre-pulse baseline, i.e. [0:nbasepre]
- nbasepost : int
The bin number corresponding to the post-pulse baseline, i.e. [nbasepost:-1]
- ioffset : float
The offset in the measured TES current
- qetbias : float
Applied QET bias current
- rload : float
Load resistance of TES circuit (rp + rsh)
- rsh : float, optional
Value of the shunt resistor for the TES circuit
Returns: - integrated_energy : float
The energy absorbed by the TES in units of eV
-
qetpy.utils._utils.
stdcomplex
(x, axis=0)¶ Function to return complex standard deviation (individually computed for real and imaginary components) for an array of complex values.
Parameters: - x : ndarray
An array of complex values from which we want the complex standard deviation.
- axis : int, optional
Which axis to take the standard deviation of (should be used if the dimension of the array is greater than 1)
Returns: - std_complex : ndarray
The complex standard deviation of the inputted array, along the specified axis.
-
qetpy.utils._utils.
slope
(x, y, removemeans=True)¶ Computes the maximum likelihood slope of a set of x and y points.
Parameters: - x : array_like
Array of real-valued independent variables.
- y : array_like
Array of real-valued dependent variables.
- removemeans : boolean
Boolean flag for if the mean of x should be subtracted. This should be set to True if x has not already had its mean subtracted. Set to False if the mean has been subtracted. Default is True.
Returns: - slope : float
Maximum likelihood slope estimate, calculated as sum((x-<x>)(y-<y>))/sum((x-<x>)**2)
-
qetpy.utils._utils.
fill_negatives
(arr)¶ Simple helper function to remove negative and zero values from PSD’s and replace them with interpolated values.
Parameters: - arr: ndarray
Array of values to replace neagive values on
Returns: - arr: ndarray
Modified input array with the negative and zero values replace by interpelate values
qetpy.sim package¶
-
qetpy.sim._sim.
loadfromdidv
(DIDVobj, G=5e-10, qetbias=0.00016, tc=0.04, tload=0.9, tbath=0.02, squiddc=2.5e-12, squidpole=0.0, squidn=1.0, noisetype='transition', lgcpriors=False)¶ Function for loading the parameters from a DIDV class object.
Parameters: - DIDVobj : Object
A DIDV class object after a fit has been run, such that there are Irwin parameters that can be used to model the noise.
- G : float, optional
The thermal conductance of the TES in W/K
- qetbias : float, optional
The QET bias in Amps
- tc : float
The critical temperature of the TES in K
- tload : float
The effective temperature of the load resistor in K
- tbath : float
The bath temperature in K
- squiddc : float, optional
The DC value of the SQUID and downstream electronics noise, in Amps/rtHz. The SQUID/electronics noise should have been fit beforehand, using the following model:
(squiddc*(1.0+(squidpole/f)**squidn))**2.0
- squidpole : float, optional
The frequency pole for the SQUID and downstream electronics noise, in Hz. The SQUID/electronics noise should have been fit beforehand, using the following model:
(squiddc*(1.0+(squidpole/f)**squidn))**2.0
- squidn : float, optional
The power of the SQUID and downstream electronics noise, in Hz. The SQUID/electronics noise should have been fit beforehand, using the following model:
(squiddc*(1.0+(squidpole/f)**squidn))**2.0
- noisetype : str, optional
The type of the noise that is to be loaded. The options are transition : Use the Irwin parameters from the two pole fit as the transition noise model superconducting : Use the Irwin parameters from the one pole fit as the superconducting noise model normal : Use the Irwin parameters from the one pole fit as the normal noise model
- lgcpriors : bool, optional
If True, the priors fit values are loaded from the didv object, if False, the regular fit values are loaded
Returns: - TESobj : Object
A TESnoise class object with all of the fit parameters loaded.
-
class
qetpy.sim._sim.
TESnoise
(freqs=None, rload=0.012, r0=0.15, rshunt=0.005, beta=1.0, loopgain=10.0, inductance=4e-07, tau0=0.0005, G=5e-10, qetbias=0.00016, tc=0.04, tload=0.9, tbath=0.02, n=5.0, lgcb=True, squiddc=2.5e-12, squidpole=0.0, squidn=1.0)¶ Bases:
object
Class for the simulation of the TES noise using the simple Irwin theory. Supports noise simulation for in transition, superconducting, and normal.
Attributes: - freqs : float, array_like
The frequencies for which we will calculate the noise simulation
- rload : float
The load resistance of the TES (sum of shunt and parasitic resistances) in Ohms
- r0 : float
The bias resistance of the TES in Ohms
- rshunt : float
The shunt resistance of the TES circuit in Ohms
- beta : float
The current sensitivity of the TES (dlogR/dlogI), unitless
- loopgain : float
The Irwin loop gain of the TES, unitless
- inductance : float
The inductance of the TES circuit in Henries
- tau0 : float
The thermal time constant (equals C/G) in s
- G : float
The thermal conductance of the TES in W/K
- qetbias : float
The QET bias in Amps
- tc : float
The critical temperature of the TES in K
- tload : float
The effective temperature of the load resistor in K
- tbath : float
The bath temperature in K
- n : float
The power-law dependence of the power flow to the heat bath
- lgcb : boolean
Boolean flag that determines whether we use the ballistic (True) or diffusive limit when calculating TFN power noise
- squiddc : float
The frequency pole for the SQUID and downstream electronics noise, in Hz. The SQUID/electronics noise should have been fit beforehand, using the following model:
(squiddc*(1.0+(squidpole/f)**squidn))**2.0
- squidpole : float
The frequency pole for the SQUID and downstream electronics noise, in Hz. The SQUID/electronics noise should have been fit beforehand, using the following model:
(squiddc*(1.0+(squidpole/f)**squidn))**2.0
- squidn : float
The power of the SQUID and downstream electronics noise, in Hz. The SQUID/electronics noise should have been fit beforehand, using the following model:
(squiddc*(1.0+(squidpole/f)**squidn))**2.0
- f_tfn : float
Function that estimates the noise suppression of the thermal fluctuation noise due to the difference in temperature between the bath and the TES. Supports the ballistic and diffusive limits, which is chosen via lgcb
Methods
dIdP
([freqs])The two-pole dIdP function determined from the TES parameters. dIdV
([freqs])The two-pole dIdV function determined from the TES parameters. dIdVnormal
([freqs])The one-pole dIdV function determined from the TES parameters for when the TES is normal. dIdVsc
([freqs])The one-pole dIdV function determined from the TES parameters for when the TES is superconducting. s_iload
([freqs])The Johnson load current noise determined from the TES parameters for in transition. s_iloadnormal
([freqs])The Johnson load current noise determined from the TES parameters for normal. s_iloadsc
([freqs])The Johnson load current noise determined from the TES parameters for superconducting. s_isquid
([freqs])The SQUID and downstream electronics current noise, currently is using a 1/f model that must be specified when initializing the class. s_ites
([freqs])The Johnson TES current noise determined from the TES parameters for in transition. s_itesnormal
([freqs])The Johnson TES current noise determined from the TES parameters for normal. s_itfn
([freqs])The thermal fluctuation noise in current determined from the TES parameters for in transition. s_itot
([freqs])The total current noise for the TES in transition. s_itotnormal
([freqs])The total current noise for the TES when normal. s_itotsc
([freqs])The total current noise for the TES when superconducting. s_pload
([freqs])The Johnson load power noise determined from the TES parameters for in transition. s_psquid
([freqs])The SQUID and downstream electronics power noise, currently is using a 1/f model that must be specified when initializing the class. s_ptes
([freqs])The Johnson TES power noise determined from the TES parameters for in transition. s_ptfn
([freqs])The thermal fluctuation noise in power determined from the TES parameters for in transition. s_ptot
([freqs])The total power noise for the TES in transition. s_vload
([freqs])The Johnson load voltage noise determined from the TES parameters. s_vtes
([freqs])The Johnson TES voltage noise determined from the TES parameters for in transition. s_vtesnormal
([freqs])The Johnson TES voltage noise determined from the TES parameters for normal. -
dIdP
(freqs=None)¶ The two-pole dIdP function determined from the TES parameters.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - dIdP : float, ndarray
The two-pole dIdP function
-
dIdV
(freqs=None)¶ The two-pole dIdV function determined from the TES parameters.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - dIdV : float, ndarray
The two-pole dIdV function
-
dIdVnormal
(freqs=None)¶ The one-pole dIdV function determined from the TES parameters for when the TES is normal.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - dIdVnormal : float, ndarray
The one-pole dIdV function for when the TES is normal.
-
dIdVsc
(freqs=None)¶ The one-pole dIdV function determined from the TES parameters for when the TES is superconducting.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - dIdVsc : float, ndarray
The one-pole dIdV function for when the TES is superconducting.
-
s_iload
(freqs=None)¶ The Johnson load current noise determined from the TES parameters for in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_iload : float, ndarray
The Johnson load current noise at the specified frequencies
-
s_iloadnormal
(freqs=None)¶ The Johnson load current noise determined from the TES parameters for normal.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_iloadnormal : float, ndarray
The Johnson load current noise at the specified frequencies
-
s_iloadsc
(freqs=None)¶ The Johnson load current noise determined from the TES parameters for superconducting.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_iloadsc : float, ndarray
The Johnson load current noise at the specified frequencies
-
s_isquid
(freqs=None)¶ The SQUID and downstream electronics current noise, currently is using a 1/f model that must be specified when initializing the class.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_isquid : float, ndarray
The SQUID and downstream electronics current noise at the specified frequencies
-
s_ites
(freqs=None)¶ The Johnson TES current noise determined from the TES parameters for in transition. This noise has both an electronic and thermal component.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_ites : float, ndarray
The Johnson TES current noise at the specified frequencies
-
s_itesnormal
(freqs=None)¶ The Johnson TES current noise determined from the TES parameters for normal.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_itesnormal : float, ndarray
The Johnson TES current noise at the specified frequencies
-
s_itfn
(freqs=None)¶ The thermal fluctuation noise in current determined from the TES parameters for in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_itfn : float, ndarray
The thermal fluctuation noise in current at the specified frequencies
-
s_itot
(freqs=None)¶ The total current noise for the TES in transition. This is calculated by summing each of the current noise sources together. Units are [A^2/Hz].
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_itot : float, ndarray
The total current noise at the specified frequencies
-
s_itotnormal
(freqs=None)¶ The total current noise for the TES when normal. This is calculated by summing each of the current noise sources together. Units are [A^2/Hz].
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_itotnormal : float, ndarray
The total current noise at the specified frequencies
-
s_itotsc
(freqs=None)¶ The total current noise for the TES when superconducting. This is calculated by summing each of the current noise sources together. Units are [A^2/Hz].
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_itotsc : float, ndarray
The total current noise at the specified frequencies
-
s_pload
(freqs=None)¶ The Johnson load power noise determined from the TES parameters for in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_pload : float, ndarray
The Johnson load power noise at the specified frequencies
-
s_psquid
(freqs=None)¶ The SQUID and downstream electronics power noise, currently is using a 1/f model that must be specified when initializing the class. This is only used for when the TES is in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_psquid : float, ndarray
The SQUID and downstream electronics power noise at the specified frequencies
-
s_ptes
(freqs=None)¶ The Johnson TES power noise determined from the TES parameters for in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_ptes : float, ndarray
The Johnson TES power noise at the specified frequencies
-
s_ptfn
(freqs=None)¶ The thermal fluctuation noise in power determined from the TES parameters for in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_ptfn : float, ndarray
The thermal fluctuation noise in power at the specified frequencies
-
s_ptot
(freqs=None)¶ The total power noise for the TES in transition. This is calculated by summing each of the current noise sources together and using dIdP to convert to power noise. Units are [W^2/Hz].
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_ptot : float, ndarray
The total power noise at the specified frequencies
-
s_vload
(freqs=None)¶ The Johnson load voltage noise determined from the TES parameters. This formula holds no matter where we are in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_vload : float, ndarray
The Johnson load voltage noise at the specified frequencies
-
s_vtes
(freqs=None)¶ The Johnson TES voltage noise determined from the TES parameters for in transition.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_vtes : float, ndarray
The Johnson TES voltage noise at the specified frequencies
-
s_vtesnormal
(freqs=None)¶ The Johnson TES voltage noise determined from the TES parameters for normal.
Parameters: - freqs : float, ndarray, optional
The frequencies for which we will calculate the noise simulation. If left as None, the function will use the values from the initialization.
Returns: - s_vtesnormal : float, ndarray
The Johnson TES voltage noise at the specified frequencies
Example Usage¶
Jupyter notebooks providing detailed instructions and examples of how to use the various classes and functions of QETpy can be found below. The notebooks themselves (and corresponding data) can be downloaded from: https://github.com/berkeleycdms/QETpy/tree/master/demos
Table of Contents
Example Code for using the DIDV class¶
Import the needed packages to run the test script.
In [1]:
from qetpy import DIDV
import matplotlib.pyplot as plt
import numpy as np
import h5py
%matplotlib inline
/galbascratch/samwatkins/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
Set all of the necessary parameters and load the traces from an HDF5 file in the repository.
In [2]:
# Setting various parameters that are specific to the dataset
Rshunt = 5.0e-3
Rbias_SG = 20000.0
Rfb = 5000.0
loopgain = 2.4
ADCperVolt = 65536.0/2.0
fs = 625.0e3
sgFreq = 100.0
sgAmp = 0.009381 /Rbias_SG
drivergain = 4.0
Rp = 0.0060367199999999998
Rload = Rshunt+Rp
dRload = 0.0001
R0 = 0.075570107054005367
dR0 = 8.96383052e-04
convToAmps = Rfb * loopgain * drivergain * ADCperVolt
saveResults = False
# load the dataset
with h5py.File('example_traces.h5','r') as f:
rawTraces = np.array(f["rawTraces"])
fileSaveName = "example_traces_data"
# set the priors information, for use the priors fitting
priors = np.zeros(7)
invpriorsCov = np.zeros((7,7))
priors[0] = Rload
priors[1] = R0
invpriorsCov[0,0] = 1.0/dRload**2
invpriorsCov[1,1] = 1.0/dR0**2
dt0=-18.8e-6
Run the processing package on the data.
In [3]:
didvfit = DIDV(rawTraces, fs, sgFreq, sgAmp, Rshunt, tracegain=convToAmps) #note that there are many more attributes
didvfit.processtraces()
didvfit.doallfits()
# didvfit.dofit(2) # just do one fit
didvfit.plot_full_trace()

Let’s look at the fit parameters for the 2-pole fit.
In [4]:
didvfit.fitparams2
Out[4]:
array([ 2.91338904e-01, 1.96261960e+00, 1.87363027e-03, 9.97908425e-07,
-1.88710545e-05])
In [5]:
didvfit.irwinparams2
Out[5]:
array([ 1.00000000e-02, 3.00000000e-01, -6.22036528e-02, 7.71482552e-01,
2.90729547e-07, 4.28157207e-04, -1.88710545e-05])
In [6]:
didvfit.get_irwinparams_dict(2)
Out[6]:
{'rload': 0.01,
'r0': 0.3,
'beta': -0.062203652825646105,
'l': 0.771482552122021,
'L': 2.907295469988362e-07,
'tau0': 0.00042815720654307293,
'dt': -1.887105448791047e-05,
'tau_eff': 0.0002413064572931682}
Let’s see what dIdV(0) is.
In [7]:
didvfit.didvfit2_freqdomain[0].real
Out[7]:
0.44366389157720754
What are the fall times?
In [8]:
didvfit.falltimes2
Out[8]:
array([1.00151672e-06, 2.41306457e-04])
Let’s play with the plotting functions available.
Let’s first plot all of this fits on the full trace.
In [9]:
didvfit.plot_full_trace(poles="all",plotpriors=True)

Now let’s plot a single trace and save the file to the current
directory. If a different directory is wanted, then use the savepath
variable.
In [10]:
didvfit.plot_single_period_of_trace(poles=[2,3], lgcsave=True, savename="test")
Let’s plot a zoomed in trace of just the 2 pole fit. Note that by default, all fits are plotted.
In [11]:
didvfit.plot_zoomed_in_trace(poles=2)

Let’s flip the trace and shift it by half a period of the signal generator in order to see if there are any nonlinearities. Spoilter alert: there aren’t!
In [12]:
didvfit.plot_didv_flipped()

Now let’s look at the real and imaginary parts of the dIdV.
In [13]:
didvfit.plot_re_im_didv(poles=[2,3])


In [ ]:
Table of Contents
Using the autocuts
Algorithm¶
This is a quick look at how to use the autocuts
algorithm.
Note that there are many more optional arguments than what are shown here. For example, you can choose which cuts to do, change the outlier algorithm used, or indicate that you are cutting on dIdV data.
First, let’s import the function.
In [1]:
import numpy as np
import matplotlib.pyplot as plt
from qetpy import autocuts, calc_psd
Now, let’s load the data.
In [2]:
pathtodata = "test_autocuts_data.npy"
traces = np.load(pathtodata)
fs = 625e3
Let’s look at the PSD before the cuts, to get a sense of the change.
In [3]:
f, psd = calc_psd(traces, fs=fs, folded_over=True)
In [4]:
fig, ax = plt.subplots(figsize=(10,6))
ax.loglog(f, np.sqrt(psd), label="Before autocuts")
ax.set_ylim([1e-12,1e-7])
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('PSD (A/$\sqrt{\mathrm{Hz}}$)')
ax.set_title("PSD before autocuts")
ax.legend(loc="upper right")
ax.grid(linestyle='dotted')
ax.tick_params(which='both',direction='in',right=True,top=True)

Apply the autocuts function.
In [5]:
?autocuts
In [6]:
cut = autocuts(traces, fs=fs)
print(f"The cut efficiency is {np.sum(cut)/len(traces)}.")
The cut efficiency is 0.488.
Let’s compare the PSD after the cuts, we should see the noise go down by a fair amount.
In [7]:
psd_cut = calc_psd(traces[cut], fs=fs, folded_over=True)[1]
In [8]:
fig, ax = plt.subplots(figsize=(10,6))
ax.loglog(f, np.sqrt(psd), label="Before autocuts")
ax.loglog(f, np.sqrt(psd_cut), label="Before autocuts")
ax.set_ylim([1e-12,1e-7])
ax.set_xlabel('Frequency (Hz)')
ax.set_ylabel('PSD (A/$\sqrt{\mathrm{Hz}}$)')
ax.set_title("PSD before autocuts")
ax.legend(loc="upper right")
ax.grid(linestyle='dotted')
ax.tick_params(which='both',direction='in',right=True,top=True)

The change is huge! Which makes sense, as we have removed many of the pulses, muon tails, etc. Please note that there may still be “bad” traces in the data, as the autocuts function is not perfect. There may be more cuts that one would like to do that are more specific to the dataset.
In [ ]:
Table of Contents
Example Code for using the IV class¶
Import the need packages to run the test script
In [1]:
import numpy as np
from qetpy import IV
Let’s load the example data. To see how this data was created, look at
the run_31_chips_iv.ipynb
file, which loads the data from Pickle
files. This data was created from Run 31 at SLAC, using TES chips. There
is no guarantee that that notebook will run.
In [2]:
testdata = np.load("test_iv_data.npz")
dites = testdata["dites"]
dites_err = testdata["dites_err"]
vb = testdata["vb"]
vb_err = testdata["vb_err"]
rload = testdata["rload"]
rload_err = testdata["rload_err"]
Now let’s use the IV class and calculate the IV curves
In [3]:
ivdata = IV(dites, dites_err, vb, vb_err, rload, rload_err, ["A","B","C"])
ivdata.calc_iv()
Let’s take a look at the plotting. We can plot all of the curves together.
In [4]:
ivdata.plot_all_curves()



If you want to plot certain channels or certain bath temperatures, use the chans and temps flags.
In [5]:
ivdata.plot_all_curves(temps=[0,7], chans=1)



We can also plot the IV, resistance, and power curves separately. See the documentation for more information on the plotting options.
In [6]:
ivdata.plot_iv(temps=0, chans=0, showfit=False);
ivdata.plot_rv(temps=[0,-1], chans=[0,1]);
ivdata.plot_pv(temps="all", chans=2);



In [ ]:
Table of Contents
0.1 Imports
0.2 Load test data
0.3 Create noise object
0.4 Calculate the PSD and corrCoeff
1 Calculate unCorrelated noise
1.1 Test saving
1.2 Test plotting of PSD and corrCoeff
2 Plot a few CSDs
2.1 Try to plot a CSD for a non existant channel
2.2 Try to save a figure with a bad path
3 Plot Real vs Imaginary PSDs
4 Plot unCorrelated part of the noise PSD
5 Create noise simulation object
Noise Analysis Test¶
Imports¶
In [1]:
from qetpy import Noise
from qetpy.sim import TESnoise
from qetpy.plotting import compare_noise, plot_noise_sim
import numpy as np
import matplotlib.pyplot as plt
Load test data¶
In [2]:
pathToTraces = ''
traces_PT_on = np.load(pathToTraces+'traces.npy')
Create noise object¶
In [3]:
#savePath = 'example_Figs/' #used for test, user should define new path for test so they don't save over these figs
savePath = '' #user needs to define new path
sampleRate = 625e3 #define sample rate
channels = [ 'PCS1' , 'PES1' , 'PFS1' , 'PAS2' , 'PBS2' , 'PES2' , 'PDS2' ] #define the channel names
g124_noise = Noise(traces_PT_on, sampleRate, channels) #initialize a noise object
g124_noise.name = 'G124 SLAC Run 37 Pulse Tube On'
Calculate the PSD and corrCoeff¶
In [4]:
g124_noise.calculate_psd()
g124_noise.calculate_corrcoeff()
g124_noise.calculate_csd()
Test saving¶
Uncomment to save and re-load
In [6]:
#saveName = pathToTraces + g124_noise.name.replace(" ", "_") + '.pkl'
#g124_noise.save(pathToTraces)
In [7]:
#del g124_noise
In [8]:
# with open(pathToTraces,'rb') as savefile:
# g124_noise = pickle.load(savefile)
Test plotting of PSD and corrCoeff¶
In [9]:
g124_noise.plot_psd(lgcoverlay=True)

In [10]:
g124_noise.plot_psd(lgcoverlay=False)

In [11]:
g124_noise.plot_corrcoeff(lgcsave=False, lgcsmooth=True, nwindow=13 )

Try to plot a CSD for a non existant channel¶
In [13]:
g124_noise.plot_csd(whichcsd=['68'])
index out of range
Try to save a figure with a bad path¶
In [14]:
g124_noise.plot_csd(whichcsd=['11'], lgcsave=True, savepath = 'yay/python/is/great')
Invalid save path. Figure not saved

Create noise simulation object¶
In [19]:
noise_sim = TESnoise(freqs = g124_noise.freqs[1:])
Note, these default noise parameters are completely made up, just for demostration
In [20]:
plot_noise_sim(g124_noise.freqs, g124_noise.psd[0,:], noise_sim, istype='power')
Out[20]:
(<Figure size 864x576 with 1 Axes>,
<matplotlib.axes._subplots.AxesSubplot at 0x7f8e4b5a4908>)

In [ ]:
Indices and tables¶
Developed and maintained by Caleb Fink (https://github.com/cwfink) and Sam Watkins (https://github.com/slwatkins)