daplis.functions.sensor_plot module
Module with scripts for plotting the LinoSPAD2 sensor population.
This script utilizes an unpacking module used specifically for the LinoSPAD2 data output.
This file can also be imported as a module and contains the following functions:
collect_data_and_apply_mask - Collect data from files and apply
mask to the valid pixel count.
plot_single_pix_hist - Plot a histogram for each pixel in the given
range.
plot_sensor_population - Plot number of timestamps in each pixel
for all data files.
plot_sensor_population_rates - Plot photon rate in each pixel
for all data files.
plot_sensor_population_spdc - Plot sensor population for SPDC data.
plot_sensor_population_full_sensor - Plot the number of timestamps
in each pixel for all data files from two different FPGAs/sensor halves.
- daplis.functions.sensor_plot.collect_data_and_apply_mask(files: List[str] | str, daughterboard_number: str, motherboard_number: str, firmware_version: str, timestamps: int, apply_hot_pixel_mask: bool = True, absolute_timestamps: bool = False, save_to_file: bool = False, correct_pix_address: bool = False, calculate_rates: bool = False, acq_window_length: float | None = None, number_of_cycles: float | None = None) ndarray | tuple[ndarray, ndarray][source]
Collect data from files and return number of timestamps in pixels.
Unpacks data and returns the number of timestamps (and photon rate) in each pixel. Optionally, aplly mask or hot pixels, save the data into a file.
- Parameters:
files (List[str], str) – List of data file paths.
daughterboard_number (str) – The LinoSPAD2 daughterboard number.
motherboard_number (str) – The LinoSPAD2 motherboard number, including the “#”.
firmware_version (str) – LinoSPAD2 firmware version.
timestamps (int) – Number of timestamps per pixel per acquisition cycle.
apply_hot_pixel_mask (bool, optional) – Switch for applying the mask on warm/hot pixels. Default is True.
absolute_timestamps (bool, optional) – Indicator for data files with absolute timestamps. Default is False.
correct_pix_address (bool, optional) – Check for correcting the pixel addressing. The default is False.
calculate_rates (bool, optional) – Switch for calculating the photon rate for each pixel. The default is False.
acq_window_length (float, optional) – Length of each acquisition cycle; maximum is 4 ms. If None, estimated from the data. The default is None.
number_of_cycles (float, optional) – Number of acquisition cycles per data file. If None, estimated from the data. The default is None.
- Returns:
timestamps_per_pixel (ndarray of shape (256,)) – Number of valid timestamps accumulated in each pixel.
rates (ndarray of shape (256,), optional) – Returned only when ‘calculate_rates=True’. Photon detection rates per pixel, in events per second.
- daplis.functions.sensor_plot.plot_sensor_population(path: str, daughterboard_number: str, motherboard_number: str, firmware_version: str, timestamps: int = 512, y_scale: str = 'linear', apply_hot_pixel_mask: bool = True, look_for_peaks: bool = True, peak_threshold: int = 10, single_file: bool = False, pickle_fig: bool = False, correct_pix_address: bool = False, absolute_timestamps: bool = False) tuple[Figure, Figure][source]
Plot number of timestamps in each pixel for all datafiles.
Plot sensor population as number of timestamps vs. pixel number. Analyzes all data files in the given folder. The output figure is saved in the “results” folder, which is created if it does not exist, in the same folder where datafiles are. Works with the firmware version ‘2212’.
- Parameters:
path (str) – Path to the datafiles.
daughterboard_number (str) – The LinoSPAD2 daughterboard number. Required for choosing the correct calibration data.
motherboard_number (str) – The LinoSPAD2 motherboard number, including the “#”.
firmware_version (str) – LinoSPAD2 firmware version. Versions ‘2212b’ (block) or ‘2212s’ (skip) are recognized.
timestamps (int, optional) – Number of timestamps per pixel per acquisition cycle. Default is “512”.
y_scale (str, optional) – Scale for the y-axis of the plot. Use “log” for logarithmic. The default is “linear”.
style (str, optional) – Style of the plot. The default is “-o”.
apply_hot_pixel_mask (bool, optional) – Switch for applying the mask on warm/hot pixels. The default is True.
look_for_peaks (bool, optional) – Switch for finding the highest peaks. The default is False.
peak_threshold (int, optional) – Threshold multiplier that is applied to median across the whole sensor for finding peaks. The default is 10.
single_file (bool, optional) – Switch for using only the first file in the folder. Can be utilized for a quick plot. The default is False.
pickle_fig (bool, optional) – Switch for pickling the figure. Can be used when plotting takes a lot of time. The default is False.
correct_pix_address (bool, optional) – Switch for correcting pixel addressing for the faulty firmware version for the 23 side of the daughterboard. The default is False.
absolute_timestamps (bool, optional) – Indicator for data files with absolute timestamps. Default is False.
- Return type:
None.
Examples
An example how the function can be used to get the sensor occupation from a single file while looking for peaks - the most quick and straightforward approach to find where the beams were focused and get the peak position for further use in, e.g., delta_t functions. Here, the data were collected using the ‘23’-side sensor half which required correction of the pixel addressing.
First, get the absolute path to where the ‘.dat’ files are. >>> path = r’C:/Path/To/Data’
Now to the function itself. >>> plot_sensor_popuation( >>> path, >>> daughterboard_number=”NL11”, >>> motherboard_number=”#21”, >>> firmware_version=”2212s”, >>> timestamps = 1000, >>> correct_pix_address = True, >>> look_for_peaks = True, >>> single_file = True, >>> )
- daplis.functions.sensor_plot.plot_sensor_population_full_sensor(path, daughterboard_number: str, motherboard_number1: str, motherboard_number2: str, firmware_version: str, timestamps: int = 512, y_scale: str = 'linear', style: str = '-o', apply_hot_pixel_mask: bool = True, color: str | None = None, find_peaks: bool = False, peak_threshold: int = 10, pickle_fig: bool = False, single_file: bool = False, absolute_timestamps: bool = False)[source]
Plot the number of timestamps in each pixel for all datafiles.
Plot sensor population as the number of timestamps vs. pixel number. Analyzes all data files in the given folder. The output figure is saved in the “results” folder, which is created if it does not exist, in the same folder where datafiles are. Works with the firmware version ‘2212’.
- Parameters:
path (str) – Path to the datafiles.
daughterboard_number (str) – The LinoSPAD2 daughterboard number. Required for choosing the correct calibration data.
motherboard_number1 (str) – The LinoSPAD2 motherboard number for the first board.
motherboard_number2 (str) – The LinoSPAD2 motherboard number for the second board.
firmware_version (str) – LinoSPAD2 firmware version. Versions ‘2212b’ (block) or ‘2212s’ (skip) are recognized.
timestamps (int, optional) – Number of timestamps per pixel per acquisition cycle. Default is “512”.
y_scale (str, optional) – Scale for the y-axis of the plot. Use “log” for logarithmic. The default is “linear”.
style (str, optional) – Style of the plot. The default is “-o”.
apply_hot_pixel_mask (bool, optional) – Switch for applying the mask on warm/hot pixels. The default is True.
color (str, optional) – Color for the plot. The default is ‘salmon’.
find_peaks (bool, optional) – Switch for finding the highest peaks and fitting them with a Gaussian to provide their position. The default is False.
peak_threshold (int, optional) – Threshold multiplier for setting the threshold for finding peaks. The default is 10.
pickle_fig (bool, optional) – Switch for pickling the figure. Can be used when plotting takes a lot of time. The default is False.
single_file (bool, optional) – Switch for unpacking only the first file for a quick plot. The default is False.
absolute_timestamps (bool, optional) – Indicator for data files with absolute timestamps. Default is False.
- Return type:
None.
Notes
As the pixel addressing is incorrect for one of the sensor halves (depends on the daughterboard-motherboards combinatios; in NL11, for motherboard #21 pixel addressing should be applied), it is important to apply pixel addressing to the correct board/sensor half. For this function, the order in which the motherboards are input is key, as pixel addressing is corrected for the second board.
TLDR: motherboard_number2 should be for the one where correction of the pixel addressing is required.
- daplis.functions.sensor_plot.plot_single_pix_hist(path, pixels, daughterboard_number: str, motherboard_number: str, firmware_version: str, timestamps: int = 512, cycle_length: float = 4000000000.0, multiplier: int = 1000000.0, fit_average: bool = False, color: str | None = None)[source]
Plot a histogram for each pixel in the given range.
Used mainly for checking the homogeneity of the LinoSPAD2 output (mainly clock and acquisition window size settings).
- Parameters:
path (str) – Path to data file.
pixels (array-like, list) – Array of pixels indices.
daughterboard_number (str) – LinoSPAD2 daughterboard number.
motherboard_number (str) – LinoSPAD2 motherboard (FPGA) number, including the ‘#’.
firmware_version (str) – LinoSPAD2 firmware version.
timestamps (int, optional) – Number of timestamps per pixel per acquisition cycle. The default is 512.
cycle_length (float, optional) – Length of the data acquisition cycle. The default is 4e9, or 4 ms.
multiplier (int, optional) – Multiplier of 17.857 for the bin size of the histogram. The default is 1e6.
fit_average (int, optional) – Switch for fitting averages of histogram counts in windows of +/-10. The default is False.
color (str, optional) – Color of the histogram. The default is ‘teal’.
- Return type:
None.
- daplis.functions.sensor_plot.unpickle_plot(plot_pickle_file: str) dict[source]
Unpickle a saved figure and return plot data.
Load a pickled figure with the sensor population plot, extract and return the plot data.
- Parameters:
plot_pickle_file (str) – The absolute path to the pickle file with the sensor population plot.
- Returns:
A tuple containing: - fig (matplotlib.figure.Figure): The unpickled figure object. - plot_data (dict): A dictionary with keys “Histogram” and “Fit_{i}” (for i >= 1), where each value is a tuple of x and y data for the corresponding line plot.
- Return type:
tuple
- Raises:
FileNotFoundError – If the specified pickle file does not exist, a FileNotFoundError is raised and an error message is printed.