6 from typing
import NamedTuple
8 MAX_FLOAT = np.finfo(np.float64).max
9 MIN_FLOAT = np.finfo(np.float64).min
12 class DataSettings(NamedTuple):
13 data: np.ndarray =
None
14 data_noise: np.ndarray =
None
15 time_axis: np.array =
None
16 irf_histogram: np.array =
None
17 acquisition_time: float = MAX_FLOAT
20 class LifetimeSettings(NamedTuple):
21 lifetime_spectrum: np.array = np.array([], dtype=np.float64)
22 use_amplitude_threshold: bool =
False
23 abs_lifetime_spectrum: bool =
True
24 amplitude_threshold: float = MIN_FLOAT
27 class ConvolutionSettings(NamedTuple):
28 convolution_method: int = IMP.bff.DecayConvolution.FAST
29 excitation_period: float = 100.0
30 irf_shift_channels: float = 0.0
31 irf_background_counts: float = 0.0
37 class PatternSettings(NamedTuple):
38 constant_offset: float = 0.0
40 pattern_fraction: float = 0.0
46 class PileupSettings(NamedTuple):
47 pile_up_model: str =
"coates"
48 repetition_rate: float = 10.0
49 instrument_dead_time: float = 120.0
55 class ScalingSettings(NamedTuple):
56 constant_offset: float = 0.0
62 class LinearizationSettings(NamedTuple):
69 class ScoreSettings(NamedTuple):
70 score_type: str =
"default"
78 _ignore_attributes = [
82 'linearization_table',
97 'data': (
"_data",
"y"),
98 'data_noise': (
"_data",
"ey"),
99 'model': (
"_model",
"y"),
100 'y': (
"_model",
"y"),
101 'x': (
"_model",
"x"),
102 'acquisition_time': (
"_data",
"acquisition_time"),
103 'time_axis': (
"_data",
"x"),
104 'irf_histogram': (
"_irf",
"y"),
105 'irf': (
"_irf",
"y"),
110 'lifetime_spectrum': (
"lifetime_handler",
"get_lifetime_spectrum",
111 "set_lifetime_spectrum"),
112 'use_amplitude_threshold': (
"lifetime_handler",
113 "use_amplitude_threshold"),
114 'abs_lifetime_spectrum': (
"lifetime_handler",
"abs_lifetime_spectrum"),
115 'amplitude_threshold': (
"lifetime_handler",
"amplitude_threshold"),
118 'corrected_irf': (
"decay_convolution.corrected_irf",
"y"),
119 'convolution_range': (
"decay_convolution",
"get_range",
"set_range"),
120 'convolution_method': (
"decay_convolution",
"convolution_method"),
121 'excitation_period': (
"decay_convolution",
"excitation_period"),
122 'irf_shift_channels': (
"decay_convolution",
"irf_shift_channels"),
123 'irf_background_counts': (
"decay_convolution",
124 "irf_background_counts"),
127 'scatter_fraction': (
"decay_scatter",
"pattern_fraction"),
130 'constant_offset': (
"",
"constant_background"),
131 'pattern_fraction': (
"decay_background",
"pattern_fraction"),
134 'pile_up_model': (
"decay_pileup",
"pile_up_model"),
135 'instrument_dead_time': (
"decay_pileup",
"instrument_dead_time"),
136 'use_pile_up_correction': (
"decay_pileup",
"active"),
139 'scale_model_to_data': (
"decay_scale",
"active"),
140 'number_of_photons': (
"decay_scale",
"number_of_photons"),
143 'linearization_table': (
"decay_linearization.data",
"y"),
144 'linearization': (
"decay_linearization.data",
"y"),
145 'use_linearization': (
"decay_linearization",
"active"),
148 'score_type': (
"decay_score",
"score_type"),
149 'score_range': (
'',
'get_score_range',
'set_score_range'),
150 'score': (
"decay_score",
"score"),
151 'weighted_residuals': (
"decay_score",
"weighted_residuals")
155 'get_mean_lifetime': (
"decay_convolution",
"get_mean_lifetime"),
156 'get_score': (
"decay_score",
"get_score")
160 def make_decay_curves(
161 data: np.ndarray =
None,
162 data_noise: np.ndarray =
None,
163 time_axis: np.array =
None,
164 irf_histogram: np.array =
None,
168 acquisition_time: float = MAX_FLOAT,
171 if time_axis
is None:
172 time_axis = np.array([], np.float64)
174 data = np.array([], np.float64)
176 if irf_histogram
is None:
177 irf_histogram = np.zeros_like(data)
178 if len(irf_histogram) > 0:
179 irf_histogram[0] = 1.0
181 acquisition_time=acquisition_time)
183 if data_noise
is not None:
184 decay.set_ey(data_noise)
190 lifetime_settings=
None,
191 convolution_settings=
None,
192 scatter_settings=
None,
193 background_settings=
None,
194 pileup_settings=
None,
195 scaling_settings=
None,
196 linearization_settings=
None,
200 if data_settings
is None:
201 data_settings = DataSettings()
202 if lifetime_settings
is None:
203 lifetime_settings = LifetimeSettings()
204 if convolution_settings
is None:
205 convolution_settings = ConvolutionSettings()
206 if background_settings
is None:
207 background_settings = PatternSettings()
208 if scatter_settings
is None:
209 scatter_settings = PatternSettings()
210 if pileup_settings
is None:
211 pileup_settings = PileupSettings()
212 if linearization_settings
is None:
213 linearization_settings = LinearizationSettings()
214 if scaling_settings
is None:
215 scaling_settings = ScalingSettings()
216 if score_settings
is None:
217 score_settings = ScoreSettings()
220 data, irf = self.make_decay_curves(*data_settings)
225 lifetime_handler, irf, *convolution_settings)
227 decay_scatter.data = irf
231 *linearization_settings)
235 self._data, self._irf, self._model = data, irf, model
236 self.lifetime_handler = lifetime_handler
237 self.decay_convolution = decay_convolution
238 self.decay_scatter = decay_scatter
239 self.decay_pileup = decay_pileup
240 self.decay_linearization = decay_linearization
241 self.decay_scale = decay_scale
242 self.decay_background = decay_background
243 self.decay_score = decay_score
245 self._decay_modifier = [
246 self.decay_convolution,
249 self.decay_linearization,
251 self.decay_background,
254 def load(self, *args, **kwargs):
255 super().load(*args, **kwargs)
256 self._model.x = self._data.x
257 self._irf.x = self._data.x
261 for dm
in self._decay_modifier:
265 def score(self, *args, **kwargs):
267 return self.decay_score.get_score(*args, **kwargs)
270 def mean_lifetime(self):
271 return self.decay_convolution.get_mean_lifetime(self._data)
274 def constant_background(self):
275 return self.decay_scale.constant_background
277 @constant_background.setter
278 def constant_background(self, v):
279 self.decay_scale.constant_background = v
280 self.decay_background.constant_offset = v
282 def get_score_range(self):
283 return self.decay_score.get_range(self._data)
285 def set_score_range(self, start_stop):
286 for dm
in self._decay_modifier:
287 dm.set_range(start_stop)
288 self.decay_score.set_range(start_stop)
A decorator that adds pile-up effects to a DecayCurve object.
A decay modifier to apply linearization to a DecayCurve.
A class for scaling a DecayCurve by a constant factor and subtracting a constant background value...
Class for scoring model fluorescence decay.
Class for fluorescence decay curves.
The DecayPattern class represents a decay pattern with a constant offset and a background pattern...
Bayesian Fluorescence Framework.
Store and handle lifetime spectra.