qetpy.trigger package

Submodules

qetpy.trigger.cont_trigger module

qetpy.trigger.cont_trigger.getchangeslessthanthresh(x, threshold)

Helper function that returns a list of the start and ending indices of the ranges of inputted values that change by less than the specified threshold value

Parameters:
x : ndarray

1-dimensional of values.

threshold : int

Value to detect the different ranges of vals that change by less than this threshold value.

Returns:
ranges : ndarray

List of tuples that each store the start and ending index of each range. For example, vals[ranges[0][0]:ranges[0][1]] gives the first section of values that change by less than the specified threshold.

vals : ndarray

The corresponding starting and ending values for each range in x.

qetpy.trigger.cont_trigger.rand_sections(x, n, l, t=None, fs=1.0)

Return random, non-overlapping sections of a 1 or 2 dimensional array. For 2-dimensional arrays, the function treats each row as independent from the other rows.

Parameters:
x : ndarray

n dimensional array to choose sections from

n : int

Number of sections to choose

l : int

Length in bins of sections

t : array_like or float, optional

Start times (in s) associated with x

fs : float, optional

Sample rate of data (in Hz)

Returns:
evttimes : ndarray

Array of the corresponding event times for each section

res : ndarray

Array of the n sections of x, each with length l

class qetpy.trigger.cont_trigger.OptimumFilt(fs, template, noisepsd, tracelength, trigtemplate=None)

Bases: object

Class for applying a time-domain optimum filter to a long trace, which can be thought of as an FIR filter.

Attributes:
phi : ndarray

The optimum filter in time-domain, equal to the inverse FT of (FT of the template/power spectral density of noise)

norm : float

The normalization of the optimal amplitude.

tracelength : int

The desired trace length (in bins) to be saved when triggering on events.

fs : float

The sample rate of the data (Hz).

pulse_range : int

If detected events are this far away from one another (in bins), then they are to be treated as the same event.

traces : ndarray

