From ae59265ef749091b2424699e5a6501d1bcd16159 Mon Sep 17 00:00:00 2001 From: Mohacsi Istvan Date: Tue, 29 Nov 2022 14:40:08 +0100 Subject: [PATCH 1/6] Two solutions for combined PVs --- ophyd_devices/epics/devices/specMotors.py | 105 ++++++++++++++++++++-- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/ophyd_devices/epics/devices/specMotors.py b/ophyd_devices/epics/devices/specMotors.py index b2d54ef..4b75e1f 100644 --- a/ophyd_devices/epics/devices/specMotors.py +++ b/ophyd_devices/epics/devices/specMotors.py @@ -8,6 +8,7 @@ IMPORTANT: Virtual monochromator axes should be implemented already in EPICS!!! """ import numpy as np +import time from math import isclose, tan, atan, sqrt, sin, asin from ophyd import ( EpicsSignal, @@ -18,6 +19,7 @@ from ophyd import ( PVPositioner, Device, Component, + DynamicDeviceComponent, Kind, ) from ophyd.pseudopos import pseudo_position_argument, real_position_argument @@ -95,7 +97,8 @@ class PmDetectorRotation(PseudoPositioner): class GirderMotorX1(PVPositioner): - """Girder X translation pseudo motor""" + """Girder X translation pseudo motor + """ setpoint = Component(EpicsSignal, ":X_SET", name="sp") readback = Component(EpicsSignalRO, ":X1", name="rbv") @@ -103,7 +106,8 @@ class GirderMotorX1(PVPositioner): class GirderMotorY1(PVPositioner): - """Girder Y translation pseudo motor""" + """Girder Y translation pseudo motor + """ setpoint = Component(EpicsSignal, ":Y_SET", name="sp") readback = Component(EpicsSignalRO, ":Y1", name="rbv") @@ -111,7 +115,8 @@ class GirderMotorY1(PVPositioner): class GirderMotorYAW(PVPositioner): - """Girder YAW pseudo motor""" + """Girder YAW pseudo motor + """ setpoint = Component(EpicsSignal, ":YAW_SET", name="sp") readback = Component(EpicsSignalRO, ":YAW1", name="rbv") @@ -119,7 +124,8 @@ class GirderMotorYAW(PVPositioner): class GirderMotorROLL(PVPositioner): - """Girder ROLL pseudo motor""" + """Girder ROLL pseudo motor + """ setpoint = Component(EpicsSignal, ":ROLL_SET", name="sp") readback = Component(EpicsSignalRO, ":ROLL1", name="rbv") @@ -127,7 +133,8 @@ class GirderMotorROLL(PVPositioner): class GirderMotorPITCH(PVPositioner): - """Girder YAW pseudo motor""" + """Girder YAW pseudo motor + """ setpoint = Component(EpicsSignal, ":PITCH_SET", name="sp") readback = Component(EpicsSignalRO, ":PITCH1", name="rbv") @@ -135,7 +142,7 @@ class GirderMotorPITCH(PVPositioner): class VirtualEpicsSignalRO(EpicsSignalRO): - """This is a test class to create derives signals from one or + """This is a test class to create derives signals from one or multiple original signals... """ @@ -154,7 +161,8 @@ class VirtualEpicsSignalRO(EpicsSignalRO): class MonoTheta1(VirtualEpicsSignalRO): - """Converts the pusher motor position to theta angle""" + """Converts the pusher motor position to theta angle + """ _mono_a0_enc_scale1 = -1.0 _mono_a1_lever_length1 = 206.706 @@ -170,7 +178,8 @@ class MonoTheta1(VirtualEpicsSignalRO): class MonoTheta2(VirtualEpicsSignalRO): - """Converts the pusher motor position to theta angle""" + """Converts the pusher motor position to theta angle + """ _mono_a3_enc_offs2 = -19.7072 _mono_a2_pusher_offs2 = 5.93905 @@ -186,7 +195,8 @@ class MonoTheta2(VirtualEpicsSignalRO): class EnergyKev(VirtualEpicsSignalRO): - """Converts the pusher motor position to energy in keV""" + """Converts the pusher motor position to energy in keV + """ _mono_a3_enc_offs2 = -19.7072 _mono_a2_pusher_offs2 = 5.93905 @@ -202,3 +212,80 @@ class EnergyKev(VirtualEpicsSignalRO): ) E_keV = -self._mono_hce / self._mono_2d2 / sin(theta2_deg / 180.0 * 3.14152) return E_keV + +class CombinedEpicsSignalRO(EpicsSignalRO): + """This is a test class to create derives signals from one or + multiple original signals... + """ + def __init__(self, *args, **kwargs): + if "pvs" in kwargs: + self._private_signals = [] + for key in kwargs["pvs"]: + self.__dict__[key] = EpicsSignalRO(kwargs["pvs"][key], auto_monitor=True) + self._private_signals.append(key) + del kwargs["pvs"] + super().__init__(*args, **kwargs) + def wait_for_connection(self, *args, **kwargs): + for key in self._private_signals: + print(key) + self.__dict__[key].wait_for_connection() + def calc(self, vals: list): + return vals + def get(self, *args, **kwargs): + raw = [self.__dict__[key].value for key in self._private_signals] + print(raw) + return self.calc(raw) + +class SumPvs(CombinedEpicsSignalRO): + """Adds up four current signals""" + def calc(self, vals): + total = 0 + for vv in vals: + total += vv + return total + + +class Bpm4i(Device): + SUB_VALUE = "value" + _default_sub = SUB_VALUE + + ch1 = Component(EpicsSignalRO, "S2", auto_monitor=True, kind=Kind.omitted, name="ch1") + ch2 = Component(EpicsSignalRO, "S3", auto_monitor=True, kind=Kind.omitted, name="ch2") + ch3 = Component(EpicsSignalRO, "S4", auto_monitor=True, kind=Kind.omitted, name="ch3") + ch4 = Component(EpicsSignalRO, "S5", auto_monitor=True, kind=Kind.omitted, name="ch4") + + def __init__(self, prefix="", *, name, **kwargs): + super().__init__(prefix, name=name, **kwargs) + self.ch1.subscribe(self._emit_value) + + def _emit_value(self, **kwargs): + timestamp = kwargs.pop("timestamp", time.time()) + self.wait_for_connection() + self._run_subs(sub_type=self.SUB_VALUE, timestamp=timestamp, obj=self) + + def get(self, *args, **kwargs): + return self.ch1.get() + self.ch2.get() + self.ch3.get() + self.ch4.get() + + def read(self, *args, **kwargs): + return {self.name: {'value': self.get(), 'timestamp': time.time()}} + + + + + + + +if __name__ == "__main__": + #dut = SumPvs("X12SA-OP1-SCALER.S2", pvs={"q1": "X12SA-OP1-SCALER.S2", "q2": "X12SA-OP1-SCALER.S3", "q3": "X12SA-OP1-SCALER.S4", "q4": "X12SA-OP1-SCALER.S5"}, name="sum_all") + #dut.wait_for_connection() + #print(dut.read()) + dut = Bpm4i("X12SA-OP1-SCALER.", name="bpm4i") + dut.wait_for_connection() + print(dut.read()) + + + + + + + From e044d7f8abe9031fce3a5474dd8684dfcecd26f3 Mon Sep 17 00:00:00 2001 From: Mohacsi Istvan Date: Tue, 29 Nov 2022 14:47:09 +0100 Subject: [PATCH 2/6] Older blacking --- ophyd_devices/epics/devices/specMotors.py | 55 +++++++++-------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/ophyd_devices/epics/devices/specMotors.py b/ophyd_devices/epics/devices/specMotors.py index 4b75e1f..a47e065 100644 --- a/ophyd_devices/epics/devices/specMotors.py +++ b/ophyd_devices/epics/devices/specMotors.py @@ -97,8 +97,7 @@ class PmDetectorRotation(PseudoPositioner): class GirderMotorX1(PVPositioner): - """Girder X translation pseudo motor - """ + """Girder X translation pseudo motor""" setpoint = Component(EpicsSignal, ":X_SET", name="sp") readback = Component(EpicsSignalRO, ":X1", name="rbv") @@ -106,8 +105,7 @@ class GirderMotorX1(PVPositioner): class GirderMotorY1(PVPositioner): - """Girder Y translation pseudo motor - """ + """Girder Y translation pseudo motor""" setpoint = Component(EpicsSignal, ":Y_SET", name="sp") readback = Component(EpicsSignalRO, ":Y1", name="rbv") @@ -115,8 +113,7 @@ class GirderMotorY1(PVPositioner): class GirderMotorYAW(PVPositioner): - """Girder YAW pseudo motor - """ + """Girder YAW pseudo motor""" setpoint = Component(EpicsSignal, ":YAW_SET", name="sp") readback = Component(EpicsSignalRO, ":YAW1", name="rbv") @@ -124,8 +121,7 @@ class GirderMotorYAW(PVPositioner): class GirderMotorROLL(PVPositioner): - """Girder ROLL pseudo motor - """ + """Girder ROLL pseudo motor""" setpoint = Component(EpicsSignal, ":ROLL_SET", name="sp") readback = Component(EpicsSignalRO, ":ROLL1", name="rbv") @@ -133,8 +129,7 @@ class GirderMotorROLL(PVPositioner): class GirderMotorPITCH(PVPositioner): - """Girder YAW pseudo motor - """ + """Girder YAW pseudo motor""" setpoint = Component(EpicsSignal, ":PITCH_SET", name="sp") readback = Component(EpicsSignalRO, ":PITCH1", name="rbv") @@ -142,7 +137,7 @@ class GirderMotorPITCH(PVPositioner): class VirtualEpicsSignalRO(EpicsSignalRO): - """This is a test class to create derives signals from one or + """This is a test class to create derives signals from one or multiple original signals... """ @@ -161,8 +156,7 @@ class VirtualEpicsSignalRO(EpicsSignalRO): class MonoTheta1(VirtualEpicsSignalRO): - """Converts the pusher motor position to theta angle - """ + """Converts the pusher motor position to theta angle""" _mono_a0_enc_scale1 = -1.0 _mono_a1_lever_length1 = 206.706 @@ -178,8 +172,7 @@ class MonoTheta1(VirtualEpicsSignalRO): class MonoTheta2(VirtualEpicsSignalRO): - """Converts the pusher motor position to theta angle - """ + """Converts the pusher motor position to theta angle""" _mono_a3_enc_offs2 = -19.7072 _mono_a2_pusher_offs2 = 5.93905 @@ -195,8 +188,7 @@ class MonoTheta2(VirtualEpicsSignalRO): class EnergyKev(VirtualEpicsSignalRO): - """Converts the pusher motor position to energy in keV - """ + """Converts the pusher motor position to energy in keV""" _mono_a3_enc_offs2 = -19.7072 _mono_a2_pusher_offs2 = 5.93905 @@ -213,10 +205,12 @@ class EnergyKev(VirtualEpicsSignalRO): E_keV = -self._mono_hce / self._mono_2d2 / sin(theta2_deg / 180.0 * 3.14152) return E_keV + class CombinedEpicsSignalRO(EpicsSignalRO): """This is a test class to create derives signals from one or multiple original signals... """ + def __init__(self, *args, **kwargs): if "pvs" in kwargs: self._private_signals = [] @@ -225,19 +219,24 @@ class CombinedEpicsSignalRO(EpicsSignalRO): self._private_signals.append(key) del kwargs["pvs"] super().__init__(*args, **kwargs) + def wait_for_connection(self, *args, **kwargs): for key in self._private_signals: print(key) self.__dict__[key].wait_for_connection() + def calc(self, vals: list): return vals + def get(self, *args, **kwargs): raw = [self.__dict__[key].value for key in self._private_signals] print(raw) return self.calc(raw) - + + class SumPvs(CombinedEpicsSignalRO): """Adds up four current signals""" + def calc(self, vals): total = 0 for vv in vals: @@ -267,25 +266,13 @@ class Bpm4i(Device): return self.ch1.get() + self.ch2.get() + self.ch3.get() + self.ch4.get() def read(self, *args, **kwargs): - return {self.name: {'value': self.get(), 'timestamp': time.time()}} - - - - - + return {self.name: {"value": self.get(), "timestamp": time.time()}} if __name__ == "__main__": - #dut = SumPvs("X12SA-OP1-SCALER.S2", pvs={"q1": "X12SA-OP1-SCALER.S2", "q2": "X12SA-OP1-SCALER.S3", "q3": "X12SA-OP1-SCALER.S4", "q4": "X12SA-OP1-SCALER.S5"}, name="sum_all") - #dut.wait_for_connection() - #print(dut.read()) + # dut = SumPvs("X12SA-OP1-SCALER.S2", pvs={"q1": "X12SA-OP1-SCALER.S2", "q2": "X12SA-OP1-SCALER.S3", "q3": "X12SA-OP1-SCALER.S4", "q4": "X12SA-OP1-SCALER.S5"}, name="sum_all") + # dut.wait_for_connection() + # print(dut.read()) dut = Bpm4i("X12SA-OP1-SCALER.", name="bpm4i") dut.wait_for_connection() print(dut.read()) - - - - - - - From 3e5c951a14f628eda439f667311513988e7c787a Mon Sep 17 00:00:00 2001 From: Mohacsi Istvan Date: Tue, 29 Nov 2022 17:00:56 +0100 Subject: [PATCH 3/6] With a simple Signal --- ophyd_devices/epics/devices/specMotors.py | 61 +++++------------------ 1 file changed, 13 insertions(+), 48 deletions(-) diff --git a/ophyd_devices/epics/devices/specMotors.py b/ophyd_devices/epics/devices/specMotors.py index a47e065..696e119 100644 --- a/ophyd_devices/epics/devices/specMotors.py +++ b/ophyd_devices/epics/devices/specMotors.py @@ -17,7 +17,7 @@ from ophyd import ( PseudoPositioner, PseudoSingle, PVPositioner, - Device, + Device, Signal, Component, DynamicDeviceComponent, Kind, @@ -206,41 +206,19 @@ class EnergyKev(VirtualEpicsSignalRO): return E_keV -class CombinedEpicsSignalRO(EpicsSignalRO): - """This is a test class to create derives signals from one or - multiple original signals... - """ - +class CurrentSum(Signal): + """Adds up four current signals from the parent""" def __init__(self, *args, **kwargs): - if "pvs" in kwargs: - self._private_signals = [] - for key in kwargs["pvs"]: - self.__dict__[key] = EpicsSignalRO(kwargs["pvs"][key], auto_monitor=True) - self._private_signals.append(key) - del kwargs["pvs"] super().__init__(*args, **kwargs) + self.parent.ch1.subscribe(self._emit_value) - def wait_for_connection(self, *args, **kwargs): - for key in self._private_signals: - print(key) - self.__dict__[key].wait_for_connection() - - def calc(self, vals: list): - return vals + def _emit_value(self, **kwargs): + timestamp = kwargs.pop("timestamp", time.time()) + self.wait_for_connection() + self._run_subs(sub_type='value', timestamp=timestamp, obj=self) def get(self, *args, **kwargs): - raw = [self.__dict__[key].value for key in self._private_signals] - print(raw) - return self.calc(raw) - - -class SumPvs(CombinedEpicsSignalRO): - """Adds up four current signals""" - - def calc(self, vals): - total = 0 - for vv in vals: - total += vv + total = self.parent.ch1.get() + self.parent.ch2.get() + self.parent.ch3.get() + self.parent.ch4.get() return total @@ -252,27 +230,14 @@ class Bpm4i(Device): ch2 = Component(EpicsSignalRO, "S3", auto_monitor=True, kind=Kind.omitted, name="ch2") ch3 = Component(EpicsSignalRO, "S4", auto_monitor=True, kind=Kind.omitted, name="ch3") ch4 = Component(EpicsSignalRO, "S5", auto_monitor=True, kind=Kind.omitted, name="ch4") + sum = Component(CurrentSum, kind=Kind.hinted, name="sum", ) - def __init__(self, prefix="", *, name, **kwargs): - super().__init__(prefix, name=name, **kwargs) - self.ch1.subscribe(self._emit_value) - def _emit_value(self, **kwargs): - timestamp = kwargs.pop("timestamp", time.time()) - self.wait_for_connection() - self._run_subs(sub_type=self.SUB_VALUE, timestamp=timestamp, obj=self) - - def get(self, *args, **kwargs): - return self.ch1.get() + self.ch2.get() + self.ch3.get() + self.ch4.get() - - def read(self, *args, **kwargs): - return {self.name: {"value": self.get(), "timestamp": time.time()}} if __name__ == "__main__": - # dut = SumPvs("X12SA-OP1-SCALER.S2", pvs={"q1": "X12SA-OP1-SCALER.S2", "q2": "X12SA-OP1-SCALER.S3", "q3": "X12SA-OP1-SCALER.S4", "q4": "X12SA-OP1-SCALER.S5"}, name="sum_all") - # dut.wait_for_connection() - # print(dut.read()) - dut = Bpm4i("X12SA-OP1-SCALER.", name="bpm4i") + dut = Bpm4i("X12SA-OP1-SCALER.", name="bpm4") dut.wait_for_connection() print(dut.read()) + print(dut.describe()) + From f3a14ab8b442f501d76eb9937e96407e57d3db57 Mon Sep 17 00:00:00 2001 From: Mohacsi Istvan Date: Tue, 29 Nov 2022 17:03:42 +0100 Subject: [PATCH 4/6] Blacked on 3.10 --- ophyd_devices/epics/devices/SpmBase.py | 10 +++++----- ophyd_devices/epics/devices/XbpmBase.py | 10 +++++----- ophyd_devices/epics/devices/specMotors.py | 18 +++++++++++------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/ophyd_devices/epics/devices/SpmBase.py b/ophyd_devices/epics/devices/SpmBase.py index f996bd3..be5a1d6 100644 --- a/ophyd_devices/epics/devices/SpmBase.py +++ b/ophyd_devices/epics/devices/SpmBase.py @@ -57,7 +57,7 @@ class SpmSim(SpmBase): # Define normalized 2D gaussian def gaus2d(x=0, y=0, mx=0, my=0, sx=1, sy=1): return np.exp( - -((x - mx) ** 2.0 / (2.0 * sx**2.0) + (y - my) ** 2.0 / (2.0 * sy**2.0)) + -((x - mx) ** 2.0 / (2.0 * sx ** 2.0) + (y - my) ** 2.0 / (2.0 * sy ** 2.0)) ) # Generator for dynamic values @@ -73,10 +73,10 @@ class SpmSim(SpmBase): beam = self._simFrame() total = np.sum(beam) - np.sum(beam[24:48, :]) rnge = np.floor(np.log10(total) - 0.0) - s1 = np.sum(beam[0:16, :]) / 10**rnge - s2 = np.sum(beam[16:24, :]) / 10**rnge - s3 = np.sum(beam[40:48, :]) / 10**rnge - s4 = np.sum(beam[48:64, :]) / 10**rnge + s1 = np.sum(beam[0:16, :]) / 10 ** rnge + s2 = np.sum(beam[16:24, :]) / 10 ** rnge + s3 = np.sum(beam[40:48, :]) / 10 ** rnge + s4 = np.sum(beam[48:64, :]) / 10 ** rnge self.s1w.set(s1).wait() self.s2w.set(s2).wait() diff --git a/ophyd_devices/epics/devices/XbpmBase.py b/ophyd_devices/epics/devices/XbpmBase.py index 9035412..8a2a853 100644 --- a/ophyd_devices/epics/devices/XbpmBase.py +++ b/ophyd_devices/epics/devices/XbpmBase.py @@ -87,7 +87,7 @@ class XbpmSim(XbpmBase): # define normalized 2D gaussian def gaus2d(x=0, y=0, mx=0, my=0, sx=1, sy=1): return np.exp( - -((x - mx) ** 2.0 / (2.0 * sx**2.0) + (y - my) ** 2.0 / (2.0 * sy**2.0)) + -((x - mx) ** 2.0 / (2.0 * sx ** 2.0) + (y - my) ** 2.0 / (2.0 * sy ** 2.0)) ) # Generator for dynamic values @@ -103,10 +103,10 @@ class XbpmSim(XbpmBase): beam = self._simFrame() total = np.sum(beam) rnge = np.floor(np.log10(total) - 0.0) - s1 = np.sum(beam[32:64, 32:64]) / 10**rnge - s2 = np.sum(beam[0:32, 32:64]) / 10**rnge - s3 = np.sum(beam[32:64, 0:32]) / 10**rnge - s4 = np.sum(beam[0:32, 0:32]) / 10**rnge + s1 = np.sum(beam[32:64, 32:64]) / 10 ** rnge + s2 = np.sum(beam[0:32, 32:64]) / 10 ** rnge + s3 = np.sum(beam[32:64, 0:32]) / 10 ** rnge + s4 = np.sum(beam[0:32, 0:32]) / 10 ** rnge self.s1w.set(s1).wait() self.s2w.set(s2).wait() diff --git a/ophyd_devices/epics/devices/specMotors.py b/ophyd_devices/epics/devices/specMotors.py index 696e119..04e83b6 100644 --- a/ophyd_devices/epics/devices/specMotors.py +++ b/ophyd_devices/epics/devices/specMotors.py @@ -17,7 +17,8 @@ from ophyd import ( PseudoPositioner, PseudoSingle, PVPositioner, - Device, Signal, + Device, + Signal, Component, DynamicDeviceComponent, Kind, @@ -208,6 +209,7 @@ class EnergyKev(VirtualEpicsSignalRO): class CurrentSum(Signal): """Adds up four current signals from the parent""" + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.parent.ch1.subscribe(self._emit_value) @@ -215,10 +217,15 @@ class CurrentSum(Signal): def _emit_value(self, **kwargs): timestamp = kwargs.pop("timestamp", time.time()) self.wait_for_connection() - self._run_subs(sub_type='value', timestamp=timestamp, obj=self) + self._run_subs(sub_type="value", timestamp=timestamp, obj=self) def get(self, *args, **kwargs): - total = self.parent.ch1.get() + self.parent.ch2.get() + self.parent.ch3.get() + self.parent.ch4.get() + total = ( + self.parent.ch1.get() + + self.parent.ch2.get() + + self.parent.ch3.get() + + self.parent.ch4.get() + ) return total @@ -230,9 +237,7 @@ class Bpm4i(Device): ch2 = Component(EpicsSignalRO, "S3", auto_monitor=True, kind=Kind.omitted, name="ch2") ch3 = Component(EpicsSignalRO, "S4", auto_monitor=True, kind=Kind.omitted, name="ch3") ch4 = Component(EpicsSignalRO, "S5", auto_monitor=True, kind=Kind.omitted, name="ch4") - sum = Component(CurrentSum, kind=Kind.hinted, name="sum", ) - - + sum = Component(CurrentSum, kind=Kind.hinted, name="sum",) if __name__ == "__main__": @@ -240,4 +245,3 @@ if __name__ == "__main__": dut.wait_for_connection() print(dut.read()) print(dut.describe()) - From 60708d54cbd5d8c236415c9f1d93f203eb037bfe Mon Sep 17 00:00:00 2001 From: Mohacsi Istvan Date: Tue, 29 Nov 2022 17:10:31 +0100 Subject: [PATCH 5/6] Added to ini files --- ophyd_devices/epics/__init__.py | 1 + ophyd_devices/epics/devices/SpmBase.py | 10 +++++----- ophyd_devices/epics/devices/XbpmBase.py | 10 +++++----- ophyd_devices/epics/devices/__init__.py | 14 +++++++------- ophyd_devices/epics/devices/specMotors.py | 14 +++++--------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/ophyd_devices/epics/__init__.py b/ophyd_devices/epics/__init__.py index b91a7eb..b422915 100644 --- a/ophyd_devices/epics/__init__.py +++ b/ophyd_devices/epics/__init__.py @@ -7,6 +7,7 @@ from .devices.DelayGeneratorDG645 import DelayGeneratorDG645 from .devices.InsertionDevice import InsertionDevice from .devices.slits import SlitH, SlitV from .devices.specMotors import ( + Bpm4i, EnergyKev, GirderMotorPITCH, GirderMotorROLL, diff --git a/ophyd_devices/epics/devices/SpmBase.py b/ophyd_devices/epics/devices/SpmBase.py index be5a1d6..f996bd3 100644 --- a/ophyd_devices/epics/devices/SpmBase.py +++ b/ophyd_devices/epics/devices/SpmBase.py @@ -57,7 +57,7 @@ class SpmSim(SpmBase): # Define normalized 2D gaussian def gaus2d(x=0, y=0, mx=0, my=0, sx=1, sy=1): return np.exp( - -((x - mx) ** 2.0 / (2.0 * sx ** 2.0) + (y - my) ** 2.0 / (2.0 * sy ** 2.0)) + -((x - mx) ** 2.0 / (2.0 * sx**2.0) + (y - my) ** 2.0 / (2.0 * sy**2.0)) ) # Generator for dynamic values @@ -73,10 +73,10 @@ class SpmSim(SpmBase): beam = self._simFrame() total = np.sum(beam) - np.sum(beam[24:48, :]) rnge = np.floor(np.log10(total) - 0.0) - s1 = np.sum(beam[0:16, :]) / 10 ** rnge - s2 = np.sum(beam[16:24, :]) / 10 ** rnge - s3 = np.sum(beam[40:48, :]) / 10 ** rnge - s4 = np.sum(beam[48:64, :]) / 10 ** rnge + s1 = np.sum(beam[0:16, :]) / 10**rnge + s2 = np.sum(beam[16:24, :]) / 10**rnge + s3 = np.sum(beam[40:48, :]) / 10**rnge + s4 = np.sum(beam[48:64, :]) / 10**rnge self.s1w.set(s1).wait() self.s2w.set(s2).wait() diff --git a/ophyd_devices/epics/devices/XbpmBase.py b/ophyd_devices/epics/devices/XbpmBase.py index 8a2a853..9035412 100644 --- a/ophyd_devices/epics/devices/XbpmBase.py +++ b/ophyd_devices/epics/devices/XbpmBase.py @@ -87,7 +87,7 @@ class XbpmSim(XbpmBase): # define normalized 2D gaussian def gaus2d(x=0, y=0, mx=0, my=0, sx=1, sy=1): return np.exp( - -((x - mx) ** 2.0 / (2.0 * sx ** 2.0) + (y - my) ** 2.0 / (2.0 * sy ** 2.0)) + -((x - mx) ** 2.0 / (2.0 * sx**2.0) + (y - my) ** 2.0 / (2.0 * sy**2.0)) ) # Generator for dynamic values @@ -103,10 +103,10 @@ class XbpmSim(XbpmBase): beam = self._simFrame() total = np.sum(beam) rnge = np.floor(np.log10(total) - 0.0) - s1 = np.sum(beam[32:64, 32:64]) / 10 ** rnge - s2 = np.sum(beam[0:32, 32:64]) / 10 ** rnge - s3 = np.sum(beam[32:64, 0:32]) / 10 ** rnge - s4 = np.sum(beam[0:32, 0:32]) / 10 ** rnge + s1 = np.sum(beam[32:64, 32:64]) / 10**rnge + s2 = np.sum(beam[0:32, 32:64]) / 10**rnge + s3 = np.sum(beam[32:64, 0:32]) / 10**rnge + s4 = np.sum(beam[0:32, 0:32]) / 10**rnge self.s1w.set(s1).wait() self.s2w.set(s2).wait() diff --git a/ophyd_devices/epics/devices/__init__.py b/ophyd_devices/epics/devices/__init__.py index f1a0cac..534071f 100644 --- a/ophyd_devices/epics/devices/__init__.py +++ b/ophyd_devices/epics/devices/__init__.py @@ -3,20 +3,20 @@ from .slits import SlitH, SlitV from .XbpmBase import XbpmBase, XbpmCsaxsOp from .SpmBase import SpmBase from .InsertionDevice import InsertionDevice -from .specMotors import ( - PmMonoBender, - PmDetectorRotation, +from .devices.specMotors import ( + Bpm4i, + EnergyKev, + GirderMotorPITCH, + GirderMotorROLL, GirderMotorX1, GirderMotorY1, - GirderMotorROLL, GirderMotorYAW, - GirderMotorPITCH, MonoTheta1, MonoTheta2, - EnergyKev, + PmDetectorRotation, + PmMonoBender, ) - # Standard ophyd classes from ophyd import EpicsSignal, EpicsSignalRO, EpicsMotor from ophyd.sim import SynAxis, SynSignal, SynPeriodicSignal diff --git a/ophyd_devices/epics/devices/specMotors.py b/ophyd_devices/epics/devices/specMotors.py index 04e83b6..3bbd8fc 100644 --- a/ophyd_devices/epics/devices/specMotors.py +++ b/ophyd_devices/epics/devices/specMotors.py @@ -20,11 +20,9 @@ from ophyd import ( Device, Signal, Component, - DynamicDeviceComponent, Kind, ) from ophyd.pseudopos import pseudo_position_argument, real_position_argument -from ophyd.utils.epics_pvs import data_type class PmMonoBender(PseudoPositioner): @@ -149,12 +147,6 @@ class VirtualEpicsSignalRO(EpicsSignalRO): raw = super().get(*args, **kwargs) return self.calc(raw) - # def describe(self): - # val = self.get() - # d = super().describe() - # d[self.name]["dtype"] = data_type(val) - # return d - class MonoTheta1(VirtualEpicsSignalRO): """Converts the pusher motor position to theta angle""" @@ -237,7 +229,11 @@ class Bpm4i(Device): ch2 = Component(EpicsSignalRO, "S3", auto_monitor=True, kind=Kind.omitted, name="ch2") ch3 = Component(EpicsSignalRO, "S4", auto_monitor=True, kind=Kind.omitted, name="ch3") ch4 = Component(EpicsSignalRO, "S5", auto_monitor=True, kind=Kind.omitted, name="ch4") - sum = Component(CurrentSum, kind=Kind.hinted, name="sum",) + sum = Component( + CurrentSum, + kind=Kind.hinted, + name="sum", + ) if __name__ == "__main__": From 5ecdf39457dc612f733d33d8f1322a2f4a4b0263 Mon Sep 17 00:00:00 2001 From: Mohacsi Istvan Date: Tue, 29 Nov 2022 17:12:07 +0100 Subject: [PATCH 6/6] Added to ini files --- ophyd_devices/epics/devices/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ophyd_devices/epics/devices/__init__.py b/ophyd_devices/epics/devices/__init__.py index 534071f..c65ce0b 100644 --- a/ophyd_devices/epics/devices/__init__.py +++ b/ophyd_devices/epics/devices/__init__.py @@ -3,7 +3,7 @@ from .slits import SlitH, SlitV from .XbpmBase import XbpmBase, XbpmCsaxsOp from .SpmBase import SpmBase from .InsertionDevice import InsertionDevice -from .devices.specMotors import ( +from .specMotors import ( Bpm4i, EnergyKev, GirderMotorPITCH,