upgrade of the adjustable value_property
This commit is contained in:
@@ -172,10 +172,10 @@ class Daq(Assembly):
|
||||
timeout=self.timeout,
|
||||
).json()
|
||||
)
|
||||
|
||||
runno = response['run_number']
|
||||
|
||||
filenames = response['files']
|
||||
runno = response["run_number"]
|
||||
|
||||
filenames = response["files"]
|
||||
|
||||
# filenames = [
|
||||
# (directory_base / Path(filename_format.format(runno)))
|
||||
@@ -186,27 +186,27 @@ class Daq(Assembly):
|
||||
|
||||
return runno, filenames
|
||||
|
||||
def get_next_run_number(self,pgroup=None):
|
||||
def get_next_run_number(self, pgroup=None):
|
||||
if pgroup is None:
|
||||
pgroup = self.pgroup
|
||||
res = requests.get(
|
||||
f"{self.broker_address}/get_next_run_number",
|
||||
json={'pgroup':pgroup},
|
||||
json={"pgroup": pgroup},
|
||||
timeout=self.timeout,
|
||||
)
|
||||
assert res.ok, f'Getting last run number failed {res.raise_for_status()}'
|
||||
return int(res.json()['message'])
|
||||
)
|
||||
assert res.ok, f"Getting last run number failed {res.raise_for_status()}"
|
||||
return int(res.json()["message"])
|
||||
|
||||
def get_last_run_number(self,pgroup=None):
|
||||
def get_last_run_number(self, pgroup=None):
|
||||
if pgroup is None:
|
||||
pgroup = self.pgroup
|
||||
res = requests.get(
|
||||
f"{self.broker_address}/get_last_run_number",
|
||||
json={'pgroup':pgroup},
|
||||
json={"pgroup": pgroup},
|
||||
timeout=self.timeout,
|
||||
)
|
||||
assert res.ok, f'Getting last run number failed {res.raise_for_status()}'
|
||||
return int(res.json()['message'])
|
||||
)
|
||||
assert res.ok, f"Getting last run number failed {res.raise_for_status()}"
|
||||
return int(res.json()["message"])
|
||||
|
||||
def get_detector_frequency(self):
|
||||
return self._event_master.event_codes[
|
||||
@@ -243,16 +243,17 @@ class Daq(Assembly):
|
||||
f"{self.broker_address}/take_pedestal", json=parameters
|
||||
).json()
|
||||
|
||||
def append_aux(self,*file_names,run_number=None,pgroup=None):
|
||||
def append_aux(self, *file_names, run_number=None, pgroup=None):
|
||||
if pgroup is None:
|
||||
pgroup = self.pgroup
|
||||
if run_number is None:
|
||||
run_number = self.get_last_run_number()
|
||||
|
||||
return requests.post(
|
||||
self.broker_address_aux+'/copy_user_files',
|
||||
json={'pgroup': pgroup, 'run_number': run_number, 'files': file_names}
|
||||
)
|
||||
self.broker_address_aux + "/copy_user_files",
|
||||
json={"pgroup": pgroup, "run_number": run_number, "files": file_names},
|
||||
)
|
||||
|
||||
|
||||
def validate_response(resp):
|
||||
if resp.get("status") == "ok":
|
||||
|
||||
+63
-32
@@ -71,8 +71,8 @@ namespace.append_obj(
|
||||
"Run_Table2",
|
||||
name="run_table",
|
||||
module_name="eco.utilities.runtable",
|
||||
exp_id=config_bernina.pgroup.value,
|
||||
exp_path=f"/sf/bernina/data/{config_bernina.pgroup.value}/res/run_table/",
|
||||
exp_id=config_bernina.pgroup._value,
|
||||
exp_path=f"/sf/bernina/data/{config_bernina.pgroup._value}/res/run_table/",
|
||||
devices="bernina",
|
||||
keydf_fname="/sf/bernina/config/src/python/gspread/gspread_keys.pkl",
|
||||
cred_fname="/sf/bernina/config/src/python/gspread/pandas_push",
|
||||
@@ -473,7 +473,7 @@ namespace.append_obj(
|
||||
Id="SARES21-XRD",
|
||||
configuration=config_bernina.xrd_config(),
|
||||
diff_detector={"jf_id": "JF01T03V01"},
|
||||
invert_kappa_ellbow=config_bernina.invert_kappa_ellbow.value,
|
||||
invert_kappa_ellbow=config_bernina.invert_kappa_ellbow._value,
|
||||
name="xrd",
|
||||
lazy=True,
|
||||
)
|
||||
@@ -665,33 +665,37 @@ def _message_end_scan(scan):
|
||||
# )
|
||||
# print(f"Status: {response.json()['status']} Message: {response.json()['message']}")
|
||||
|
||||
def _create_general_run_info(scan,daq=daq):
|
||||
with open(scan.scan_info_filename,'r') as f:
|
||||
|
||||
def _create_general_run_info(scan, daq=daq):
|
||||
with open(scan.scan_info_filename, "r") as f:
|
||||
si = json.load(f)
|
||||
|
||||
info = {}
|
||||
# general info, potentially automatically filled
|
||||
info['general'] = {}
|
||||
info["general"] = {}
|
||||
# individual data filled by daq/writers/user through api
|
||||
info['start'] = {}
|
||||
info['end'] = {}
|
||||
info['steps'] = []
|
||||
info["start"] = {}
|
||||
info["end"] = {}
|
||||
info["steps"] = []
|
||||
|
||||
|
||||
def _copy_scan_info_to_raw(scan,daq=daq):
|
||||
|
||||
def _copy_scan_info_to_raw(scan, daq=daq):
|
||||
|
||||
# get data that should come later from api or similar.
|
||||
run_directory = list(Path(f"/sf/bernina/data/{daq.pgroup}/raw").glob(f'run{scan.run_number:04d}*'))[0].as_posix()
|
||||
with open(scan.scan_info_filename,'r') as f:
|
||||
run_directory = list(
|
||||
Path(f"/sf/bernina/data/{daq.pgroup}/raw").glob(f"run{scan.run_number:04d}*")
|
||||
)[0].as_posix()
|
||||
with open(scan.scan_info_filename, "r") as f:
|
||||
si = json.load(f)
|
||||
|
||||
# correct some data in there (relative paths for now)
|
||||
from os.path import relpath
|
||||
|
||||
newfiles = []
|
||||
for files in si['scan_files']:
|
||||
newfiles.append([relpath(file,run_directory) for file in files])
|
||||
|
||||
si['scan_files'] = newfiles
|
||||
for files in si["scan_files"]:
|
||||
newfiles.append([relpath(file, run_directory) for file in files])
|
||||
|
||||
si["scan_files"] = newfiles
|
||||
|
||||
# save temprary file and send then to raw
|
||||
runno = daq.get_last_run_number()
|
||||
@@ -707,11 +711,9 @@ def _copy_scan_info_to_raw(scan,daq=daq):
|
||||
f.seek(0)
|
||||
json.dump(si, f, sort_keys=True, cls=NumpyEncoder, indent=4)
|
||||
f.truncate()
|
||||
|
||||
|
||||
print(f"Copying info file to run {runno} to the raw directory of {pgroup}.")
|
||||
response = daq.append_aux(
|
||||
scaninfofile.as_posix(), pgroup=pgroup, run_number=runno
|
||||
)
|
||||
response = daq.append_aux(scaninfofile.as_posix(), pgroup=pgroup, run_number=runno)
|
||||
print(f"Status: {response.json()['status']} Message: {response.json()['message']}")
|
||||
|
||||
|
||||
@@ -1071,40 +1073,69 @@ class THz_in_air(Assembly):
|
||||
self._append(SmaractRecord, "SARES23:ESB15", name="focus_Ry", is_setting=True)
|
||||
self._append(SmaractRecord, "SARES23:ESB11", name="focus_Rx", is_setting=True)
|
||||
self._append(SmaractRecord, "SARES23:LIC18", name="thz_wp", is_setting=True)
|
||||
self._append(SmaractRecord, "SARES23:LIC16", name="delaystage_thz", is_setting=True)
|
||||
self._append(
|
||||
SmaractRecord, "SARES23:LIC16", name="delaystage_thz", is_setting=True
|
||||
)
|
||||
self._append(DelayTime, self.delaystage_thz, name="delay_thz", is_setting=True)
|
||||
self._append(MotorRecord, "SLAAR21-LMOT-M521:MOTOR_1", name="delaystage_800_pump", is_setting=True)
|
||||
self._append(DelayTime, self.delaystage_800_pump, name="delay_800_pump", is_setting=True)
|
||||
|
||||
self._append(
|
||||
MotorRecord,
|
||||
"SLAAR21-LMOT-M521:MOTOR_1",
|
||||
name="delaystage_800_pump",
|
||||
is_setting=True,
|
||||
)
|
||||
self._append(
|
||||
DelayTime, self.delaystage_800_pump, name="delay_800_pump", is_setting=True
|
||||
)
|
||||
self._append(
|
||||
AdjustableFS,
|
||||
"/photonics/home/gac-bernina/eco/configuration/combined_delta",
|
||||
name="combined_delta",
|
||||
default_value=0,
|
||||
is_setting=True,
|
||||
)
|
||||
self.delay_thz = DelayTime(self.delaystage_thz, name="delay_thz")
|
||||
|
||||
self.thz_polarization = AdjustableVirtual(
|
||||
self._append(
|
||||
AdjustableVirtual,
|
||||
[self.crystal_ROT, self.thz_wp],
|
||||
self.thz_pol_get,
|
||||
self.thz_pol_set,
|
||||
name="thz_polarization",
|
||||
|
||||
|
||||
)
|
||||
self.combined_delay = AdjustableVirtual(
|
||||
# self.thz_polarization = AdjustableVirtual(
|
||||
# [self.crystal_ROT, self.thz_wp],
|
||||
# self.thz_pol_get,
|
||||
# self.thz_pol_set,
|
||||
# name="thz_polarization",
|
||||
# )
|
||||
self._append(
|
||||
AdjustableVirtual,
|
||||
[self.delay_thz, self.delay_800_pump],
|
||||
self.delay_get,
|
||||
self.delay_set,
|
||||
name="combined_delay",
|
||||
|
||||
)
|
||||
|
||||
# self.combined_delay = AdjustableVirtual(
|
||||
# [self.delay_thz, self.delay_800_pump],
|
||||
# self.delay_get,
|
||||
# self.delay_set,
|
||||
# name="combined_delay",
|
||||
# )
|
||||
|
||||
def thz_pol_set(self, val):
|
||||
return 1.0 * val, 1.0 / 2 * val
|
||||
|
||||
def thz_pol_get(self, val, val2):
|
||||
return 1.0 * val
|
||||
return 1.0 * val2
|
||||
|
||||
def delay_set(self, val):
|
||||
return 1.0 * val, 1.0 * val
|
||||
return 1.0 * val + self.combined_delta(), 1.0 * val
|
||||
|
||||
def delay_get(self, val, val2):
|
||||
return 1.0 * val
|
||||
|
||||
|
||||
namespace.append_obj(
|
||||
THz_in_air,
|
||||
lazy=True,
|
||||
|
||||
@@ -246,19 +246,34 @@ def update_changes(Adj):
|
||||
def value_property(Adj, wait_for_change=True, value_name="_value"):
|
||||
if wait_for_change:
|
||||
|
||||
def tmp(Adj, value):
|
||||
Adj.set_target_value(value, hold=False).wait()
|
||||
def set_target_value_wait(self, value):
|
||||
self.set_target_value(value, hold=False).wait()
|
||||
|
||||
def get_current_value(self):
|
||||
o = self.get_current_value()
|
||||
if hasattr(o, "__setitem__"):
|
||||
# print("overwriting output class")
|
||||
|
||||
class TempObj(o.__class__):
|
||||
def __setitem__(oself, *args):
|
||||
o.__class__.__setitem__(oself, *args)
|
||||
self._set_target_value_wait(oself)
|
||||
|
||||
return TempObj(o)
|
||||
else:
|
||||
return o
|
||||
|
||||
Adj._set_target_value_wait = set_target_value_wait
|
||||
Adj._get_current_value = get_current_value
|
||||
|
||||
setattr(
|
||||
Adj,
|
||||
value_name,
|
||||
property(
|
||||
Adj.get_current_value,
|
||||
tmp,
|
||||
Adj._get_current_value,
|
||||
Adj._set_target_value_wait,
|
||||
),
|
||||
)
|
||||
|
||||
Adj.value = property(lambda self: self._value)
|
||||
return Adj
|
||||
|
||||
|
||||
|
||||
@@ -294,5 +294,7 @@ class PositionMonitors(Assembly):
|
||||
super().__init__(name=name)
|
||||
self._append(CameraPositionMonitor, 'SLAAR21-LCAM-C551', name='post_compressor_focus', is_display='recursive', is_status=True)
|
||||
self._append(CameraPositionMonitor, 'SLAAR21-LCAM-C552', name='post_compressor_position', is_display='recursive', is_status=True)
|
||||
self._append(CameraPositionMonitor, 'SLAAR21-LCAM-C531', name='opaout_position', is_display='recursive', is_status=True)
|
||||
self._append(CameraPositionMonitor, 'SLAAR21-LCAM-C511', name='opaout_focus', is_display='recursive', is_status=True)
|
||||
# self._append(CameraPositionMonitor, 'SLAAR21-LCAM-C541', name='cam541')
|
||||
# self._append(CameraPositionMonitor, 'SLAAR21-LCAM-C542', name='cam542')
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
from eco import Assembly
|
||||
from eco.epics.adjustable import AdjustablePv, AdjustablePvEnum
|
||||
from eco.epics.detector import DetectorPvData, DetectorPvDataStream
|
||||
|
||||
|
||||
class LabMaxEnergyMonitor(Assembly):
|
||||
def __init__(self,pvname, name=None):
|
||||
super().__init__(name=name)
|
||||
self.pvname = pvname
|
||||
self._append(DetectorPvDataStream, pvname+':READ_SC',name='pulse_energy')
|
||||
self._append(DetectorPvDataStream, pvname+':ENERGY_AVE100',name='pulse_energy_avg100')
|
||||
self._append(AdjustablePvEnum, pvname+':READ.SCAN',name='read_mode')
|
||||
self._append(AdjustablePv, pvname+':SET_FSD',name='output_signal_voltage', is_setting=True)
|
||||
self._append(AdjustablePvEnum, pvname+':WL_CORR_MODE',name='correct_wavelenght', is_setting=True)
|
||||
self._append(AdjustablePvEnum, pvname+':TRIG_SOURCE',name='trigger_source', is_setting=True)
|
||||
self._append(AdjustablePv, pvname+':SET_TRIG_LEVEL',name='output_signal_voltage', is_setting=True)
|
||||
self._append(DetectorPvData, pvname+':GET_RANGE_SC',name='range', is_setting=True)
|
||||
self._append(AdjustablePv, pvname+':SELECT_RANGE',name='set_range', is_setting=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user