2 # -*- coding: utf-8 -*-
7 import matplotlib
.pyplot
as plt
9 from gi
.repository
import GLib
10 from gi
.repository
import Hkl
13 sample
= Hkl
.Sample
.new("toto")
14 lattice
= Hkl
.Lattice
.new(1.54, 1.54, 1.54,
18 sample
.lattice_set(lattice
)
20 detector
= Hkl
.Detector
.factory_new(Hkl
.DetectorType(0))
22 factory
= Hkl
.factories()['K6C']
23 geometry
= factory
.create_new_geometry()
24 axes_names
= geometry
.axes_names_get()
26 # set the initial position
27 geometry
.axes_values_set([0, 120, 0, -90, 0, 60], Hkl
.UnitEnum
.USER
)
29 # get all engines for a given configuration
30 engines
= factory
.create_new_engine_list()
32 # prepare the engines to work with the related geometry, detector and
34 engines
.init(geometry
, detector
, sample
)
36 #[0, 0, 1] -> [0, 1, 1]
38 h
= numpy
.linspace(0, 0, n
+ 1)
39 k
= numpy
.linspace(0, 1, n
+ 1)
40 l
= numpy
.linspace(1, 1, n
+ 1)
43 hkl
= engines
.engine_get_by_name("hkl")
44 pseudo_axes_names
= ["h", "k", "l"]
46 # compute the trajectory
48 for idx
, hh
, kk
, ll
in zip(range(n
), h
, k
, l
):
50 solutions
= hkl
.pseudo_axes_values_set([hh
, kk
, ll
],
52 first_solution
= solutions
.items()[0]
53 # if no exception raised we have at least one solution
54 # move the diffractometer to the solution
55 engines
.select_solution(first_solution
)
56 motors_positions
.append(geometry
.axes_values_get(Hkl
.UnitEnum
.USER
))
57 except GLib
.GError
, err
:
61 plt
.title("motors trajectory (1st solution)")
62 # reorder the motors_positions for the plot
63 motors_positions
= numpy
.array(motors_positions
).T
64 for y
, name
in zip(motors_positions
, axes_names
):
65 plt
.plot(y
, 'o-', label
=name
)
68 plt
.xlabel("trajectory point index")
69 plt
.ylabel("motor position (Degree)")
72 plt
.title("hkl trajectory")
73 hkl_positions
= numpy
.array([h
, k
, l
])
74 for y
, name
in zip(hkl_positions
, pseudo_axes_names
):
75 plt
.plot(y
, 'o-', label
=name
)
78 plt
.xlabel("trajectory point index")
79 plt
.ylabel("pseudo motor position")