Skip to content

Commit 8a8ebe3

Browse files
committed
WIP export/restore special cases
1 parent 6e0f270 commit 8a8ebe3

File tree

5 files changed

+157
-13
lines changed

5 files changed

+157
-13
lines changed

hklpy2/diffract.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,15 @@ def print_axes(names):
302302

303303
if full:
304304
print(f"diffractometer={self.name!r}")
305-
print(f"{self.sample}")
306305
print(f"{self.operator.solver}")
307-
# TODO: reflections
308-
# TODO: constraints
306+
print(f"{self.sample!r}")
307+
print(f"U={self.operator.solver.U}")
308+
print(f"UB={self.operator.solver.UB}")
309+
for v in self.operator.sample.reflections.values():
310+
print(f"{v}")
311+
for v in self.operator.constraints.values():
312+
print(f"constraint: {v}")
313+
309314
print_axes(self.pseudo_axis_names)
310315
print(f"wavelength={self.wavelength.get()}")
311316
print_axes(self.real_axis_names)

hklpy2/operations/configure.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _asdict(self) -> dict:
4747
from ..__init__ import __version__
4848

4949
dfrct = self.diffractometer # local shortcut
50-
config = {
50+
config = { # TODO: move to operator._asdict()
5151
"_header": {
5252
"datetime": str(datetime.datetime.now()),
5353
"energy_units": dfrct._wavelength.energy_units,
@@ -74,7 +74,8 @@ def export(self, file, comment=""):
7474
e4cv.operator.configuration.export("e4cv-config.yml", comment="example")
7575
"""
7676
path = pathlib.Path(file)
77-
config = self._asdict()
77+
config = self._asdict() # TODO: call operator._asdict() directly
78+
# TODO: could pass additional header content as kwargs
7879
config["_header"]["file"] = str(file)
7980
config["_header"]["comment"] = str(comment)
8081
dump = yaml.dump(
@@ -162,7 +163,7 @@ def compare(incoming, existing, template):
162163
"engine mismatch: incoming=%r existing=%r",
163164
)
164165
compare(
165-
config.get("geometry"),
166+
config.get("geometry"), # TODO: geometry belongs in solver section
166167
self.diffractometer.operator.solver.geometry,
167168
"geometry mismatch: incoming=%r existing=%r",
168169
)

hklpy2/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def _asdict(self):
8989
"""Describe the diffractometer as a dictionary."""
9090
config = {
9191
"name": self.diffractometer.name,
92-
"geometry": self.geometry,
92+
"geometry": self.geometry, # TODO: geometry belongs in solver section
9393
"axes": {
9494
"pseudo_axes": self.diffractometer.pseudo_axis_names,
9595
"real_axes": self.diffractometer.real_axis_names,
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#hklpy2 configuration file
2+
3+
_header:
4+
datetime: '2024-09-26 17:15:41.875799'
5+
energy_units: keV
6+
energy: 11.363646219141787
7+
hklpy2_version: 0.0.25.dev88+g6e0f270.d20240926
8+
python_class: Fourc
9+
source_type: X-ray
10+
wavelength_units: angstrom
11+
wavelength: 1.09106
12+
file: fourc-configuration.yml
13+
comment: 'E4CV with Fourc axes names and vibranium orientation'
14+
name: fourc
15+
geometry: E4CV
16+
axes:
17+
pseudo_axes:
18+
- h
19+
- k
20+
- l
21+
real_axes:
22+
- theta
23+
- chi
24+
- phi
25+
- ttheta
26+
axes_xref:
27+
h: h
28+
k: k
29+
l: l
30+
theta: omega
31+
chi: chi
32+
phi: phi
33+
ttheta: tth
34+
extra_axes: {}
35+
sample_name: vibranium
36+
samples:
37+
vibranium:
38+
name: vibranium
39+
lattice:
40+
a: 6.283185307179586
41+
b: 6.283185307179586
42+
c: 6.283185307179586
43+
alpha: 90.0
44+
beta: 90.0
45+
gamma: 90.0
46+
reflections:
47+
r1:
48+
name: r1
49+
geometry: E4CV
50+
pseudos:
51+
h: 2
52+
k: 0
53+
l: 0
54+
reals:
55+
theta: 10
56+
chi: 0
57+
phi: 0
58+
ttheta: 20
59+
wavelength: 1.09106
60+
digits: 4
61+
r2:
62+
name: r2
63+
geometry: E4CV
64+
pseudos:
65+
h: 0
66+
k: 2
67+
l: 0
68+
reals:
69+
theta: 10
70+
chi: 90
71+
phi: 0
72+
ttheta: 20
73+
wavelength: 1.09106
74+
digits: 4
75+
reflections_order:
76+
- r1
77+
- r2
78+
U:
79+
- - -0.0
80+
- -0.0
81+
- -1.0
82+
- - 0.0
83+
- 1.0
84+
- -0.0
85+
- - 1.0
86+
- -0.0
87+
- -0.0
88+
UB:
89+
- - -0.0
90+
- -0.0
91+
- -1.0
92+
- - 0.0
93+
- 1.0
94+
- -0.0
95+
- - 1.0
96+
- -0.0
97+
- -0.0
98+
digits: 3
99+
constraints:
100+
theta:
101+
label: theta
102+
low_limit: -180.0
103+
high_limit: 180.0
104+
class: LimitsConstraint
105+
chi:
106+
label: chi
107+
low_limit: -180.0
108+
high_limit: 180.0
109+
class: LimitsConstraint
110+
phi:
111+
label: phi
112+
low_limit: -180.0
113+
high_limit: 180.0
114+
class: LimitsConstraint
115+
ttheta:
116+
label: ttheta
117+
low_limit: -180.0
118+
high_limit: 180.0
119+
class: LimitsConstraint
120+
solver:
121+
name: hkl_soleil
122+
version: 5.0.0.3512
123+
mode: bissector
124+
description: HklSolver(name='hkl_soleil', version='5.0.0.3512', geometry='E4CV',
125+
engine_name='hkl', mode='bissector')
126+
real_axes:
127+
- omega
128+
- chi
129+
- phi
130+
- tth
131+
engine: hkl

hklpy2/tests/test_diffract.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,19 @@ def test_diffractometer_wh(capsys):
302302
e4cv.wh(full=True)
303303
captured = capsys.readouterr()
304304
lines = captured.out.splitlines()
305-
assert len(lines) == 6, f"{captured.out=}"
305+
assert len(lines) == 12, f"{captured.out=}"
306306
assert lines[0].startswith("diffractometer=")
307-
assert lines[1].startswith("Sample(name=")
308-
assert lines[2].startswith("HklSolver(name")
309-
assert lines[3].startswith("h=")
310-
assert lines[4].startswith("wavelength=")
311-
assert lines[5].startswith("omega=")
307+
assert lines[1].startswith("HklSolver(name")
308+
assert lines[2].startswith("Sample(name=")
309+
assert lines[3].startswith("U=")
310+
assert lines[4].startswith("UB=")
311+
# assert lines[].startswith("Reflection(")
312+
assert lines[5].startswith("constraint: ")
313+
assert lines[6].startswith("constraint: ")
314+
assert lines[7].startswith("constraint: ")
315+
assert lines[8].startswith("constraint: ")
316+
assert lines[9].startswith("h=")
317+
assert lines[10].startswith("wavelength=")
318+
assert lines[11].startswith("omega=")
312319

313320
# TODO: extra axis names

0 commit comments

Comments
 (0)