Skip to content
Snippets Groups Projects
Commit 0fbf15df authored by Simone Vadilonga's avatar Simone Vadilonga
Browse files

timeout connection None and mca derived signals first test

parent 7c44a986
No related branches found
No related tags found
No related merge requests found
# Workarounds/patches
from ophyd.signal import EpicsSignalBase
EpicsSignalBase.set_defaults(timeout=200)
EpicsSignalBase.set_defaults(connection_timeout= None, timeout=200)
from bessyii_devices.ring import Ring
......@@ -38,12 +38,12 @@ from beamlinetools.devices.mca_old import xMap
# next_injection.wait_for_connection()
# Keithleys
# print('Connecting to Amperometers')
# ks = 'K64851MF102L:'
# kth00 = keithley6485(ks + '12', name='myspot_keithley0', read_attrs=['readback'], labels={'detectors'})
# kth00.wait_for_connection()
# kth01 = keithley6485(ks + '14', name='myspot_keithley1', read_attrs=['readback'], labels={'detectors'})
# kth01.wait_for_connection()
print('Connecting to Amperometers')
ks = 'K64851MF102L:'
kth00 = keithley6485(ks + '12', name='myspot_keithley0', read_attrs=['readback'], labels={'detectors'})
kth00.wait_for_connection()
kth01 = keithley6485(ks + '14', name='myspot_keithley1', read_attrs=['readback'], labels={'detectors'})
kth01.wait_for_connection()
# motors
# print('Connecting to motors')
......@@ -53,10 +53,10 @@ from beamlinetools.devices.mca_old import xMap
# mz.wait_for_connection()
# Monochromator
print('Connecting to DCM')
dcm = DCMmySpot("DCM1OS2L:", name='dcm')
dcm.wait_for_connection()
dcm.p.set_mono_type()
# print('Connecting to DCM')
# dcm = DCMmySpot("DCM1OS2L:", name='dcm')
# dcm.wait_for_connection()
# dcm.p.set_mono_type()
# Apertures
# print('Connecting to Slit3')
......@@ -76,6 +76,8 @@ mca_old.wait_for_connection()
from beamlinetools.devices.mca import MyEpicsMCA
mca= MyEpicsMCA('dxpXMAP:', name="mca")
from beamlinetools.devices.mca import ExafsDet
from beamlinetools.devices.mca import ExafsDet, DivideByArgs
ex_det = ExafsDet(mca.ch1.roi0.count, lt=mca.ch1.lifetime, name="ex_det")
div_det1 = DivideByArgs(mca.ch1.roi0.count, [mca.ch1.lifetime], name="div_det1")
div_det2 = DivideByArgs(mca.ch1.roi0.count, [mca.ch1.lifetime, kth00.readback], name="div_det2")
div_det2l = DivideByArgs(mca.ch1.roi0.count, [mca.ch1.lifetime, kth00.readback], log=True, name="div_det2l")
......@@ -71,7 +71,7 @@ class Channel(Device):
lifetime = Cpt(EpicsSignalRO, '.ELTM', kind='config')
realtime = Cpt(EpicsSignalRO, '.ERTM', kind='config')
deadtime = Cpt(EpicsSignalRO, '.IDTIM', kind='config')
class MyEpicsMCA(Device):
......@@ -158,17 +158,32 @@ class ExafsDet(DerivedSignal):
# 1 signal divided by another one
# 1 signal divided by 2 other signals
# natural log of (1 signal divided by another one)
class ExafsDetBK(DerivedSignal):
def __init__(self, derived_from, *, lt=None,write_access=None, name=None, parent=None, **kwargs):
self.lt = lt
import numpy as np
class DivideByArgs(DerivedSignal):
def __init__(self, derived_from, divisors, log=False, write_access=None, name=None, parent=None, **kwargs):
if divisors.__class__ is not list:
raise ValueError(f"divisors should be a list, while it is a {type(divisors)}")
if len(divisors) == 0:
raise ValueError(f"The divisors list should contain at least one element")
self._divisors = divisors
if log.__class__ is not bool:
raise ValueError(f"log should be a bool, while it is a {type(log)}")
self._log = log
super().__init__(derived_from, write_access=None, name=None, parent=None, **kwargs)
def inverse(self, value):
"""Compute original signal value -> derived signal value"""
value = value/self.lt.get()
divisor = 1
for div in self._divisors:
divisor *= div.get()
value = value / divisor
if self._log:
value = np.log(value)
return value
def forward(self, value):
"""Compute derived signal value -> original signal value"""
return value
\ No newline at end of file
return value
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment