tes package
Module contents
Submodules
tes.calibration module
Functions to calibrate the TES detector.
Author: Leonardo Assis Morais
- tes.calibration.area_histogram(max_area, bin_number, areas)
Create an area histogram.
- Parameters
max_area (float) –
- Maximum area allowed (remove extremely large areas not due to
photon detections).
bin_number (int) – Number of histogram bins.
areas (np.ndarray) – Data with areas of TES pulses.
- Returns
bin_centre (np.darray) – Array with the positions of the histograms bin centres. Used for plotting the histogram with correct values for areas in the x-axis.
counts (np.ndarray) – Histogram counts.
error (np.ndarray) – Standard deviation for counts (poissonian distribution assumed: std. = sqrt(counts).
bin_width (float) – Bin width for plotting.
- tes.calibration.find_thresholds(gauss_fit, maxima_list, bin_centre, counts, const)
Find the counting thresholds given a gaussian fit.
- Parameters
gauss_fit (lmfit fit) – Result of a least square minimisation using lmfit.
maxima_list (np.ndarray) – Array with the positions of maxima points.
bin_centre (np.ndarray) – Array with centre bin positions for histogram.
counts (np.ndarray) – List with counts for histogram.
const (float) – Value used for scipy.optimise.brentq. See ‘Notes’ below for more information.
- Returns
dist (list) – List with the normalised distributions.
new_thresh_list – List of counting thresholds.
Requires
——– – scipy.optimize.brentq
Notes
Sometimes this function breaks if brentq function cannot find roots. If that is the case, slowly increase the value of the variable ‘const’.
- tes.calibration.gaussian_model(fitting, counts, bin_centre, max_idx)
Implement mixture model comprised of gaussians.
- Parameters
fitting (class lmfit.minimizer.MinimizerResult) – Result from fitting using lmfit.
counts (np.ndarray) – Histogram counts.
bin_centre (np.darray) – Array with the positions of the histograms bin centres. Used for plotting the histogram with correct values for areas in the x-axis.
max_idx (int) – Number of gaussian distributions used in the model.
- Returns
model – Model of composed of sum of gaussians using the results obtained from the fitting with lmfit.
- Return type
np.ndarray
- tes.calibration.guess_histogram(areas, bin_number, win_length, minimum, max_area)
Create first guess for histogram fitting.
Using a Hann function to create an approximate fit for the data, estimates the position for the centre of the different peaks in the area histogram.
WARNING: The Hann window fitting must be checked to see if it is reasonable using the function plot_guess.
maxima
- Parameters
bin_number (int) – Number of bins used in histogram.
win_length (int) – Length of the Hann window used in the fit.
minimum (int) – Minimum value for the function maxima to consider a given number of counts as a peak.
max_area (float) – Areas > max_area are considered invalid counts and removed from the analysis. Used to remove event with anomalous areas.
- Returns
counts (np.darray) – Array with counts for each histogram bin.
smooth_hist (np.darray) – Array with the continuous fit used to determine the positions of the maxima in the data.
bin_centre (np.darray) – Array with the positions of the histograms bin centres. Used for plotting the histogram with correct values for areas in the x-axis.
max_i (list) – List with the position of the maxima points.
- tes.calibration.maxima(function, thresh=10)
Find local maxima of a function f.
Uses rising zero crossings of the gradient of f to find function local maxima.
- Parameters
function (ndarray) – Function f to be analysed.
thresh (int) – Only return a maxima if f[maxima] > thresh.
- Returns
array
Array with maxima points of f.
- tes.calibration.plot_area(ax, bin_centre, counts, error, model, plot_steps)
Require area_histogram to be run before.
- Parameters
ax (figure axis) – Figure axis of the figure to be plotted.
bin_centre (np.darray) – Array with the positions of the histograms bin centres. Used for plotting the histogram with correct values for areas in the x-axis.
counts (np.ndarray) – Histogram counts.
error (np.ndarray) – Standard deviation for counts
model (np.ndarray) – Model generated with gaussian_model
plot_steps (int) – Number of histogram points to be skipped when plotting.
- Returns
None.
Requires
——–
area_histogram
- tes.calibration.plot_guess(ax, hist, smooth_hist, bin_centres, max_i)
Plot the histogram with an educated guess for its fitting.
Visual check if the maxima positions determined by the guess_thresholds are reasonable.
Requires guess_thresholds.
- Parameters
ax (figure axis) – Figure axis of the figure to be plotted.
hist (np.darray) – Histogram obtained from the guess_thresholds function.
smooth_hist – Smoothed histogram obtained from the guess_thresholds function.
bin_centres – Centre of the bins for the histogram. Obtained from the guess_thresholds function.
max_i (list) – List with the position of the maxima points for the peaks in histogram. Obtained from the guess_thresholds function.
- Returns
ax – Axis for the figure with the histogram, smoothed histogram and maxima points plotted.
- Return type
figure axis
- tes.calibration.plot_histogram(ax, data, bin_number, measurement)
Plot histogram of TES characteristics.
- Parameters
ax (figure axis) – Figure axis of the figure to be plotted.
data (np.ndarray) – Data extracted from TES (height, area, length, maximum slope).
bin_number (int) – Number of histogram bins.
measurement (str) – Type of measurement plotted.
- Returns
- Return type
None.
- tes.calibration.plot_normalised(ax, max_i, bin_centre, dist, thresholds)
Plot the graph with the normalised distributions.
- Parameters
ax (figure axis) – Figure axis of the figure to be plotted.
max_i (np.ndarray) – Number of distributions to be plotted.
bin_centre (np.ndarray) – x-axis positions for histogram data.
dist (np.ndarray) – Distributions to be plotted.
thresholds (np.ndarray) – Counting thresholds positions to be plotted.
- Returns
- Return type
None.
- tes.calibration.residual_gauss(params, i_var, data, eps_data, max_idx)
Gaussian model to fit histogram from TES detections.
Model composed of a sum of N gaussian distributions, to be used with the lmfit package to fit histograms from TES detections. Returns the residual between data and model, divided by the error in the data.
- Parameters
params (lmfit object) – List of parameters to be used in the fit.
i_var – Independent variable to be used in the fit.
data (np.ndarray) – Data to be fitted.
eps_data (np.ndarray) – Standard deviation of each data point.
max_idx (int) – Number of gaussian distributions used in the model.
- Returns
residual – Array with the different between data and model divided by the error in data.
- Return type
np.ndarray
tes.counts module
Module to assist in counting photons routine.
- class tes.counts.Counts(count, uncorrelated, vacuum)
Bases:
tuple- property count
Alias for field number 0
Alias for field number 1
- property vacuum
Alias for field number 2
- tes.counts.coincidence(abs_time, mask, low, high)
Find coincidences between two channels.
After finding a coincidence, return indices of coincident events.
- Parameters
abs_time (ndarray) – Array where each entry corresponds to the time which the detection was performed with respect to an initial time t0. This array can be constructed using np.cumsum(CaptureData(datapath).times).
mask (ndarray bool) – Identifies the channels in abs_time. For abs_times where mask is False, time t is coincident if abs_time+low <= t <= abs_time+high. If the mask is True t is coincident if abs_time-high <= t <= abs_time-low.
low (float) – The starting of the coincidence window.
high (float) – The ending side of the coincidence window.
- Returns
coincidences(coinc, coinc_mask) (tuple) –
- coincndarray
Indexes of the coincident event in the other channel. When more than one event is found in the window the negated value of the first index is entered.
- coinc_maskndarray bool
Indicates where exactly one event was found in the window.
Requires
——— – tes.counts.window
- tes.counts.counting_photons(data, thresh_list, vacuum=False, coinc_mask=None, herald_mask=None)
Convert TES pulse area in photon-number.
Given an TES pulse area data set and the calibration (list with the counting thresholds, passed through thresh_list), returns the number of counts for each Fock state.
If the mask with the heralding source is given, also includes the number of vacuum counts.
- Parameters
data (np.ndarray) – Measured data.
thresh_list (np.ndarray) – List with the counting thresholds obtained after detector calibration.
vacuum (bool) – If true, it will use the herald_mask to calculate vacuum counts
coinc_mask (ndarray, bool) – Mask indicating coincidence counts.
herald_mask (ndarray, bool) – Mask indicating which events are in the heralding channel.
- Returns
Counts(count, uncorrelated, vacuum) –
- countndarray
Counts for each photon number
- uncorrelated :
Counts events not correlated with herald. Only calculated when coinc_mask and herald_mask are provided.
- vacuum :
indicates if count[0] contains vacuum counts
- Return type
named tuple
- tes.counts.get_thresholds(calibration_file)
Load the threshold from a calibration file.
Calibration file must be generated with “TES_Calibration.ipynb”.
- Parameters
calibration_file (str) – Calibration file path.
- Returns
thresholds – Array with the threshold positions.
- Return type
np.array
tes.data_acquisition module
Module used to perform measurements with the TES.
- tes.data_acquisition.pulse_drive(time, channel, p_thres, s_thres, baseline_sub, datapath, filename)
Perform measurements over TES traces.
- Measure the following characteristics of TES traces:
Length
Area
Maximum slope or height
Rise Time
- Parameters
time (int) – Time in seconds to take measurements.
channel (int) – Processing channel chosen to take measurements.
p_thres (int) – Pulse threshold chosen using the MCA.
s_thres (int) – Slope threshold chosen using the MCA.
base_sub (bool) – If True, the baseline correction will be activated. It can automatically update the baseline level in the case where it changes.
datapath (str) – Folder where the registers will be saved.
filename (str) – Name of the file where the registers will be saved.
- Returns
- Return type
None
- tes.data_acquisition.trace_drive(time, channel, p_thres, s_thres, baseline_sub, datapath, filename)
Record TES traces.
- Parameters
time (int) – Time in seconds to take measurements.
channel (int) – Processing channel chosen to take measurements.
p_thres (int) – Pulse threshold chosen using the MCA.
s_thres (int) – Slope threshold chosen using the MCA.
base_sub (bool) – If True, the baseline correction will be activated. It can automatically update the baseline level in the case where it changes.
datapath (str) – Folder where the registers will be saved.
filename (str) – Name of the file where the registers will be saved.
- Returns
- Return type
None
Notes
Keep your trace measurements up to 1 minute.
tes.folder_management module
Module with convenient functions for folder management.
- tes.folder_management.find_folders(master_folder)
Search for folders inside the given address.
- Parameters
master_folder (string) – address of the master folder on local computer.
- Raises
AttributeError: – Raises error when no folder can be found.
- Returns
measurements – list with the address of folders inside master_folder.
- Return type
list
- tes.folder_management.manage_folders(index, measurement_folders)
Create a folder structure for a given measurement set.
- Parameters
index (integer) – Select the measurement folder to be analysed
measurements (list) – contains all addresses of measurement folders
- Raises
AttributeError: – Raises error when no folder can be found.
- Returns
- datapathpath
address of the measurement folder
- folder_analysispath
address of the analysis folder
- folder_figurespath
address of the figures folder
- Return type
tuple with
tes.mca_control module
Module with functions to control the MCA.
Should be used together with the Jupyter Notebook “MCA_and_Measurements.ipynb”.
- tes.mca_control.area_histogram(registers, time, channel, bin_width, p_thres, s_thres, xrange, yrange)
Plot area histogram given the thresholds chosen.
Always run this function to realise a sanity test for the selected values for baseline offset, pulse threshold and slope threshold. You should be able to see clear distinct peaks indicating that the current configuration of the TES can discriminate number of photons.
- Parameters
registers (dict) – Dictionary that stores the values of all registers that control the measurements performed by the FPGA.
time (int) – Time (in seconds) the histogram should be accumulated over.
channel (int) – Channel to be analysed.
bin_width (int) – 2^(bin_width) will be the width of the histogram bin.
s_thres (int) – Determine the pulse threshold.
- Returns
(fig,) – Figure with the plotted histogram.
- Return type
tuple
- tes.mca_control.baseline_offset(registers, time, channel, bin_width, baseline_offset)
Determine the detection baseline for TES detections.
Change the values of baseline_offset until you see a big peak in the histogram. When the peak appears, put its centre at x = 0 by choosing an appropriate baseline_offset.
- Parameters
registers (dict) – Dictionary that stores the values of all registers that control the measurements performed by the FPGA.
time (int) – Time (in seconds) the histogram should be accumulated over.
channel (int) – Channel to be analysed.
bin_width (int) – 2^(bin_width) will be the width of the histogram bin
baseline_offset (int) – Determine the baseline offset.
- Returns
(fig,) – Figure with the plotted histogram.
- Return type
tuple
- tes.mca_control.configure_channels(registers, adc_channel, proc_channel, invert)
Configure connections to ADC channels.
Connects the selected ADC channel (check in the lab to which ADC channel you connected the TES cables) to the selected processing channel (digital channel to which you will refer in the next steps of the notebook).
- Parameters
registers (dict) – Dictionary that stores the values of all registers that control the measurements performed by the FPGA.
adc_channel (int) – Determine which adc channel is being used. May assume values 0-7.
proc_channel (int) – Determine which processing channel is being used. May assume values 0-1.
invert (bool) – Determines if the signal polarisation should be inverted. True inverts, False does not invert.
- Returns
- Return type
None.
- tes.mca_control.pulse_threshold(registers, time, channel, bin_width, p_thres)
Determine the pulse threshold.
- Parameters
registers (dict) – Dictionary that stores the values of all registers that control the measurements performed by the FPGA.
time (int) – Time (in seconds) the histogram should be accumulated over.
channel (int) – Channel to be analysed.
bin_width (int) – 2^(bin_width) will be the width of the histogram bin.
pulse_threshold (int) – Determine the pulse threshold.
- Returns
(fig,) – Figure with the plotted histogram.
- Return type
tuple
- tes.mca_control.slope_threshold(registers, time, channel, bin_width, s_thres)
Determine the slope threshold.
- Parameters
registers (dict) – Dictionary that stores the values of all registers that control the measurements performed by the FPGA.
time (int) – Time (in seconds) the histogram should be accumulated over.
channel (in) – Channel to be analysed.
bin_width (int) – 2^(bin_width) will be the width of the histogram bin.
s_thres (int) – Determine the pulse threshold.
- Returns
(fig,) – Figure with the plotted histogram.
- Return type
tuple
tes.traces module
Module to be used with jupyter notebook TES Trace Generator.
- tes.traces.correct_xticks(ax)
Properly edit the xticks for a matplotlib plot.
- Parameters
ax (axis object) – Axis with x-axis to be edited.
- Returns
ax (axis object) – Edited axis object.
expx (int) – Integer to be added to the x-axis label.
- tes.traces.correct_yticks(ax)
Properly edit the yticks for a matplotlib plot.
- Parameters
ax (axis object) – Axis with x-axis to be edited.
- Returns
ax (axis object) – Edited axis object.
expy (int) – Integer to be added to the x-axis label.
- tes.traces.create_statistics_file(measurement_folders)
Create file with measurements statistics in measurement folder.
- Parameters
measurement_folder (list of paths) – list containing the paths of the folders where the measurements are stored and where the stats files will be created.
- Returns
- Return type
None
- tes.traces.extract_data(datapath, measurements)
Extract data and registers for a given address.
- Parameters
datapath (str) – String containing the measurement folder address.
measurements (list of paths) – List with the paths of all measurement folders.
- Returns
data (tes.data.CaptureData) – Contains the data to be plotted.
registers (TYPE) – Contains the information required to plot timing information properly.
- tes.traces.plot_traces(data, ax, number_traces, trace_length, time_register, choose_trace)
Plot traces using collected using the FPGA.
- Can plot:
- a single trace (number_traces = 1, slope = False,
details = False)
many traces (number_traces > 1)
- Parameters
data (tes.data.CaptureData) – Contains the data to be plotted.
number_traces (int) – The number of different TES pulses to be plotted.
trace_length (int) – The number of points in each TES pulse.
time_register (dict) – Contains the time information for the pulses.
choose_trace (int) – Choose a single TES pulse to plot. (if number_traces == 1)
ax (matplotlib.axis) – Figure axis where traces will be plotted.
- Returns
- Return type
None.