use slots for python classes
This commit is contained in:
1 parent
f0a627d2b5
commit
f972762bda
3 files changed
+45
-38
No files matched your search
@@ -2,7 +2,7 @@ from dataclasses import dataclass, field
|
||||
import numpy as np
|
||||
from functools import cached_property
|
||||
|
||||
@dataclass
|
||||
@dataclass(slots=True)
|
||||
class HistogramParameters:
|
||||
"""
|
||||
Parameters controlling the per-pixel histogram calculation of the fluorescence data.
|
||||
@@ -33,7 +33,7 @@ class HistogramParameters:
|
||||
n_threads : int = 16
|
||||
max_frames_to_process : int = None
|
||||
|
||||
class HistogramResult:
|
||||
class HistogramResult():
|
||||
"""
|
||||
Per-pixel histograms of the pedestal-subtracted fluorescence data and the corresponding pedestal.
|
||||
|
||||
@@ -48,13 +48,14 @@ class HistogramResult:
|
||||
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:
|
||||
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.
|
||||
@@ -71,13 +72,14 @@ class LinearFitResult:
|
||||
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:
|
||||
class JungfrauCalibrationResult():
|
||||
"""
|
||||
Results of the Jungfrau gain calibration. Gain maps are None until the corresponding
|
||||
calibration step has been run.
|
||||
@@ -99,6 +101,7 @@ class JungfrauCalibrationResult:
|
||||
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):
|
||||
"""
|
||||
|
||||
@@ -30,50 +30,54 @@ class JungfrauInputParameters:
|
||||
A class to hold input parameters for the Jungfrau detector calibration.
|
||||
"""
|
||||
|
||||
_file_dir : Path = None
|
||||
__slots__ = ("_file_dir", "_pedestal_file", "_pedestal_file_hg", "_num_pedestals_g0", "_num_pedestals_g1", "_num_pedestals_g2", "_num_pedestals_hg0", "_num_pedestals_hg1",
|
||||
"_num_pedestals_hg2", "pedestal_g0_file_prefix", "pedestal_g1_file_prefix", "pedestal_g2_file_prefix", "_fluorescent_Copper_file", "_fluorescent_Copper_file_hg",
|
||||
"_backplane_pulsing_signals", "_backplane_pulsing_signals_hg", "_cs_data", "_cs_data_offset", "_output_dir", "_backplanepulsing_voltages",
|
||||
"_currentsource_exptimes", "_histogram_params_G0", "_histogram_params_HG0", "_fit_elastic_scattering", "_beam_energy", "_num_acquisition_per_cs_exposure", "_num_acquisition_per_bp_pulse" )
|
||||
|
||||
#deprecated - use pedestal_g0_file_prefix instead
|
||||
_pedestal_file : Path = None
|
||||
_pedestal_file_hg : Path = None
|
||||
_num_pedestals_g0 : int = 1000
|
||||
_num_pedestals_g1 : int = 1000
|
||||
_num_pedestals_g2 : int = 1000
|
||||
_num_pedestals_hg0 : int = None
|
||||
_num_pedestals_hg1 : int = None
|
||||
_num_pedestals_hg2 : int = None
|
||||
def __init__(self):
|
||||
self._file_dir : Path = None # TODO: maybe use a sentinel for all the None types - more specific
|
||||
|
||||
pedestal_g0_file_prefix : str = None
|
||||
pedestal_g1_file_prefix : str = None
|
||||
pedestal_g2_file_prefix : str = None
|
||||
#deprecated - use pedestal_g0_file_prefix instead
|
||||
self._pedestal_file : Path = None
|
||||
self._pedestal_file_hg : Path = None
|
||||
self._num_pedestals_g0 : int = 1000
|
||||
self._num_pedestals_g1 : int = 1000
|
||||
self._num_pedestals_g2 : int = 1000
|
||||
self._num_pedestals_hg0 : int = None
|
||||
self._num_pedestals_hg1 : int = None
|
||||
self._num_pedestals_hg2 : int = None
|
||||
|
||||
_fluorescent_Copper_file : Path = None
|
||||
_fluorescent_Copper_file_hg : Path = None
|
||||
self.pedestal_g0_file_prefix : str = None
|
||||
self.pedestal_g1_file_prefix : str = None
|
||||
self.pedestal_g2_file_prefix : str = None
|
||||
|
||||
self._fluorescent_Copper_file : Path = None
|
||||
self._fluorescent_Copper_file_hg : Path = None
|
||||
|
||||
_backplane_pulsing_signals : Path = None
|
||||
_backplane_pulsing_signals_hg : Path = None
|
||||
_cs_data : Path = None
|
||||
_cs_data_offset : int = 3*10*64
|
||||
self._backplane_pulsing_signals : Path = None
|
||||
self._backplane_pulsing_signals_hg : Path = None
|
||||
self._cs_data : Path = None
|
||||
self._cs_data_offset : int = 3*10*64
|
||||
|
||||
# outputs
|
||||
_output_dir : Path = Path.cwd() # default to current working directory
|
||||
# outputs
|
||||
self._output_dir : Path = Path.cwd() # default to current working directory
|
||||
|
||||
# backplane pulsing parameters
|
||||
_backplanepulsing_voltages : np.ndarray = None
|
||||
# backplane pulsing parameters
|
||||
self._backplanepulsing_voltages : np.ndarray = None
|
||||
|
||||
# current source exposure times
|
||||
_currentsource_exptimes : np.ndarray = None
|
||||
# current source exposure times
|
||||
self._currentsource_exptimes : np.ndarray = None
|
||||
|
||||
_histogram_params_G0 : HistogramParameters = field(default_factory=lambda: HistogramParameters(adu_min = 200.5, adu_max = 600.5))
|
||||
self._histogram_params_G0 : HistogramParameters = field(default_factory=lambda: HistogramParameters(adu_min = 200.5, adu_max = 600.5))
|
||||
|
||||
_histogram_params_HG0 : HistogramParameters = field(default_factory=lambda: HistogramParameters(adu_min = 600.5, adu_max = 1400.5))
|
||||
self._histogram_params_HG0 : HistogramParameters = field(default_factory=lambda: HistogramParameters(adu_min = 600.5, adu_max = 1400.5))
|
||||
|
||||
_fit_elastic_scattering : bool = False # wether to fit elastic scattering in CuFlo spectra - default is False
|
||||
self._fit_elastic_scattering : bool = False # wether to fit elastic scattering in CuFlo spectra - default is False
|
||||
self._beam_energy : float = 8.048 # keV - default energy of the beam
|
||||
|
||||
_beam_energy : float = 8.048 # keV - default energy of the beam
|
||||
|
||||
_num_acquisition_per_cs_exposure : int = 10 # number of acquisitions per exposure time for the current source data - default is 10
|
||||
_num_acquisition_per_bp_pulse : int = 100 # number of samples per backplane pulsing voltage - default is 100
|
||||
self._num_acquisition_per_cs_exposure : int = 10 # number of acquisitions per exposure time for the current source data - default is 10
|
||||
self._num_acquisition_per_bp_pulse : int = 100 # number of samples per backplane pulsing voltage - default is 100
|
||||
|
||||
@classmethod
|
||||
def from_config(cls, config_file : Path) -> "JungfrauInputParameters":
|
||||
|
||||
@@ -23,7 +23,7 @@ class GAINTYPE(Enum):
|
||||
G1 = 2 # gain 1
|
||||
G2 = 3 # gain 2
|
||||
|
||||
@dataclass
|
||||
@dataclass(slots=True)
|
||||
class Parameter:
|
||||
"""
|
||||
A single fit parameter consisting of an initial guess and optional bounds.
|
||||
@@ -41,7 +41,7 @@ class Parameter:
|
||||
lower_bound : float = None # a parameter limit of None defaults to -infinity
|
||||
upper_bound : float = None # a parameter limit of None defaults to infinity
|
||||
|
||||
@dataclass
|
||||
@dataclass(slots=True)
|
||||
class FitParams:
|
||||
"""
|
||||
Initial guesses and bounds for the per-pixel fit of the copper fluorescence spectrum.
|
||||
|
||||
Reference in new issue
Block a user