Files

122 lines
5.0 KiB
Python

from dataclasses import dataclass, field
import numpy as np
from functools import cached_property
@dataclass(slots=True)
class HistogramParameters:
"""
Parameters controlling the per-pixel histogram calculation of the fluorescence data.
Attributes
----------
adu_min : float
Minimum ADU value to consider for the histogram.
adu_max : float
Maximum ADU value to consider for the histogram.
bin_width : int
Width of each histogram bin in ADU.
sigma_multiplier : float
Threshold for updating the pedestal: only frames with residuals smaller than
``sigma_multiplier * std`` are used. For ``sigma_multiplier <= 0`` the pedestal is not updated.
batch_size : int
Number of frames loaded sequentially per batch before the histogram calculation of that batch starts.
n_threads : int
Number of threads used for calculating the histogram.
max_frames_to_process : int | None
Maximum number of frames to process. If None, all frames are processed.
"""
adu_min : float = 600.5
adu_max : float = 1400.5
bin_width : int = 4
sigma_multiplier : float = 1.0
batch_size : int = 100
n_threads : int = 16
max_frames_to_process : int = None
class HistogramResult():
"""
Per-pixel histograms of the pedestal-subtracted fluorescence data and the corresponding pedestal.
Attributes
----------
histogram_values : np.ndarray
Histogram counts of shape (n_rows, n_cols, n_bins).
histogram_bin_centers : np.ndarray
Bin centers in ADU of shape (n_bins,).
pedestal_mean : np.ndarray
Mean pedestal per pixel of shape (n_rows, n_cols).
pedestal_std : np.ndarray
Pedestal standard deviation per pixel of shape (n_rows, n_cols).
"""
__slots__ = ("histogram_values", "histogram_bin_centers", "pedestal_mean", "pedestal_std")
def __init__(self, histogram_values : np.ndarray, histogram_bin_centers : np.ndarray, pedestal_mean : np.ndarray, pedestal_std : np.ndarray):
self.histogram_values : np.ndarray = histogram_values
self.histogram_bin_centers : np.ndarray = histogram_bin_centers
self.pedestal_mean : np.ndarray = pedestal_mean
self.pedestal_std : np.ndarray = pedestal_std
class LinearFitResult():
"""
Result of per-pixel linear fits in two consecutive gain stages, e.g. G0/G1 for the
backplane pulsing scan or G1/G2 for the current source scan.
Attributes
----------
fitted_parameters : np.ndarray
Fitted parameters of shape (n_rows, n_cols, 4). The last axis contains
[intercept, slope] of the first gain stage followed by [intercept, slope] of the second gain stage.
fitrange_1 : np.ndarray
Index range [start, stop) of the scan points used for the fit of the first gain stage,
of shape (n_rows, n_cols, 2).
fitrange_2 : np.ndarray
Index range [start, stop) of the scan points used for the fit of the second gain stage,
of shape (n_rows, n_cols, 2).
"""
__slots__ = ("fitted_parameters", "fitrange_1", "fitrange_2")
def __init__(self, fitted_parameters : np.ndarray, fitrange_1 : np.ndarray, fitrange_2 : np.ndarray):
# third dimension are fitted parameters, gain0 intercept, gain0 slope, gain1 intercept, gain1 slope
self.fitted_parameters : np.ndarray = fitted_parameters
self.fitrange_1 : np.ndarray = fitrange_1
self.fitrange_2 : np.ndarray = fitrange_2
class JungfrauCalibrationResult():
"""
Results of the Jungfrau gain calibration. Gain maps are None until the corresponding
calibration step has been run.
Attributes
----------
beam_energy : float
The energy of the beam in keV used for the G0/HG0 calibration.
gain0 : np.ndarray | None
G0 gain per pixel in ADU/keV of shape (n_rows, n_cols).
gain1 : np.ndarray | None
G1 gain per pixel in ADU/keV, calibrated relative to G0.
gain2 : np.ndarray | None
G2 gain per pixel in ADU/keV, calibrated relative to G1.
highgain0 : np.ndarray | None
HG0 gain per pixel in ADU/keV.
highgain1 : np.ndarray | None
G1 gain per pixel in ADU/keV, calibrated relative to HG0.
highgain2 : np.ndarray | None
G2 gain per pixel in ADU/keV, calibrated relative to the HG0-based G1.
"""
__slots__ = ("beam_energy", "gain0", "gain1", "gain2", "highgain0", "highgain1", "highgain2")
def __init__(self, beam_energy : float):
"""
Parameters
----------
beam_energy : float
The energy of the beam in keV.
"""
self.beam_energy : float = beam_energy # in keV -> should be frozen set by calibration
self.gain0 : np.ndarray | None = None
self.gain1 : np.ndarray | None = None
self.gain2 : np.ndarray | None = None
self.highgain0 : np.ndarray | None = None
self.highgain1 : np.ndarray | None = None # gain 1 relative to highgain 0
self.highgain2 : np.ndarray | None = None # gain 2 relative to highgain 0