From 35dc0c3b97014eb7aa487c916f71039ac3797f69 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Fri, 27 Aug 2021 16:44:38 +0200 Subject: [PATCH] made active undulators and CHIC fudge offset settable from the constructor --- devices/undulator.py | 38 +++++++++++++++++++++++++------------- maloja.py | 9 ++++++++- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/devices/undulator.py b/devices/undulator.py index 4690a5e..cfef679 100644 --- a/devices/undulator.py +++ b/devices/undulator.py @@ -2,27 +2,37 @@ from time import sleep import numpy as np from epics import PV +from logzero import logger as log + from slic.core.adjustable import Adjustable from slic.core.adjustable import PVAdjustable from slic.core.scanner.scanbackend import wait_for_all #, stop_all -# 14 is the CHIC -n_unds = [6, 7, 8, 9, 10, 11, 12, 13, - 15, 16, 17, 18, 19, 20, 21, 22 -] - -und_names = [f"SATUN{n:02}-UIND030" for n in n_unds] -und_name_cal = "SATUN13-UIND030" - +UND_NAME_FMT = "SATUN{:02}-UIND030" +N_UND_CHIC = 14 class Undulators(Adjustable): - def __init__(self, scaled=True, ID="ATHOS_UNDULATORS", name="Athos Undulators", units="eV"): + def __init__(self, n_unds, n_und_cal, chic_fudge_offset=0, scaled=True, ID="ATHOS_UNDULATORS", name="Athos Undulators", units="eV"): super().__init__(ID, name=name, units=units) + + self.n_unds = n_unds = list(n_unds) + self.n_und_cal = n_und_cal + + if n_und_cal not in n_unds: + raise ValueError(f"the reference undulator ({n_und_cal}) is not in the list of active undulators: {n_unds}") + + if N_UND_CHIC in n_unds: + log.warning(f"the CHIC ({N_UND_CHIC}) is in the list of active undulators: {n_unds}, and will be ignored/removed") + n_unds.remove(N_UND_CHIC) + + self.und_names = und_names = [UND_NAME_FMT.format(n) for n in n_unds] + self.und_name_cal = und_name_cal = UND_NAME_FMT.format(n_und_cal) + self.adjs = {name: Undulator(name) for name in und_names} - self.chic = CHIC(name, units) + self.chic = CHIC(chic_fudge_offset, name, units) self.scaled = scaled @@ -71,7 +81,8 @@ class Undulators(Adjustable): def get_current_value(self): - a = self.adjs[und_name_cal] + n = self.und_name_cal + a = self.adjs[n] k = a.get_current_value() energy = self.convert.E(k) @@ -155,7 +166,8 @@ class ScalerEK: class CHIC(PVAdjustable): - def __init__(self, name, units): + def __init__(self, fudge_offset, name, units): + self.fudge_offset = fudge_offset name += " CHIC Energy" super().__init__("SATUN-CHIC:PHOTON-ENERGY", name=name) self.pvs.start = PV("SATUN-CHIC:APPLY-DELAY-OFFSET-PHASE") @@ -163,7 +175,7 @@ class CHIC(PVAdjustable): def set_target_value(self, value, hold=False): - fudge_offset = 3 + fudge_offset = self.fudge_offset print("CHIC fudge offset is", fudge_offset) value -= fudge_offset value /= 1000 diff --git a/maloja.py b/maloja.py index 3cb1a82..2552035 100644 --- a/maloja.py +++ b/maloja.py @@ -32,7 +32,14 @@ source_y = Motor("SATES20-MANIP1:MOTOR_1", name="Source manipulator y") source_x = Motor("SATES20-MANIP1:MOTOR_2", name="Source manipulator x") att = Attenuator("SATFE10-OATT064") -und = Undulators(name="z Athos Undulators") + +n_und_cal = 6 +n_unds = [ + 6, 7, 8, 9, 10, 11, 12, 13, # 14 is the CHIC + 15, 16, 17, 18, 19, 20, 21, 22 +] +chic_fudge_offset = 0 +und = Undulators(n_unds, n_und_cal, chic_fudge_offset, name="z Athos Undulators") xota_z_trans = Motor("SATES21-XOTA166:W_Z", name="Table 1: Z coordinated") #xota_hori_z = Motor("SATES21-XOTA166:MOTOR_Z", name="Table 1: Z raw")