Skip to content

Commit 1243f1a

Browse files
committed
Add noqa: E731 for lambda func
1 parent 9ca7caf commit 1243f1a

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

diffpy/snmf/containers.py

+9-23
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ComponentSignal:
88
----------
99
grid: 1d array of floats
1010
The vector containing the grid points of the component.
11-
11+
iq: 1d array of floats
1212
The intensity/g(r) values of the component.
1313
weights: 1d array of floats
1414
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):
2525
self.stretching_factors = np.ones(number_of_signals) + np.random.randn(number_of_signals) * perturbation
2626
self.id = int(id_number)
2727

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-
4528
def apply_stretch(self, m):
4629
"""Applies a stretching factor to a component
4730
@@ -53,14 +36,17 @@ def apply_stretch(self, m):
5336
Returns
5437
-------
5538
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.
5841
"""
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)
6147
second_derivative_func = numdifftools.Derivative(derivative_func)
6248

63-
stretched_component = self._interpolate_stretching_factor(self.stretching_factors[m])
49+
stretched_component = func(self.stretching_factors[m])
6450
stretched_component_gra = derivative_func(self.stretching_factors[m])
6551
stretched_component_hess = second_derivative_func(self.stretching_factors[m])
6652

0 commit comments

Comments
 (0)