refactor: misc changes; playing around
This commit is contained in:
@ -1,18 +1,20 @@
|
|||||||
"""
|
"""
|
||||||
Scritpt to be developed as template for phoenic scritps
|
Scritpt to be developed as template for phoenic scritps
|
||||||
"""
|
"""
|
||||||
#from unittest import mock
|
|
||||||
|
# from unittest import mock
|
||||||
import numpy as np
|
import numpy as np
|
||||||
#import pandas
|
|
||||||
#import pytest
|
# import pandas
|
||||||
#from bec_lib import messages
|
# import pytest
|
||||||
#import device_server
|
# from bec_lib import messages
|
||||||
#from ophyd importPhoenixTemplate.pyitioner import PVPositionerComparator
|
# import device_server
|
||||||
#from ophyd.status import DeviceStatus, SubscriptionStatus
|
# from ophyd importPhoenixTemplate.pyitioner import PVPositionerComparator
|
||||||
|
# from ophyd.status import DeviceStatus, SubscriptionStatus
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#import ophyd
|
# import ophyd
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import importlib
|
import importlib
|
||||||
@ -21,39 +23,38 @@ import ophyd
|
|||||||
|
|
||||||
#
|
#
|
||||||
phoenix.add_phoenix_config()
|
phoenix.add_phoenix_config()
|
||||||
#bec.config.update_session_with_file('./ConfigPHOENIX/device_config/phoenix_devices.yaml')
|
# bec.config.update_session_with_file('./ConfigPHOENIX/device_config/phoenix_devices.yaml')
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
w1.
|
|
||||||
|
|
||||||
s1=scans.line_scan(dev.ScanX,0,0.1,steps=4,exp_time=.2,relative=False,delay=2)
|
s1 = scans.line_scan(dev.ScanX, 0, 0.1, steps=4, exp_time=0.2, relative=False, delay=2)
|
||||||
|
|
||||||
s2=scans.phoenix_line_scan(dev.ScanX,0,0.1,steps=4,exp_time=.2,relative=False,delay=2)
|
s2 = scans.phoenix_line_scan(dev.ScanX, 0, 0.1, steps=4, exp_time=0.2, relative=False, delay=2)
|
||||||
|
|
||||||
res1 = s1.scan.to_pandas()
|
res1 = s1.scan.to_pandas()
|
||||||
re1 = res1.to_numpy()
|
re1 = res1.to_numpy()
|
||||||
w1=PH.PhGroup('Bec Linescan')
|
w1 = PH.PhGroup("Bec Linescan")
|
||||||
w1.linescan2group(s1)
|
w1.linescan2group(s1)
|
||||||
|
|
||||||
print('res1')
|
print("res1")
|
||||||
print(res1)
|
print(res1)
|
||||||
print('as numpy')
|
print("as numpy")
|
||||||
print('re1')
|
print("re1")
|
||||||
|
|
||||||
|
|
||||||
res2 = s2.scan.to_pandas()
|
res2 = s2.scan.to_pandas()
|
||||||
re2 = res2.to_numpy()
|
re2 = res2.to_numpy()
|
||||||
w2=PH.PhGroup('PHOENIX Linescan')
|
w2 = PH.PhGroup("PHOENIX Linescan")
|
||||||
w2.linescan2group(s2)
|
w2.linescan2group(s2)
|
||||||
|
|
||||||
print('res2')
|
print("res2")
|
||||||
print(res2)
|
print(res2)
|
||||||
print('as numpy')
|
print("as numpy")
|
||||||
print('re2')
|
print("re2")
|
||||||
|
|
||||||
|
|
||||||
print (s1)
|
print(s1)
|
||||||
print('---------------------------------')
|
print("---------------------------------")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# scan will not diode
|
# scan will not diode
|
||||||
|
@ -1,43 +1,46 @@
|
|||||||
#from unittest import mock
|
# from unittest import mock
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
#import pandas
|
|
||||||
#import pytest
|
# import pandas
|
||||||
#from bec_lib import messages
|
# import pytest
|
||||||
#import device_server
|
# from bec_lib import messages
|
||||||
#from ophyd import Component as Cpt
|
# import device_server
|
||||||
|
# from ophyd import Component as Cpt
|
||||||
from ophyd import Device, EpicsMotor, EpicsSignal, EpicsSignalRO
|
from ophyd import Device, EpicsMotor, EpicsSignal, EpicsSignalRO
|
||||||
#from ophyd import FormattedComponent as FCpt
|
|
||||||
#from ophyd import Kind, PVPositioner, Signal
|
# from ophyd import FormattedComponent as FCpt
|
||||||
#from ophyd.flyers import FlyerInterface
|
# from ophyd import Kind, PVPositioner, Signal
|
||||||
#from ophyd.pv_positioner import PVPositionerComparator
|
# from ophyd.flyers import FlyerInterface
|
||||||
#from ophyd.status import DeviceStatus, SubscriptionStatus
|
# from ophyd.pv_positioner import PVPositionerComparator
|
||||||
|
# from ophyd.status import DeviceStatus, SubscriptionStatus
|
||||||
|
|
||||||
from bec_lib.config_helper import ConfigHelper
|
from bec_lib.config_helper import ConfigHelper
|
||||||
from bec_lib.logger import bec_logger
|
from bec_lib.logger import bec_logger
|
||||||
|
|
||||||
logger = bec_logger.logger
|
logger = bec_logger.logger
|
||||||
|
|
||||||
|
|
||||||
#import ophyd
|
# import ophyd
|
||||||
#logger = bec_logger.logger
|
# logger = bec_logger.logger
|
||||||
# load simulation
|
# load simulation
|
||||||
#bec.config.load_demo_config()
|
# bec.config.load_demo_config()
|
||||||
|
|
||||||
# .. define base path for directory with scripts
|
# .. define base path for directory with scripts
|
||||||
|
|
||||||
|
|
||||||
|
class PhoenixBL:
|
||||||
|
|
||||||
class PhoenixBL():
|
|
||||||
"""
|
"""
|
||||||
#
|
#
|
||||||
# General class for PHOENIX beamline located in phoenix_bec/phoenic_bec/scripts
|
# General class for PHOENIX beamline located in phoenix_bec/phoenic_bec/scripts
|
||||||
#
|
#
|
||||||
"""
|
"""
|
||||||
t0=time.time()
|
|
||||||
|
t0 = time.time()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
init PhoenixBL() in phoenix_bec/scripts
|
init PhoenixBL() in phoenix_bec/scripts
|
||||||
@ -45,50 +48,60 @@ class PhoenixBL():
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
|
||||||
print('..... init PhoenixBL from phoenix_bec/scripts/phoenix.py')
|
print("..... init PhoenixBL from phoenix_bec/scripts/phoenix.py")
|
||||||
|
|
||||||
# load local configuration
|
# load local configuration
|
||||||
|
|
||||||
self.path_scripts_local = '/data/test/x07mb-test-bec/bec_deployment/phoenix_bec/phoenix_bec/local_scripts/'
|
self.path_scripts_local = (
|
||||||
self.path_config_local = self.path_scripts_local + 'TEST_ConfigPhoenix/' # base dir for local configurations
|
"/data/test/x07mb-test-bec/bec_deployment/phoenix_bec/phoenix_bec/local_scripts/"
|
||||||
self.path_devices_local = self.path_config_local + 'Local_device_config/' # local yamal file
|
)
|
||||||
self.file_devices_file_local = self.path_devices_local + 'phoenix_devices.yaml'
|
self.path_config_local = (
|
||||||
|
self.path_scripts_local + "TEST_ConfigPhoenix/"
|
||||||
self.path_phoenix_bec ='/data/test/x07mb-test-bec/bec_deployment/phoenix_bec/'
|
) # base dir for local configurations
|
||||||
self.path_devices = self.path_phoenix_bec + 'phoenix_bec/device_configs/' # local yamal file
|
self.path_devices_local = (
|
||||||
self.file_devices_file = self.path_phoenix_bec + 'phoenix_bec/device_configs/phoenix_devices.yaml' # local yamal file
|
self.path_config_local + "Local_device_config/"
|
||||||
self.t0=time.time()
|
) # local yamal file
|
||||||
|
self.file_devices_file_local = self.path_devices_local + "phoenix_devices.yaml"
|
||||||
|
|
||||||
|
self.path_phoenix_bec = "/data/test/x07mb-test-bec/bec_deployment/phoenix_bec/"
|
||||||
|
self.path_devices = (
|
||||||
|
self.path_phoenix_bec + "phoenix_bec/device_configs/"
|
||||||
|
) # local yamal file
|
||||||
|
self.file_devices_file = (
|
||||||
|
self.path_phoenix_bec + "phoenix_bec/device_configs/phoenix_devices.yaml"
|
||||||
|
) # local yamal file
|
||||||
|
self.t0 = time.time()
|
||||||
|
|
||||||
def read_local_phoenix_config(self):
|
def read_local_phoenix_config(self):
|
||||||
print('read file ')
|
print("read file ")
|
||||||
print(self.file_phoenix_devices_file)
|
print(self.file_phoenix_devices_file)
|
||||||
bec.config.update_session_with_file(self.file_devices_file_local)
|
bec.config.update_session_with_file(self.file_devices_file_local)
|
||||||
|
|
||||||
def add_phoenix_config(self):
|
def add_phoenix_config(self):
|
||||||
print('add_phoenix_config ')
|
print("add_phoenix_config ")
|
||||||
print('self.file_devices_file')
|
print("self.file_devices_file")
|
||||||
bec.config.update_session_with_file(self.file_devices_file)
|
bec.config.update_session_with_file(self.file_devices_file)
|
||||||
|
|
||||||
def add_xmap(self):
|
def add_xmap(self):
|
||||||
print('add xmap ')
|
print("add xmap ")
|
||||||
print(self.path_devices+'phoenix_xmap.yaml')
|
print(self.path_devices + "phoenix_xmap.yaml")
|
||||||
|
|
||||||
bec.config.update_session_with_file(self.path_devices+'phoenix_xmap.yaml')#,timeout=100)
|
bec.config.update_session_with_file(
|
||||||
|
self.path_devices + "phoenix_xmap.yaml"
|
||||||
|
) # ,timeout=100)
|
||||||
|
|
||||||
def add_falcon(self):
|
def add_falcon(self):
|
||||||
print('add_xmap')
|
print("add_xmap")
|
||||||
print(self.path_devices+'/phoenix_falcon.yaml')
|
print(self.path_devices + "/phoenix_falcon.yaml")
|
||||||
bec.config.wait_for_config_reply()
|
# bec.config.wait_for_config_reply()
|
||||||
bec.config.update_session_with_file(self.path_devices+'/phoenix_falcon.yaml')
|
bec.config.update_session_with_file(self.path_devices + "/phoenix_falcon.yaml")
|
||||||
|
|
||||||
def show_phoenix_setup(self):
|
def show_phoenix_setup(self):
|
||||||
print(self.path_phoenix_bec)
|
print(self.path_phoenix_bec)
|
||||||
os.system('cat '+self.path_phoenix_bec+'phoenix_bec/scripts/Current_setup.txt')
|
os.system("cat " + self.path_phoenix_bec + "phoenix_bec/scripts/Current_setup.txt")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def my_log(cls,x):
|
def my_log(cls, x):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class method allows to write a user defined log file
|
class method allows to write a user defined log file
|
||||||
time is seconds relative to some point max 10 minutes ago
|
time is seconds relative to some point max 10 minutes ago
|
||||||
@ -96,21 +109,19 @@ class PhoenixBL():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
print(time.time())
|
print(time.time())
|
||||||
now = time.time() - (86400*(time.time()//86400))
|
now = time.time() - (86400 * (time.time() // 86400))
|
||||||
now = now - 3600.*(now//3600.)
|
now = now - 3600.0 * (now // 3600.0)
|
||||||
now = now - 600.*(now//600.)
|
now = now - 600.0 * (now // 600.0)
|
||||||
m=str(now)+' sec '+x
|
m = str(now) + " sec " + x
|
||||||
|
|
||||||
logger.success(m)
|
logger.success(m)
|
||||||
|
|
||||||
file=open('MyLogfile.txt','a')
|
file = open("MyLogfile.txt", "a")
|
||||||
file.write(m+'\n')
|
file.write(m + "\n")
|
||||||
file.close
|
file.close
|
||||||
|
|
||||||
|
|
||||||
|
class PhGroup:
|
||||||
|
|
||||||
class PhGroup():
|
|
||||||
"""
|
"""
|
||||||
Class to create data groups
|
Class to create data groups
|
||||||
compatible with larch groups
|
compatible with larch groups
|
||||||
@ -134,21 +145,20 @@ class PhGroup():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self,description):
|
def __init__(self, description):
|
||||||
|
|
||||||
|
setattr(self, "description", description)
|
||||||
setattr(self,'description',description)
|
|
||||||
# atribute 'label' for compatibility woith La groups...
|
# atribute 'label' for compatibility woith La groups...
|
||||||
setattr(self,'label',description)
|
setattr(self, "label", description)
|
||||||
#if type(NameTag)==list:
|
# if type(NameTag)==list:
|
||||||
# for i in NameTag:
|
# for i in NameTag:
|
||||||
# setattr(self,i,None)
|
# setattr(self,i,None)
|
||||||
# #endfor
|
# #endfor
|
||||||
#else:
|
# else:
|
||||||
# setattr(self,NameTag,None)
|
# setattr(self,NameTag,None)
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
def add(self,NameTag,content):
|
def add(self, NameTag, content):
|
||||||
"""
|
"""
|
||||||
Add tags to group...
|
Add tags to group...
|
||||||
|
|
||||||
@ -165,10 +175,9 @@ class PhGroup():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
setattr(self,NameTag,content)
|
setattr(self, NameTag, content)
|
||||||
|
|
||||||
def keys(self):
|
def keys(self):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Method gets all atributes, which are not methods
|
Method gets all atributes, which are not methods
|
||||||
and which do not start with __
|
and which do not start with __
|
||||||
@ -180,19 +189,18 @@ class PhGroup():
|
|||||||
DESCRIPTION.
|
DESCRIPTION.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
box=[]
|
box = []
|
||||||
|
|
||||||
for i in self.__dir__():
|
for i in self.__dir__():
|
||||||
if '__' not in i:
|
if "__" not in i:
|
||||||
#print(i)
|
# print(i)
|
||||||
if str(type(self.__getattribute__(i))) != "<class 'method'>":
|
if str(type(self.__getattribute__(i))) != "<class 'method'>":
|
||||||
box.append(i)
|
box.append(i)
|
||||||
#endif
|
# endif
|
||||||
#endfor
|
# endfor
|
||||||
return box
|
return box
|
||||||
|
|
||||||
|
def linescan2group(self, this_scan):
|
||||||
def linescan2group(self,this_scan):
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
method merges results of linescan into group and
|
method merges results of linescan into group and
|
||||||
@ -204,37 +212,31 @@ class PhGroup():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print('keys')
|
print("keys")
|
||||||
print(this_scan.scan.data.keys())
|
print(this_scan.scan.data.keys())
|
||||||
for outer_key in this_scan.scan.data.keys():
|
for outer_key in this_scan.scan.data.keys():
|
||||||
print('outer_key',outer_key)
|
print("outer_key", outer_key)
|
||||||
n_outer = len(this_scan.scan.data.keys())
|
n_outer = len(this_scan.scan.data.keys())
|
||||||
for inner_key in this_scan.scan.data[outer_key].keys():
|
for inner_key in this_scan.scan.data[outer_key].keys():
|
||||||
print('inner_key',inner_key)
|
print("inner_key", inner_key)
|
||||||
# calculate nunber of points
|
# calculate nunber of points
|
||||||
n_inner = len(this_scan.scan.data[outer_key][inner_key].keys())
|
n_inner = len(this_scan.scan.data[outer_key][inner_key].keys())
|
||||||
value = np.zeros(n_inner)
|
value = np.zeros(n_inner)
|
||||||
timestamp = np.zeros(n_inner)
|
timestamp = np.zeros(n_inner)
|
||||||
for i in range(n_inner):
|
for i in range(n_inner):
|
||||||
try:
|
try:
|
||||||
value[i] = this_scan.scan.data[outer_key][inner_key][i]['value']
|
value[i] = this_scan.scan.data[outer_key][inner_key][i]["value"]
|
||||||
except:
|
except:
|
||||||
value=None
|
value = None
|
||||||
try:
|
try:
|
||||||
timestamp[i] = this_scan.scan.data[outer_key][inner_key][i]['timestamp']
|
timestamp[i] = this_scan.scan.data[outer_key][inner_key][i]["timestamp"]
|
||||||
except:
|
except:
|
||||||
timestamp[i]=None
|
timestamp[i] = None
|
||||||
#endfor
|
# endfor
|
||||||
self.add(inner_key+'_'+ outer_key+'_val',value)
|
self.add(inner_key + "_" + outer_key + "_val", value)
|
||||||
self.add(inner_key+'_'+ outer_key+'_ts',timestamp)
|
self.add(inner_key + "_" + outer_key + "_ts", timestamp)
|
||||||
#endfor
|
# endfor
|
||||||
#endfor
|
# endfor
|
||||||
#endfor
|
# endfor
|
||||||
#enddef
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# enddef
|
||||||
|
Reference in New Issue
Block a user