def test_scale_scale_2(self): import numpy as np import fit2x x = np.arange(0, 16) y = np.ones_like(x) * 100 y2 = y * 10 data = fit2x.DecayCurve(x, y2) settings = { "data": data, "constant_background": 0, "active": True, "start": 0, "stop": -1 } ds = fit2x.DecayScale(**settings) model = fit2x.DecayCurve(x, y) self.assertEqual( np.allclose(ds.data.y, np.ones_like(ds.data.y) * 1000), True) self.assertEqual(np.allclose(model.y, np.ones_like(ds.data.y) * 100), True) ds.add(model) self.assertEqual(np.sum(model.y), np.sum(ds.data.y))
def test_scale_scale_3(self): ds = fit2x.DecayScale(**settings) # Scaling considering noise & background of data ds.constant_background = 100 # Set number of photons to negative value for scaling model = fit2x.DecayCurve(x, y) ds.add(model) self.assertEqual(np.allclose(model.y, ds.data.y - 100), True) self.assertEqual(ds.number_of_photons, 16000)
def test_scale_scale_1(self): x = np.arange(0, 16) y = np.ones_like(x) * 100 y2 = y * 10 data = fit2x.DecayCurve(x, y2) settings = { "data": data, "constant_background": 0, "active": True, "start": 0, "stop": -1 } ds = fit2x.DecayScale(**settings) model = fit2x.DecayCurve(x, y) ds.add(model) self.assertEqual(np.allclose(model.y, data.y), True) ds.active = False self.assertEqual(ds.active, False) model = fit2x.DecayCurve(x, y) ds.add(model) self.assertEqual(np.allclose(model.y, y), True)
def test_scale_init(self): ds = fit2x.DecayScale(**settings) self.assertEqual(np.allclose(ds.data.y, data.y), True) self.assertEqual(np.allclose(ds.data.x, data.x), True) self.assertEqual(ds.constant_background, 0.0) self.assertEqual(ds.active, True)
def __init__( self, data_settings=None, # type: DataSettings lifetime_settings=None, # type: LifetimeSettings convolution_settings=None, # type: ConvolutionSettings scatter_settings=None, # type: PatternSettings background_settings=None, # type: PatternSettings pileup_settings=None, # type: PileupSettings scaling_settings=None, # type: ScalingSettings linearization_settings=None, # type: LinearizationSettings score_settings=None # type: ScoreSettings ): super().__init__() if data_settings is None: data_settings = DataSettings() if lifetime_settings is None: lifetime_settings = LifetimeSettings() if convolution_settings is None: convolution_settings = ConvolutionSettings() if background_settings is None: background_settings = PatternSettings() if scatter_settings is None: scatter_settings = PatternSettings() if pileup_settings is None: pileup_settings = PileupSettings() if linearization_settings is None: linearization_settings = LinearizationSettings() if scaling_settings is None: scaling_settings = ScalingSettings() if score_settings is None: score_settings = ScoreSettings() # init decay curves data, irf = self.make_decay_curves(*data_settings) model = fit2x.DecayCurve(data.x) lifetime_handler = fit2x.DecayLifetimeHandler(*lifetime_settings) decay_convolution = fit2x.DecayConvolution(lifetime_handler, irf, *convolution_settings) decay_scatter = fit2x.DecayPattern(*scatter_settings) decay_scatter.data = irf decay_background = fit2x.DecayPattern(*background_settings) decay_pileup = fit2x.DecayPileup(data, *pileup_settings) decay_linearization = fit2x.DecayLinearization(*linearization_settings) decay_scale = fit2x.DecayScale(data, *scaling_settings) decay_score = fit2x.DecayScore(model, data, *score_settings) self._data, self._irf, self._model = data, irf, model self.lifetime_handler = lifetime_handler self.decay_convolution = decay_convolution self.decay_scatter = decay_scatter self.decay_pileup = decay_pileup self.decay_linearization = decay_linearization self.decay_scale = decay_scale self.decay_background = decay_background self.decay_score = decay_score self._decay_modifier = [ self.decay_convolution, self.decay_scatter, # self.decay_pileup, # TODO: seems broken self.decay_linearization, self.decay_scale, self.decay_background, ]