All of the traces to be filtered, assumed to be an ndarray of shape = (# of traces, # of channels, # of trace bins). Should be in units of Amps.

template : ndarray

The template that will be used for the Optimum Filter.

noisepsd : ndarray

The two-sided noise PSD that will be used to create the Optimum Filter.

filts : ndarray

The result of the FIR filter on each of the traces.

resolution : float

The expected energy resolution in Amps given by the template and the noisepsd, calculated from the Optimum Filter.

times : ndarray

The absolute start time of each trace (in s), should be a 1-dimensional ndarray.

pulsetimes : ndarray

If we triggered on a pulse, the time of the pulse trigger in seconds. Otherwise this is zero.

pulseamps :

If we triggered on a pulse, the optimum amplitude at the pulse trigger time. Otherwise this is zero.

trigtimes : ndarray

If we triggered due to ttl, the time of the ttl trigger in seconds. Otherwise this is zero.

pulseamps :

If we triggered due to ttl, the optimum amplitude at the ttl trigger time. Otherwise this is zero.

traces : ndarray

The corresponding trace for each detected event.

trigtypes: ndarray

Array of boolean vectors each of length 3. The first value indicates if the trace is a random or not. The second value indicates if we had a pulse trigger. The third value indicates if we had a ttl trigger.

Methods

eventtrigger(thresh[, trigthresh, …]) Method to detect events in the traces with an optimum amplitude greater than the specified threshold.
filtertraces(traces, times[, trig]) Method to apply the FIR filter the inputted traces with specified times.
eventtrigger(thresh, trigthresh=None, positivepulses=True)

Method to detect events in the traces with an optimum amplitude greater than the specified threshold. Note that this may return duplicate events, so care should be taken in post-processing to get rid of such events.

Parameters:
thresh : float

The number of standard deviations of the energy resolution to use as the threshold for which events will be detected as a pulse.

trigthresh : NoneType, float, optional

The threshold value (in units of the trigger channel) such that any amplitudes higher than this will be detected as ttl trigger event. If left as None, then only the pulses are analyzed.

positivepulses : boolean, optional

Boolean flag for which direction the pulses go in the traces. If they go in the positive direction, then this should be set to True. If they go in the negative direction, then this should be set to False. Default is True.

filtertraces(traces, times, trig=None)

Method to apply the FIR filter the inputted traces with specified times.

Parameters:
traces : ndarray

All of the traces to be filtered, assumed to be an ndarray of shape = (# of traces, # of channels, # of trace bins). Should be in units of Amps.

times : ndarray

The absolute start time of each trace (in s), should be a 1-dimensional ndarray.

trig : NoneType, ndarray, optional

The trigger channel traces to be filtered using the trigtemplate (if it exists). If left as None, then only the traces are analyzed. If the trigtemplate attribute has not been set, but this was set, then an error is raised.

qetpy.trigger.cont_trigger.acquire_randoms(filelist, n, l, datashape=None, iotype='stanford', savepath=None, savename=None, dumpnum=1, maxevts=1000)

Function for acquiring random traces from a list of files and saving the results to a .npz file for later processing.

Parameters:
filelist : list of strings

List of files to be opened to take random sections from (should be full paths)

n : int

Number of sections to choose

l : int

Length in bins of sections

datashape : tuple, NoneType, optional

The shape of the data in each file. If inputted, this should be a tuple that is (# of traces in a dataset, # of bins in each trace). If left as None, then the first file in filelist is opened, and the shape of the data in it is used.

iotype : string, optional
Type of file to open, uses a different IO function. Default is “stanford”.

“stanford” : Use qetpy.io.loadstanfordfile to open the files

savepath : NoneType, str, optional

Path to save the events to, if saveevents is True. If this is left as None, then they will be saved in the current working directory.

savename : NoneType, str, optional

Filename to save the events as. It is recommended that this follows CDMS format, which is “[code][lasttwodigitsofyear][month][day]_[24hourclocktime]”. If this is left as None, then a dummy filename is used based on the inputted filelist.

dumpnum : int, optional

The dump number that the file should start saving from and the event number should be determined by when saving. Default is 1.

maxevts : int, optional

The maximum number of events that should be stored in each dump when saving. Default is 1000.

qetpy.trigger.cont_trigger.acquire_pulses(filelist, template, noisepsd, tracelength, thresh, nchan=2, trigtemplate=None, trigthresh=None, positivepulses=True, iotype='stanford', savepath=None, savename=None, dumpnum=1, maxevts=1000)

Function for running the continuous trigger on many different files and saving the events to .npz files for later processing.

Parameters:
filelist : list of strings

List of files to be opened to take random sections from (should be full paths)

template : ndarray

The pulse template to be used when creating the optimum filter (assumed to be normalized)

noisepsd : ndarray

The two-sided power spectral density in units of A^2/Hz

tracelength : int

The desired trace length (in bins) to be saved when triggering on events.

thresh : float

The number of standard deviations of the energy resolution to use as the threshold for which events will be detected as a pulse.

trigtemplate : NoneType, ndarray, optional

The template for the trigger channel pulse. If left as None, then the trigger channel will not be analyzed.

trigthresh : NoneType, float, optional

The threshold value (in units of the trigger channel) such that any amplitudes higher than this will be detected as ttl trigger event. If left as None, then only the pulses are analyzed.

positivepulses : boolean, optional

Boolean flag for which direction the pulses go in the traces. If they go in the positive direction, then this should be set to True. If they go in the negative direction, then this should be set to False. Default is True.

iotype : string, optional
Type of file to open, uses a different IO function. Default is “stanford”.

“stanford” : Use qetpy.io.loadstanfordfile to open the files

savepath : NoneType, str, optional

Path to save the events to, if saveevents is True. If this is left as None, then they will be saved in the current working directory.

savename : NoneType, str, optional

Filename to save the events as. It is recommended that this follows CDMS format, which is “[code][lasttwodigitsofyear][month][day]_[24hourclocktime]”. If this is left as None, then a dummy filename is used based on the inputted filelist.

dumpnum : int, optional

The dump number that the file should start saving from and the event number should be determined by when saving. Default is 1.

maxevts : int, optional

The maximum number of events that should be stored in each dump when saving. Default is 1000.

Module contents