Skip to content

Commit f0a3f40

Browse files
committed
TST #183
1 parent 13663de commit f0a3f40

File tree

2 files changed

+261
-0
lines changed

2 files changed

+261
-0
lines changed

src/hklpy2/tests/fourc-i183.yml

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
_header:
2+
datetime: '2025-12-16 13:11:34.406792'
3+
hklpy2_version: 0.2.3
4+
python_class: Hklpy2Diffractometer
5+
axes:
6+
axes_xref:
7+
chi: chi
8+
h: h
9+
k: k
10+
l: l
11+
omega: omega
12+
phi: phi
13+
tth: tth
14+
extra_axes:
15+
h2: 0
16+
k2: 0
17+
l2: 0
18+
psi: 0
19+
pseudo_axes:
20+
- h
21+
- k
22+
- l
23+
real_axes:
24+
- omega
25+
- chi
26+
- phi
27+
- tth
28+
beam:
29+
class: WavelengthXray
30+
energy: 0.8532488933033981
31+
energy_units: keV
32+
source_type: Synchrotron X-ray Source
33+
wavelength: 14.530836126673075
34+
wavelength_units: angstrom
35+
constraints:
36+
chi:
37+
class: LimitsConstraint
38+
high_limit: 100.0
39+
label: chi
40+
low_limit: -2.0
41+
omega:
42+
class: LimitsConstraint
43+
high_limit: 180.0
44+
label: omega
45+
low_limit: -0.001
46+
phi:
47+
class: LimitsConstraint
48+
high_limit: 41.0
49+
label: phi
50+
low_limit: 40.0
51+
tth:
52+
class: LimitsConstraint
53+
high_limit: 180.0
54+
label: tth
55+
low_limit: -0.001
56+
digits: 4
57+
name: e4cv
58+
sample_name: s2
59+
samples:
60+
s2:
61+
U:
62+
- - 0.99898330497
63+
- 0.044644845851
64+
- -0.006260521558
65+
- - 0.00534944469
66+
- 0.020497566724
67+
- 0.99977559142
68+
- - 0.044763152623
69+
- -0.998792614859
70+
- 0.020237901816
71+
UB:
72+
- - 1.609641549918
73+
- 0.071935335169
74+
- -0.010087451485
75+
- - 0.008619451796
76+
- 0.033027313776
77+
- 1.610918145016
78+
- - 0.072125960472
79+
- -1.609334294808
80+
- 0.032608920974
81+
digits: 4
82+
lattice:
83+
a: 3.8995
84+
alpha: 90
85+
angle_units: degrees
86+
b: 3.8995
87+
beta: 90
88+
c: 3.8995
89+
digits: 4
90+
gamma: 90
91+
length_units: angstrom
92+
name: s2
93+
reflections:
94+
r_1b82:
95+
digits: 4
96+
geometry: E4CV
97+
name: r_1b82
98+
pseudos:
99+
h: 0
100+
k: 0
101+
l: 1
102+
reals:
103+
chi: 88.826
104+
omega: 39.177
105+
phi: -2.465
106+
tth: 78.971
107+
reals_units: angstrom
108+
wavelength: 4.9592
109+
wavelength_units: angstrom
110+
r_ee52:
111+
digits: 4
112+
geometry: E4CV
113+
name: r_ee52
114+
pseudos:
115+
h: 1
116+
k: 0
117+
l: 1
118+
reals:
119+
chi: 88.734
120+
omega: 108.15
121+
phi: -2.465
122+
tth: 128.05
123+
reals_units: angstrom
124+
wavelength: 4.9592
125+
wavelength_units: angstrom
126+
reflections_order:
127+
- r_1b82
128+
- r_ee52
129+
sample:
130+
U:
131+
- - 1
132+
- 0
133+
- 0
134+
- - 0
135+
- 1
136+
- 0
137+
- - 0
138+
- 0
139+
- 1
140+
UB:
141+
- - 6.283185307179586
142+
- 0.0
143+
- 0.0
144+
- - 0.0
145+
- 6.283185307179586
146+
- 0.0
147+
- - 0.0
148+
- 0.0
149+
- 6.283185307179586
150+
digits: 4
151+
lattice:
152+
a: 1
153+
alpha: 90.0
154+
angle_units: degrees
155+
b: 1
156+
beta: 90.0
157+
c: 1
158+
digits: 4
159+
gamma: 90.0
160+
length_units: angstrom
161+
name: sample
162+
reflections: {}
163+
reflections_order: []
164+
solver:
165+
description: HklSolver(name='hkl_soleil', version='5.1.3', geometry='E4CV', engine_name='hkl',
166+
mode='constant_phi')
167+
engine: hkl
168+
geometry: E4CV
169+
name: hkl_soleil
170+
real_axes:
171+
- omega
172+
- chi
173+
- phi
174+
- tth
175+
version: 5.1.3

