-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
91 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .model import Model | ||
from .models import Models | ||
from .resolution_functions import constant_resolution_function | ||
from .resolution_functions import linear_spline_resolution_function | ||
|
||
__all__ = ( | ||
constant_resolution_function, | ||
linear_spline_resolution_function, | ||
Model, | ||
Models, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Callable | ||
|
||
import numpy as np | ||
|
||
|
||
def constant_resolution_function(constant: float) -> Callable[[np.array], np.array]: | ||
"""Create a resolution function that is constant across the q range. | ||
:param constant: The constant resolution value. | ||
""" | ||
|
||
def _constant(q: np.array) -> np.array: | ||
"""Function that calculates the resolution at a given q value. | ||
The function uses the data points from the encapsulating function and produces a linearly interpolated between them. | ||
""" | ||
return np.ones(len(q)) * constant | ||
|
||
return _constant | ||
|
||
|
||
def linear_spline_resolution_function(q_data_points: np.array, resolution_points: np.array) -> Callable[[np.array], np.array]: | ||
"""Create a resolution function that is linearly interpolated between given data points. | ||
:param q_data_points: The q values at which the resolution is defined. | ||
:param resolution_points: The resolution values at the given q values. | ||
""" | ||
|
||
def _linear(q: np.array) -> np.array: | ||
"""Function that calculates the resolution at a given q value. | ||
The function uses the data points from the encapsulating function and produces a linearly interpolated between them. | ||
""" | ||
return np.interp(q, q_data_points, resolution_points) | ||
|
||
return _linear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import numpy as np | ||
|
||
from EasyReflectometry.experiment.resolution_functions import constant_resolution_function | ||
from EasyReflectometry.experiment.resolution_functions import linear_spline_resolution_function | ||
|
||
|
||
def test_constant_resolution_function(): | ||
resolution_function = constant_resolution_function(5) | ||
assert np.all(resolution_function([0, 2.5]) == [5, 5]) | ||
assert resolution_function([-100]) == 5 | ||
assert resolution_function([100]) == 5 | ||
|
||
|
||
def test_linear_spline_resolution_function(): | ||
resolution_function = linear_spline_resolution_function([0, 10], [5, 10]) | ||
assert np.all(resolution_function([0, 2.5]) == [5, 6.25]) | ||
assert resolution_function([-100]) == 5 | ||
assert resolution_function([100]) == 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters