-
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.
Merge pull request #67 from scipp/supermirror-efficiency
Add 2nd order polynomial supermirror efficiency function
- Loading branch information
Showing
5 changed files
with
200 additions
and
27 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,61 @@ | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp) | ||
import pytest | ||
import scipp as sc | ||
|
||
import ess.polarization as pol | ||
|
||
|
||
def test_SecondDegreePolynomialEfficiency_raises_if_units_incompatible(): | ||
wav = sc.scalar(1.0, unit='m') | ||
with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"): | ||
eff = pol.SecondDegreePolynomialEfficiency( | ||
a=sc.scalar(1.0, unit='1/angstrom'), | ||
b=sc.scalar(1.0, unit='1/angstrom'), | ||
c=sc.scalar(1.0), | ||
) | ||
eff(wavelength=wav) | ||
with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"): | ||
eff = pol.SecondDegreePolynomialEfficiency( | ||
a=sc.scalar(1.0, unit='1/angstrom**2'), | ||
b=sc.scalar(1.0, unit='1/angstrom**2'), | ||
c=sc.scalar(1.0), | ||
) | ||
eff(wavelength=wav) | ||
with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"): | ||
eff = pol.SecondDegreePolynomialEfficiency( | ||
a=sc.scalar(1.0, unit='1/angstrom**2'), | ||
b=sc.scalar(1.0, unit='1/angstrom'), | ||
c=sc.scalar(1.0, unit='1/angstrom'), | ||
) | ||
eff(wavelength=wav) | ||
with pytest.raises(sc.UnitError, match=" to `dimensionless` is not valid"): | ||
eff = pol.SecondDegreePolynomialEfficiency( | ||
a=sc.scalar(1.0, unit='1/angstrom**2'), | ||
b=sc.scalar(1.0, unit='1/angstrom'), | ||
c=sc.scalar(1.0), | ||
) | ||
eff(wavelength=wav / sc.scalar(1.0, unit='s')) | ||
|
||
|
||
def test_SecondDegreePolynomialEfficiency_produces_correct_values(): | ||
a = sc.scalar(1.0, unit='1/angstrom**2') | ||
b = sc.scalar(2.0, unit='1/angstrom') | ||
c = sc.scalar(3.0) | ||
f = pol.SecondDegreePolynomialEfficiency(a=a, b=b, c=c) | ||
assert f(wavelength=sc.scalar(0.0, unit='angstrom')) == 3.0 | ||
assert f(wavelength=sc.scalar(1.0, unit='angstrom')) == 6.0 | ||
assert f(wavelength=sc.scalar(2.0, unit='angstrom')) == 11.0 | ||
|
||
|
||
def test_SecondDegreePolynomialEfficiency_converts_units(): | ||
a = sc.scalar(1.0, unit='1/angstrom**2') | ||
b = sc.scalar(20.0, unit='1/nm') | ||
c = sc.scalar(3.0) | ||
f = pol.SecondDegreePolynomialEfficiency(a=a, b=b, c=c) | ||
assert f(wavelength=sc.scalar(0.0, unit='angstrom')) == 3.0 | ||
assert f(wavelength=sc.scalar(1.0, unit='angstrom')) == 6.0 | ||
assert f(wavelength=sc.scalar(2.0, unit='angstrom')) == 11.0 | ||
assert f(wavelength=sc.scalar(0.0, unit='nm')) == 3.0 | ||
assert f(wavelength=sc.scalar(0.1, unit='nm')) == 6.0 | ||
assert f(wavelength=sc.scalar(0.2, unit='nm')) == 11.0 |