src/hklpy2/tests/test_i183.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""Issue 183: UB matrix reported by pa() and configuration differ."""
2+
3+
import ast
4+
import pathlib
5+
from contextlib import nullcontext as does_not_raise
6+
7+
import numpy as np
8+
import pytest
9+
import yaml
10+
11+
from ..diffract import creator
12+
from ..user import cahkl
13+
from ..user import pa
14+
from ..user import set_diffractometer
15+
16+
THIS_DIR = pathlib.Path(__file__).parent
17+
18+
19+
@pytest.mark.parametrize(
20+
"specs, cfg_file, reals, hkl1, context",
21+
[
22+
pytest.param(
23+
dict(geometry="E4CV", solver="hkl_soleil"),
24+
THIS_DIR / "fourc-i183.yml",
25+
dict(omega=0, chi=0, phi=40, tth=0),
26+
(0.25, 0.25, 2 * 3.8995 / 20.5311),
27+
does_not_raise(),
28+
id="Ok: issue 183",
29+
),
30+
pytest.param(
31+
dict(geometry="E4CV", solver="hkl_soleil"),
32+
THIS_DIR / "e4cv_orient.yml",
33+
dict(omega=0, chi=0, phi=40, tth=0),
34+
(0, 0.5, 0),
35+
does_not_raise(),
36+
id="Ok: e4cv_orient",
37+
),
38+
pytest.param(
39+
dict(geometry="E4CV", solver="hkl_soleil"),
40+
THIS_DIR / "fourc-configuration.yml",
41+
dict(omega=0, chi=0, phi=40, tth=0),
42+
(0, 0.5, 0),
43+
does_not_raise(),
44+
id="Ok: fourc-configuration",
45+
),
46+
],
47+
)
48+
def test_issue183(specs, cfg_file, reals, hkl1, context, capsys):
49+
with context:
50+
with open(cfg_file) as fp:
51+
cfg = yaml.load(fp.read(), Loader=yaml.SafeLoader)
52+
53+
sim = creator(**specs)
54+
sim.move_reals(reals)
55+
sim.restore(cfg_file)
56+
57+
assert np.allclose(
58+
np.array(cfg["samples"][cfg["sample_name"]]["UB"]),
59+
np.array(sim.core.sample.UB),
60+
atol=0.01,
61+
)
62+
63+
assert np.allclose(
64+
np.array(sim.core.sample.UB),
65+
np.array(sim.configuration["samples"][sim.core.sample.name]["UB"]),
66+
atol=0.01,
67+
)
68+
69+
# Compare with value reported in pa()
70+
set_diffractometer(sim)
71+
pa()
72+
out, err = capsys.readouterr()
73+
assert err == ""
74+
assert "UB=" in out
75+
76+
# pick out the one line with the UB matrix
77+
line = out[out.find("UB=") + 3 :].splitlines()[0]
78+
ub = ast.literal_eval(line)
79+
assert np.allclose(
80+
np.array(sim.core.sample.UB),
81+
np.array(ub),
82+
atol=0.01,
83+
)
84+
85+
# should not raise NoForwardSolutions or return ()
86+
cahkl(*hkl1)

0 commit comments

Comments
 (0)