From 3c36a5685a695f0c0542ec43ea2bb559982f42ff Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 16 Apr 2022 11:43:07 +0200 Subject: [PATCH] added wavelength wrapper adjustable --- qspace.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/qspace.py b/qspace.py index 84721e2..e1c33b2 100644 --- a/qspace.py +++ b/qspace.py @@ -167,6 +167,30 @@ class QSpace1D(Adjustable): +h = 6.62607015e-34 # J s +c = 299792458 # m / s +e = 1.60217663e-19 # C +f = h * c / e * 1e-3 * 1e9 # E [keV] = f / lambda [nm] + + +class Wavelength(Adjustable): + + def __init__(self, energy): + self.energy = energy + assert self.energy.units == "keV" # otherwise conversion is wrong + super().__init__(energy.ID + "_WL", name=energy.name + " as Wavelength", units="nm") + + def get_current_value(self): + E = self.energy.get_current_value() + return f / E + + def set_target_value(self, value): + E = f / value + return self.energy.set_target_value(E) + + def is_moving(self): + return self.energy.is_moving() + # these point to the different motors @@ -176,7 +200,7 @@ phi = Motor("SATES30-RIXS:MOT_SRX.VAL") nu = Motor("SATES30-RIXS:MOT_DRY.VAL") # and this to the machine wavelength (maybe this needs to be calculated from the energy? then we should add a Wavelength wrapper...) -wl = PVAdjustable("MACHINE:WAVELENGTH") +wl = Wavelength(PVAdjustable("MACHINE:ENERGY")) # put it all together: q = QSpace3D("SOMETHING:Q", mu, chi, phi, nu, wl)