From 7d9286aa0d6eb9ddf7d1ae776b5c5a31ea2f51fd Mon Sep 17 00:00:00 2001 From: Roman Mankowsky Date: Thu, 11 Oct 2018 14:26:56 +0200 Subject: [PATCH] real aliases, diffractometer class and more --- eco/aliases/aliases.py | 26 +++++-- eco/aliases/namespaces/bernina.json | 2 +- eco/bernina/bernina.py | 13 ++++ eco/bernina/config.py | 6 +- eco/devices_general/motors.py | 2 +- eco/endstations/bernina_diffractometers.py | 91 ++++++++++++++++++++++ eco/endstations/bernina_xrd_new.py | 32 +++++--- eco/utilities/config.py | 6 ++ eco/xdiagnostics/profile_monitors.py | 6 ++ 9 files changed, 163 insertions(+), 21 deletions(-) create mode 100644 eco/endstations/bernina_diffractometers.py diff --git a/eco/aliases/aliases.py b/eco/aliases/aliases.py index 98582cc..fcac712 100644 --- a/eco/aliases/aliases.py +++ b/eco/aliases/aliases.py @@ -17,7 +17,7 @@ class Alias: ), f"Alias {subalias.alias} exists already!" self.children.append(subalias) - def get_all(self): + def get_all(self,joiner='.'): aa = [] if self.channel: ta = {} @@ -30,11 +30,11 @@ class Alias: for tc in self.children: taa = tc.get_all() for ta in taa: - ta["alias"] = self.alias + ta["alias"] - aa.append(ta) + aa.append({'alias':joiner.join([self.alias,ta['alias']]),'channel':ta['channel'], 'channeltype':ta['channeltype']}) + return aa - def add_children(self, *args): - self.children.append(find_aliases(*args)) +# def add_children(self, *args): +# self.children.append(find_aliases(*args)) def find_aliases(*args): @@ -54,6 +54,7 @@ class Namespace: self._path = path self.name = path.stem self.data = None + self._modified = False def read_file(self): with self._path.open("r") as fp: @@ -86,6 +87,21 @@ class Namespace: json.dump(self.data, fp) self._modified = False + def get_info(self, alias=None, channel=None): + assert alias or channel, "Either search alias or channel needs to be defined!" + assert not(alias and channel), "Only either search alias or channel can be defined" + if alias: + if alias in self.aliases: + return self.data[self.aliases.index(alias)] + else: + return None + if channel: + if channel in self.channels: + return self.data[self.channels.index(channel)] + else: + return None + + class NamespaceCollection: def __init__(self, alias_path=None): diff --git a/eco/aliases/namespaces/bernina.json b/eco/aliases/namespaces/bernina.json index 423c5ad..45152a3 100644 --- a/eco/aliases/namespaces/bernina.json +++ b/eco/aliases/namespaces/bernina.json @@ -1 +1 @@ -[{"alias": null, "channel": null, "channeltype": null}, {"alias": "name", "channel": "id2344221000", "channeltype": "bs"}] \ No newline at end of file +[{"alias": "xrd.xbase.readback", "channel": "SARES21-XRD:MOT_TX.RBV", "channeltype": "CA"}, {"alias": "xrd.xbase.user_offset", "channel": "SARES21-XRD:MOT_TX.OFF", "channeltype": "CA"}, {"alias": "xrd.ybase.readback", "channel": "SARES21-XRD:MOT_TY.RBV", "channeltype": "CA"}, {"alias": "xrd.ybase.user_offset", "channel": "SARES21-XRD:MOT_TY.OFF", "channeltype": "CA"}, {"alias": "xrd.rxbase.readback", "channel": "SARES21-XRD:MOT_RX.RBV", "channeltype": "CA"}, {"alias": "xrd.rxbase.user_offset", "channel": "SARES21-XRD:MOT_RX.OFF", "channeltype": "CA"}, {"alias": "xrd.omega.readback", "channel": "SARES21-XRD:MOT_MY_RYTH.RBV", "channeltype": "CA"}, {"alias": "xrd.omega.user_offset", "channel": "SARES21-XRD:MOT_MY_RYTH.OFF", "channeltype": "CA"}, {"alias": "xrd.gamma.readback", "channel": "SARES21-XRD:MOT_NY_RY2TH.RBV", "channeltype": "CA"}, {"alias": "xrd.gamma.user_offset", "channel": "SARES21-XRD:MOT_NY_RY2TH.OFF", "channeltype": "CA"}, {"alias": "xrd.delta.readback", "channel": "SARES21-XRD:MOT_DT_RX2TH.RBV", "channeltype": "CA"}, {"alias": "xrd.delta.user_offset", "channel": "SARES21-XRD:MOT_DT_RX2TH.OFF", "channeltype": "CA"}, {"alias": "xrd.tdet.readback", "channel": "SARES21-XRD:MOT_D_T.RBV", "channeltype": "CA"}, {"alias": "xrd.tdet.user_offset", "channel": "SARES21-XRD:MOT_D_T.OFF", "channeltype": "CA"}, {"alias": "xrd.tpol.readback", "channel": "SARES21-XRD:MOT_P_T.RBV", "channeltype": "CA"}, {"alias": "xrd.tpol.user_offset", "channel": "SARES21-XRD:MOT_P_T.OFF", "channeltype": "CA"}, {"alias": "xrd.xhl.readback", "channel": "SARES21-XRD:MOT_TBL_TX.RBV", "channeltype": "CA"}, {"alias": "xrd.xhl.user_offset", "channel": "SARES21-XRD:MOT_TBL_TX.OFF", "channeltype": "CA"}, {"alias": "xrd.zhl.readback", "channel": "SARES21-XRD:MOT_TBL_TZ.RBV", "channeltype": "CA"}, {"alias": "xrd.zhl.user_offset", "channel": "SARES21-XRD:MOT_TBL_TZ.OFF", "channeltype": "CA"}, {"alias": "xrd.yhl.readback", "channel": "SARES21-XRD:MOT_TBL_TY.RBV", "channeltype": "CA"}, {"alias": "xrd.yhl.user_offset", "channel": "SARES21-XRD:MOT_TBL_TY.OFF", "channeltype": "CA"}, {"alias": "xrd.rxhl.readback", "channel": "SARES21-XRD:MOT_TBL_RX.RBV", "channeltype": "CA"}, {"alias": "xrd.rxhl.user_offset", "channel": "SARES21-XRD:MOT_TBL_RX.OFF", "channeltype": "CA"}, {"alias": "xrd.teta.readback", "channel": "SARES21-XRD:MOT_HEX_TX.RBV", "channeltype": "CA"}, {"alias": "xrd.teta.user_offset", "channel": "SARES21-XRD:MOT_HEX_TX.OFF", "channeltype": "CA"}, {"alias": "xrd.eta.readback", "channel": "SARES21-XRD:MOT_HEX_RX.RBV", "channeltype": "CA"}, {"alias": "xrd.eta.user_offset", "channel": "SARES21-XRD:MOT_HEX_RX.OFF", "channeltype": "CA"}] diff --git a/eco/bernina/bernina.py b/eco/bernina/bernina.py index 69ad8f4..063976a 100644 --- a/eco/bernina/bernina.py +++ b/eco/bernina/bernina.py @@ -2,8 +2,21 @@ from ..utilities.config import initFromConfigList from epics import PV from .config import components from .. import ecocnf +from ..aliases import NamespaceCollection itglobals = globals() +alias_namespaces = NamespaceCollection() + + for key, value in initFromConfigList(components, lazy=ecocnf.startup_lazy).items(): globals()[key] = value + + if not ecocnf.startup_lazy: + try: + for ta in value.alias.get_all(): + alias_namespaces.bernina.update(ta['alias'],ta['channel'],ta['channeltype']) + except: + pass + alias_namespaces.bernina.store() + diff --git a/eco/bernina/config.py b/eco/bernina/config.py index feb54f8..6319921 100755 --- a/eco/bernina/config.py +++ b/eco/bernina/config.py @@ -188,12 +188,12 @@ components = [ # 'kwargs': {} # }, { - "args": ["SARES21-XRD"], + "args": [], "name": "xrd", "z_und": 142, "desc": "Xray diffractometer", - "type": "eco.endstations.bernina_xrd:XRD", - "kwargs": {}, + "type": "eco.endstations.bernina_diffractometers:XRD", + "kwargs": {'Id':"SARES21-XRD"}, }, { "args": ["SARES20-PROF142-M1"], diff --git a/eco/devices_general/motors.py b/eco/devices_general/motors.py index 3ed16d1..2c657a3 100755 --- a/eco/devices_general/motors.py +++ b/eco/devices_general/motors.py @@ -46,7 +46,7 @@ class MotorRecord: self.name = name self.alias = Alias(name) for an, af in alias_fields.items(): - self.alias.add_children( + self.alias.append( Alias(an, channel=".".join([pvname, af]), channeltype="CA") ) self._currentChange = None diff --git a/eco/endstations/bernina_diffractometers.py b/eco/endstations/bernina_diffractometers.py new file mode 100644 index 0000000..27ab9d5 --- /dev/null +++ b/eco/endstations/bernina_diffractometers.py @@ -0,0 +1,91 @@ +import sys + +sys.path.append("..") +from ..devices_general.motors import MotorRecord +from epics import PV +from ..aliases import Alias + + +def addMotorRecordToSelf(self,name=None, Id=None): + self.__dict__[name] = MotorRecord(Id, name=name) + self.alias.append(self.__dict__[name].alias) + + +class XRD: + def __init__(self, name=None, Id=None, configuration=[]): + """X-ray diffractometer platform in AiwssFEL Bernina.\ + : list of elements mounted on + the plaform, options are kappa, nutable, hlgonio, polana""" + self.Id = Id + self.name = name + self.alias = Alias(name) + + + ### motors base platform ### + addMotorRecordToSelf(self, Id=Id + ":MOT_TX", name="xbase") + addMotorRecordToSelf(self, Id=Id + ":MOT_TY", name="ybase") + addMotorRecordToSelf(self, Id=Id + ":MOT_RX", name="rxbase") + addMotorRecordToSelf(self, Id=Id + ":MOT_MY_RYTH", name="omega") + + + ### motors XRD detector arm ### + addMotorRecordToSelf(self, Id=Id + ":MOT_NY_RY2TH", name="gamma") + addMotorRecordToSelf(self, Id=Id + ":MOT_DT_RX2TH", name="delta") + + ### motors XRD area detector branch ### + addMotorRecordToSelf(self, Id=Id + ":MOT_D_T", name="tdet") + + ### motors XRD polarisation analyzer branch ### + addMotorRecordToSelf(self, Id=Id + ":MOT_P_T", name="tpol") + #missing: slits of flight tube + + ### motors heavy load goniometer ### + addMotorRecordToSelf(self, Id=Id + ":MOT_TBL_TX", name="xhl") + addMotorRecordToSelf(self, Id=Id + ":MOT_TBL_TZ", name="zhl") + addMotorRecordToSelf(self, Id=Id + ":MOT_TBL_TY", name="yhl") + try: + addMotorRecordToSelf(self, Id=Id + ":MOT_TBL_RX", name="rxhl") + except: + print("XRD.rxhl not found") + pass + try: + addMotorRecordToSelf(self, Id=Id + ":MOT_TBL_RY", name="rzhl") + except: + print("XRD.rzhl not found") + pass + + ### motors nu table ### + addMotorRecordToSelf(self, Id=Id + ":MOT_HEX_TX", name="teta") + addMotorRecordToSelf(self, Id=Id + ":MOT_HEX_RX", name="eta") + + ### motors PI hexapod ### + self.hex_x = PV("SARES20-HEX_PI:POSI-X") + self.hex_y = PV("SARES20-HEX_PI:POSI-Y") + self.hex_z = PV("SARES20-HEX_PI:POSI-Z") + self.hex_u = PV("SARES20-HEX_PI:POSI-U") + self.hex_v = PV("SARES20-HEX_PI:POSI-V") + self.hex_w = PV("SARES20-HEX_PI:POSI-W") + + def __repr__(self): + s = "**Heavy Load**\n" + motors = "xmu mu tth xbase ybase".split() + for motor in motors: + s += " - %s %.4f\n" % (motor, getattr(self, motor).wm()) + + s += " - xhl %.4f\n" % (self.xhl.wm()) + s += " - yhl %.4f\n" % (self.yhl.wm()) + s += " - zhl %.4f\n" % (self.zhl.wm()) + s += " - th %.4f\n" % (self.th.wm()) + s += "\n" + + s += "**Gonio**\n" + motors = "xmu mu tth delta det_z cam_z xbase ybase".split() + for motor in motors: + s += " - %s %.4f\n" % (motor, getattr(self, motor).wm()) + s += "\n" + + s += "**Hexapod**\n" + motors = "x y z u v w".split() + for motor in motors: + s += " - hex_%s %.4f\n" % (motor, getattr(self, "hex_" + motor).get()) + return s diff --git a/eco/endstations/bernina_xrd_new.py b/eco/endstations/bernina_xrd_new.py index cbd7334..3cd691a 100644 --- a/eco/endstations/bernina_xrd_new.py +++ b/eco/endstations/bernina_xrd_new.py @@ -14,8 +14,26 @@ class XRD: self.Id = Id self.name = name self.alias = Alias(name) + + + ### motors base platform ### + self.xbase = MotorRecord(Id + ":MOT_TX", name="xbase") + self.ybase = MotorRecord(Id + ":MOT_TY", name="ybase") + self.rxbase = MotorRecord(Id + ":MOT_RX", name="rxbase") + self.omega = MotorRecord(Id + ":MOT_MY_RYTH", name="omega") + + ### motors XRD detector arm ### + self.gamma = MotorRecord(Id + ":MOT_NY_RY2TH", name="gam") + self.delta = MotorRecord(Id + ":MOT_DT_RX2TH", name="del") - ### motors heavy load table ### + ### motors XRD area detector branch ### + self.tdet = MotorRecord(Id + ":MOT_D_T", name="tdet") + + ### motors XRD polarisation analyzer branch ### + self.tpol = MotorRecord(Id + ":MOT_P_T", name="tpol") + #missing: slits of flight tube + + ### motors heavy load goniometer ### self.xhl = MotorRecord(Id + ":MOT_TBL_TX", name="xhl") self.zhl = MotorRecord(Id + ":MOT_TBL_TZ", name="zhl") self.yhl = MotorRecord(Id + ":MOT_TBL_TY", name="yhl") @@ -30,19 +48,11 @@ class XRD: print("GPS.roll not found") pass - ### motors heavy load gonio base ### - self.omega = MotorRecord(Id + ":MOT_MY_RYTH", name="omega") + ### motors nu table ### self.tnu = MotorRecord(Id + ":MOT_HEX_TX", name="tnu") self.nu = MotorRecord(Id + ":MOT_HEX_RX", name="nu") - self.gamma = MotorRecord(Id + ":MOT_NY_RY2TH", name="gam") - self.delta = MotorRecord(Id + ":MOT_DT_RX2TH", name="del") - self.xbase = MotorRecord(Id + ":MOT_TX") - self.ybase = MotorRecord(Id + ":MOT_TY") - - ### motors XRD arm ### - self.tdet = MotorRecord(Id + ":MOT_D_T") - self.tpol = MotorRecord(Id + ":MOT_P_T") + ### motors PI hexapod ### self.hex_x = PV("SARES20-HEX_PI:POSI-X") self.hex_y = PV("SARES20-HEX_PI:POSI-Y") self.hex_z = PV("SARES20-HEX_PI:POSI-Z") diff --git a/eco/utilities/config.py b/eco/utilities/config.py index 1cb6d45..2c8fb85 100644 --- a/eco/utilities/config.py +++ b/eco/utilities/config.py @@ -62,6 +62,12 @@ def initFromConfigList(config_list, lazy=False): return op +class Exp: + def __init__(self,module): + pass + + + def loadConfig(fina): with open(fina, "r") as f: return json.load(f) diff --git a/eco/xdiagnostics/profile_monitors.py b/eco/xdiagnostics/profile_monitors.py index c4e27bf..d12d275 100755 --- a/eco/xdiagnostics/profile_monitors.py +++ b/eco/xdiagnostics/profile_monitors.py @@ -14,6 +14,12 @@ class Pprm: self._led = PV(self.Id + ":LED") self.target = EnumWrapper(self.Id + ":PROBE_SP") + def movein(self,target=1): + self.target.set(target) + + def moveout(self,target=0): + self.target.set(target) + def illuminate(self, value=None): if value: self._led.put(value)