Comments (2)
In #29 (comment), it was shown how to get photon energy from beam line controls. The same steps could be used to get wavelength instead.
Internally, the calc
module stores only the wavelength (angstroms). It converts energy to wavelength when energy is set. Here's the code:
Lines 136 to 152 in 14463c4
example
This user operation sets the energy: fourc.calc.energy = 8.04
(the units are keV). The setter
part sets the internal wavelength fourc.calc._wavelength
by calculating A_KEV/energy
. When the users asks for the current energy, it is recalculated from the internal wavelength (A_KEV/wavelength
).
from hklpy.
It is recommended to get either the energy or wavelength from the beam line controls, but not both. This is always a local customization to the specific instrument so it is not appropriate to add into the code here. (This example could be part of the documentation, however.)
There is already code in place to use an energy ophyd.Signal
(and a default Diffractometer._energy_changed()
method) to set energy and wavelength in the calc
attribute. Override the energy
Signal
with an ophyd.EpicsSignal
and connect to the desired energy PV. An example is provided (from #29 (comment) & #29 (comment)). The example also shows unit conversion (using thepint package) and a Signal
for energy offset (as requested in #25). (If the offset is an EPICS PV, then use EpicsSignal
and the PV instead).
import gi
gi.require_version('Hkl', '5.0')
import hkl.diffract
from ophyd import Component, EpicsSignal, Signal
import pint
class LocalDiffractometer(hkl.diffract.Diffractometer):
# ...
energy = Component(EpicsSignal, "EPICS:diffractometer:energy")
energy_EGU = Component(EpicsSignal, "EPICS:diffractometer:energy.EGU")
energy_update_calc = Component(EpicsSignal, "EPICS:diffractometer:energy_update_hkl")
energy_offset = Component(Signal, value=0)
# ...
def _energy_changed(self, value=None, **kwargs):
'''
Callback indicating that the energy signal was updated
'''
if energy_update_calc.get() in (1, "Yes", "locked", "OK"):
local_energy = value + self.energy_offset.get()
units = self.energy_EGU.get() # get units from EPICS
# units = "eV" # alternative: from control system always gives "eV"
logger.debug(
'{0.name} energy changed: {1} {2}'.format(
self, value, units))
keV = pint.Quantity(local_energy, units).to("keV")
self._calc.energy = keV
self._update_position()
from hklpy.
Related Issues (20)
- BUG: _geom_ not redefined when using select_diffractometer() HOT 2
- BUG: restore(configuration) should push constraints to stack HOT 1
- add a `get_constraints(axis)` function
- BUG: forward() does not give same answer as first solution in forward_solutions_table() HOT 5
- geometry mode updates which axes? HOT 3
- BUG: add_reflections() crashes session when ... HOT 1
- Add properties: axes_r, axes_w, & axes_c
- BUG: 3 tests fail at home, not in GHA HOT 3
- use nbstripout
- Rebuild geometry tables in CI
- BUG: problems with unit test workflow HOT 5
- BUG: KeyError with databroker 2.0.0b31
- Switch linting to ruff
- type annotation in DCReflection class
- BUG: packaging error - "pkgdemo" HOT 5
- 6-circle drawing is mislabeled HOT 3
- Why is Cpt(EpicsMotor) and EpicMotor creating different configuration_attrs? HOT 10
- Make home page easier to use. HOT 5
- Move on from pre-Py3.7 code HOT 1
- (Should) Test and package with Py3.12 now.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hklpy.