From eae088fbba07cdac261a44e5d41cbc07d97d7bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CRoman?= <“mankowsky_r@psi.ch”> Date: Mon, 8 Aug 2022 17:52:52 +0200 Subject: [PATCH] Added sorting of shots by chopper --- eco/acquisition/ioxos_slab.py | 24 +++++++++--- eco/acquisition/scan.py | 1 - eco/devices_general/detectors.py | 6 ++- eco/slab/slab.py | 63 ++++++++++++++++++++++---------- 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/eco/acquisition/ioxos_slab.py b/eco/acquisition/ioxos_slab.py index 7cb9be6..dce2690 100644 --- a/eco/acquisition/ioxos_slab.py +++ b/eco/acquisition/ioxos_slab.py @@ -27,6 +27,8 @@ class IoxosChannel(Assembly): self._append(AdjustablePv, self.pvbase + f":CH{ch}:START_NEW", name = "sig_start", is_setting=True) self._append(AdjustablePv, self.pvbase + f":CH{ch}:END_NEW", name = "sig_end", is_setting=True) self._append(AdjustablePvEnum, self.pvbase + f":BOX_STAT{ch}", name = "boxcar_calculation", is_setting=True) + self._append(AdjustableFS, f"/photonics/home/gac-slab/config/eco/reference_values/ioxos_{name}_chopper_ch", name="chopper_ch", is_setting=True, default_value=0) + self._append(AdjustableFS, f"/photonics/home/gac-slab/config/eco/reference_values/ioxos_{name}_chopper_thr", name="chopper_thr", is_setting=True, default_value=1000) class Slab_Ioxos(Assembly): def __init__( @@ -124,19 +126,29 @@ class Slab_Ioxos_Daq(Assembly): np.savez_compressed(file_name, **d) def save_av(self, file_name, data, adjs_rb, adjs_name, N_pulses): - print(adjs_name, "in saveav") + chopper_chs = [self.ioxos.__dict__[f"ch{n}"].chopper_ch() for n in range(8)] + chopper_thrs = [self.ioxos.__dict__[f"ch{n}"].chopper_thr() for n in range(8)] + w = np.array([data[ch]>thr for ch, thr in zip(chopper_chs, chopper_thrs)]) + d_av_on = np.mean(data, axis=1, where=w) + d_av_off = np.mean(data, axis=1, where=~w) + d_std_on = np.std(data, axis=1, where=w) + d_std_off = np.std(data, axis=1, where=~w) + d_npulses_on = np.sum(w, axis=1) + d_npulses_off = np.sum(~w, axis=1) filename_av = file_name.split("_step")[0] + ".txt" - d_av = np.mean(data, axis=1) - d_err = np.std(data, axis=1)/np.sqrt(N_pulses) - d = np.hstack([adjs_rb, d_av, d_err]) + d = np.hstack([adjs_rb, d_av_on, d_av_off, d_std_on, d_std_off, d_npulses_on, d_npulses_off]) exists = os.path.isfile(filename_av) with open(filename_av, "a") as f: if exists: np.savetxt(f,[d]) else: head = [f"{n}, " for n in adjs_name] - head.extend([f"ch{n}, " for n in range(8)]) - head.extend([f"ch{n}_err, " for n in range(8)]) + head.extend([f"ch{n}_on, " for n in range(8)]) + head.extend([f"ch{n}_off, " for n in range(8)]) + head.extend([f"ch{n}_on_std, " for n in range(8)]) + head.extend([f"ch{n}_off_std, " for n in range(8)]) + head.extend([f"ch{n}_on_npulses, " for n in range(8)]) + head.extend([f"ch{n}_off_npulses, " for n in range(8)]) header = "".join(head) np.savetxt(f,[d],header=header) diff --git a/eco/acquisition/scan.py b/eco/acquisition/scan.py index 181c3d3..c178c8a 100755 --- a/eco/acquisition/scan.py +++ b/eco/acquisition/scan.py @@ -188,7 +188,6 @@ class Scan: file_name=fina, Npulses=self.pulses_per_step, acq_pars=acq_pars ) elif isinstance(ctr, Slab_Ioxos_Daq): - print([adj.name for adj in self.adjustables], "in scan") acq = ctr.acquire(file_name=fina, N_pulses=self.pulses_per_step, adjs_rb=readbacks_step, adjs_name=[adj.name for adj in self.adjustables]) else: acq = ctr.acquire(file_name=fina, Npulses=self.pulses_per_step) diff --git a/eco/devices_general/detectors.py b/eco/devices_general/detectors.py index 24a2785..9d8de7e 100755 --- a/eco/devices_general/detectors.py +++ b/eco/devices_general/detectors.py @@ -2,8 +2,10 @@ import numpy as np from epics import caget from epics import PV from eco.epics.utilities_epics import EnumWrapper - -from bsread import source, SUB +try: + from bsread import source, SUB +except: + pass import subprocess import h5py from time import sleep diff --git a/eco/slab/slab.py b/eco/slab/slab.py index a5d272c..7efe476 100644 --- a/eco/slab/slab.py +++ b/eco/slab/slab.py @@ -4,6 +4,7 @@ import pyttsx3 from ..utilities.path_alias import PathAlias import os + os.sys.path.insert(0,"/sf/slab/config/src/python/py_scilog") _eco_lazy_init = False @@ -42,7 +43,7 @@ namespace.append_obj( name="ioxos", module_name="eco.acquisition.ioxos_slab", pvbase="SLAB-LSCP1-ESB1", - lazy=False, + lazy=True, ) #f"/sf/bernina/data/{config['pgroup']}/res/", @@ -52,15 +53,9 @@ namespace.append_obj( module_name="eco.acquisition.ioxos_slab", default_file_path='/photonics/home/gac-slab/test/', ioxos=ioxos, - lazy=False, + lazy=True, ) -#namespace.append_obj( -# "BerninaEnv", -# name="env_log", -# module_name="eco.fel.atmosphere", -# lazy=True, -#) # adding all stuff from the config components the "old" way of configuring. # whatever is added, it is available by the configured name in this module @@ -85,6 +80,46 @@ namespace.append_obj( ) +namespace.append_obj( + "Env_Sensors", + name="env_sensors", + module_name="eco.sample_env.environment_sensors", + lazy=True, +) + +## SmarAct delay stages +namespace.append_obj( + "SmaractStreamdevice", + pvname = f"SLAB-LMTS-LAM11", + accuracy=1e-3, + name="delay_1_stg", + module_name="eco.devices_general.motors", + offset_file=f"/photonics/home/gac-slab/config/eco/reference_values/smaract_delay_1_stg", + lazy=True, +) +namespace.append_obj( + "DelayTime", + module_name="eco.loptics.bernina_laser", + stage=delay_1_stg, + name="delay_1", +) + + +namespace.append_obj( + "SmaractStreamdevice", + pvname = f"SLAB-LMTS-LAM12", + accuracy=1e-3, + name="delay_2_stg", + module_name="eco.devices_general.motors", + offset_file=f"/photonics/home/gac-slab/config/eco/reference_values/smaract_delay_2_stg", + lazy=True, +) +namespace.append_obj( + "DelayTime", + module_name="eco.loptics.bernina_laser", + stage=delay_2_stg, + name="delay_2", +) ## Scan callback functions def _message_end_scan(scan): @@ -94,18 +129,8 @@ def _message_end_scan(scan): e.stop() -#def _copy_scan_info_to_raw(scan, daq=daq): -# run_number = daq.get_last_run_number() -# pgroup = daq.pgroup -# print(f"Copying info file to run {run_number} to the raw directory of {pgroup}.") -# response = daq.append_aux( -# scan.scan_info_filename, pgroup=pgroup, run_number=run_number -# ) -# print(f"Status: {response.json()['status']} Message: {response.json()['message']}") - - callbacks_start_scan = [] -callbacks_end_scan = [_message_end_scan] +callbacks_end_scan = [] elog=None def _create_metadata_structure_start_scan(scan, run_table=run_table, elog=elog):