-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from jmborr/42_tabulated_resolution
Tabulated resolution function
- Loading branch information
Showing
6 changed files
with
65 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ Models | |
:maxdepth: 1 | ||
|
||
deltadirac | ||
resolution | ||
strexpft | ||
tabulatedmodel | ||
teixeira | ||
|
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,7 @@ | ||
Resolution models | ||
================= | ||
|
||
.. automodule:: qef.models.resolution | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
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,21 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
|
||
from qef.models.tabulatedmodel import TabulatedModel | ||
|
||
|
||
class TabulatedResolutionModel(TabulatedModel): | ||
r"""Interpolator of resolution data with no fit parameters | ||
Parameters | ||
---------- | ||
xs: :class:`~numpy:numpy.ndarray` | ||
given domain of the function, energy | ||
ys: :class:`~numpy:numpy.ndarray` | ||
given domain of the function, intensity | ||
""" | ||
|
||
def __init__(self, xs, ys, *args, **kwargs): | ||
super(TabulatedResolutionModel, self).__init__(xs, ys, *args, **kwargs) | ||
self.set_param_hint('amplitude', value=1.0, vary=False) | ||
self.set_param_hint('center', value=0.0, vary=False) |
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,29 @@ | ||
from __future__ import (absolute_import, division, print_function) | ||
|
||
import os | ||
import pytest | ||
import numpy as np | ||
from lmfit.lineshapes import lorentzian | ||
|
||
from qef.models.resolution import TabulatedResolutionModel | ||
|
||
|
||
def test_tabulated_resolution(): | ||
x_sim = np.arange(-1.0, 1.0, 0.0003) # energy domain, in meV | ||
y_sim = lorentzian(x_sim, amplitude=1, center=0, sigma=0.042) | ||
intensity = 42.0 | ||
peak_center = 0.0002 | ||
x_exp = np.arange(-0.1, 0.5, 0.0004) | ||
y_exp = lorentzian(x_exp, amplitude=intensity, center=peak_center, | ||
sigma=0.042) | ||
|
||
model = TabulatedResolutionModel(x_sim, y_sim) | ||
params = model.make_params() | ||
fit = model.fit(y_exp, params, x=x_exp) | ||
|
||
assert abs(fit.best_values['amplitude'] - 1.0) < 0.0001 | ||
assert abs(fit.best_values['center'] - 0.0) < 0.0001 | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main([os.path.abspath(__file__)]) |