@@ -8,7 +8,7 @@ class ComponentSignal:
8
8
----------
9
9
grid: 1d array of floats
10
10
The vector containing the grid points of the component.
11
-
11
+ iq: 1d array of floats
12
12
The intensity/g(r) values of the component.
13
13
weights: 1d array of floats
14
14
The vector containing the weight of the component signal for each signal.
@@ -25,23 +25,6 @@ def __init__(self, grid, number_of_signals, id_number, perturbation=1e-3):
25
25
self .stretching_factors = np .ones (number_of_signals ) + np .random .randn (number_of_signals ) * perturbation
26
26
self .id = int (id_number )
27
27
28
- def _interpolate_stretching_factor (self , stretching_factor ):
29
- """Interpolates the intensity values over a normalized grid scaled by a given stretching factor.
30
-
31
- Parameters
32
- ----------
33
- stretching_factor : float
34
- The factor by which to stretch the grid.
35
-
36
- Returns
37
- -------
38
- NDArray[float64]
39
- Interpolated values of the self.iq values over the grid that has been adjusted by the stretching_factor
40
- """
41
-
42
- normalized_grid = np .arange (len (self .grid ))
43
- return np .interp (normalized_grid / stretching_factor , normalized_grid , self .iq , left = 0 , right = 0 )
44
-
45
28
def apply_stretch (self , m ):
46
29
"""Applies a stretching factor to a component
47
30
@@ -53,14 +36,17 @@ def apply_stretch(self, m):
53
36
Returns
54
37
-------
55
38
tuple of 1d arrays
56
- The tuple of vectors where one vector is the stretched component, one vector is the 1st derivative
57
- of the stretching operation, and one vector is the second derivative of the stretching operation.
39
+ The tuple of vectors where one vector is the stretched component, one vector is the 1st derivative of the
40
+ stretching operation, and one vector is the second derivative of the stretching operation.
58
41
"""
59
-
60
- derivative_func = numdifftools .Derivative (self ._interpolate_stretching_factor )
42
+ normalized_grid = np .arange (len (self .grid ))
43
+ func = lambda stretching_factor : np .interp ( # noqa: E731
44
+ normalized_grid / stretching_factor , normalized_grid , self .iq , left = 0 , right = 0
45
+ )
46
+ derivative_func = numdifftools .Derivative (func )
61
47
second_derivative_func = numdifftools .Derivative (derivative_func )
62
48
63
- stretched_component = self . _interpolate_stretching_factor (self .stretching_factors [m ])
49
+ stretched_component = func (self .stretching_factors [m ])
64
50
stretched_component_gra = derivative_func (self .stretching_factors [m ])
65
51
stretched_component_hess = second_derivative_func (self .stretching_factors [m ])
66
52
0 commit comments