diff --git a/eco/acquisition/dia.py b/eco/acquisition/dia.py index 4a1abb8..76e1e87 100644 --- a/eco/acquisition/dia.py +++ b/eco/acquisition/dia.py @@ -337,7 +337,7 @@ class DIAClient: self.client.stop() outputfilenames = [ - f"{file_name_JF}.{tcli.upper()}.h5" for tcli in self.active_clients+['camera'] # DIRTY HACK + f"{file_name_JF}.{tcli.upper()}.h5" for tcli in self.active_clients+['BSREAD.h5_SARES20-CAMS142-M4','BSREAD.h5_SARES20-CAMS142-M5'] # DIRTY HACK ] return Acquisition( diff --git a/eco/bernina/config.py b/eco/bernina/config.py index 684905b..3603056 100755 --- a/eco/bernina/config.py +++ b/eco/bernina/config.py @@ -178,7 +178,7 @@ components = [ "desc": "Intensity/position monitor after Optics hutch", "type": "eco.xdiagnostics.intensity_monitors:SolidTargetDetectorPBPS_new", "args": ["SAROP21-PBPS133"], - "kwargs": {"VME_crate": "SAROP21-CVME-PBPS1", "link": 9, 'channels':{'up':'SLAAR21-LSCP1-FNS:CH4:VAL_GET','down':'SLAAR21-LSCP1-FNS:CH5:VAL_GET','left':'SLAAR21-LSCP1-FNS:CH6:VAL_GET','right':'SLAAR21-LSCP1-FNS:CH7:VAL_GET'},'calc':{'itot':'SLAAR21-LTIM01-EVR0:CALCI','xpos':'SLAAR21-LTIM01-EVR0:CALCX','ypos':'SLAAR21-LTIM01-EVR0:CALCY'}}, + "kwargs": {"VME_crate": "SAROP21-CVME-PBPS1", "link": 9, 'channels':{'up':'SLAAR21-LSCP1-FNS:CH6:VAL_GET','down':'SLAAR21-LSCP1-FNS:CH7:VAL_GET','left':'SLAAR21-LSCP1-FNS:CH4:VAL_GET','right':'SLAAR21-LSCP1-FNS:CH5:VAL_GET'},'calc':{'itot':'SLAAR21-LTIM01-EVR0:CALCI','xpos':'SLAAR21-LTIM01-EVR0:CALCX','ypos':'SLAAR21-LTIM01-EVR0:CALCY'}}, }, { "name": "prof_opt", @@ -479,7 +479,7 @@ components = [ "name": "default_channel_list_bs", "desc": "Bernina default bs channels, used by bs_daq", "type": "eco.utilities.config:ChannelList", - "kwargs": {"file_name":"/sf/bernina/config/channel_lists/default_channel_list"}, + "kwargs": {"file_name":"/sf/bernina/config/channel_lists/default_channel_list_bs"}, "lazy": False, }, { diff --git a/eco/loptics/bernina_experiment.py b/eco/loptics/bernina_experiment.py index b6e490a..278c9b5 100755 --- a/eco/loptics/bernina_experiment.py +++ b/eco/loptics/bernina_experiment.py @@ -32,6 +32,7 @@ class DelayTime(AdjustableVirtual): self._group_velo = 299798458 # m/s self._passes = passes self.Id = stage.Id + "_delay" + self._stage = stage AdjustableVirtual.__init__( self, [stage], @@ -57,6 +58,16 @@ class DelayTime(AdjustableVirtual): s += f"{colorama.Style.RESET_ALL}" return s + def get_limits(self): + return [self._mm_to_s(tl) for tl in self._stage.get_limits()] + + def set_limits(self,low_limit,high_limit): + lims_stage = [self._s_to_mm(tl) for tl in [low_limit,high_limit]] + lims_stage.sort() + self._stage.set_limits(*lims_stage) + + + return [self._mm_to_s(tl) for tl in self._stage.get_limits()] class DelayCompensation(AdjustableVirtual): """Simple virtual adjustable for compensating delay adjustables. It assumes the first adjustable is the master for diff --git a/eco/xdiagnostics/intensity_monitors.py b/eco/xdiagnostics/intensity_monitors.py index 28dec91..341e493 100755 --- a/eco/xdiagnostics/intensity_monitors.py +++ b/eco/xdiagnostics/intensity_monitors.py @@ -4,6 +4,7 @@ from ..devices_general.detectors import FeDigitizer,PvDataStream from ..devices_general.adjustable import PvEnum from ..aliases import Alias,append_object_to_object from epics import PV +import numpy as np class GasDetector: @@ -32,8 +33,8 @@ class SolidTargetDetectorPBPS_new: self.name = name self.pvname = pvname self.alias = Alias(name) - append_object_to_object(self,MotorRecord,pvname + ":MOTOR_X1", name="diodes_x") - append_object_to_object(self,MotorRecord,pvname + ":MOTOR_Y1", name="diodes_y") + append_object_to_object(self,MotorRecord,pvname + ":MOTOR_X1", name="x_diodes") + append_object_to_object(self,MotorRecord,pvname + ":MOTOR_Y1", name="y_diodes") append_object_to_object(self,MotorRecord,pvname + ":MOTOR_PROBE", name="target_y") append_object_to_object(self,PvEnum,pvname + ":PROBE_SP", name="target") if VME_crate: @@ -54,6 +55,76 @@ class SolidTargetDetectorPBPS_new: append_object_to_object(self,PvDataStream,calc['xpos'], name="xpos") append_object_to_object(self,PvDataStream,calc['ypos'], name="ypos") + def get_calibration_values(self,seconds=5): + self.x_diodes.set_target(0).wait() + self.y_diodes.set_target(0).wait() + ds = [self.signal_up, self.signal_down, self.signal_left, self.signal_right] + aqs = [d.acquire(seconds=seconds) for d in ds] + data = [aq.wait() for aq in aqs] + mean = [np.mean(td) for td in data] + std = [np.std(td) for td in data] + norm_diodes = [1/tm/4 for tm in mean] + return norm_diodes + + def set_calibration_values(self,norm_diodes): + #this is now only for bernina when using the ioxos from sla + channels = ['SLAAR21-LTIM01-EVR0:CALCI.INPG','SLAAR21-LTIM01-EVR0:CALCI.INPH','SLAAR21-LTIM01-EVR0:CALCI.INPF','SLAAR21-LTIM01-EVR0:CALCI.INPE'] + for tc,tv in zip(channels,norm_diodes): + PV(tc).put(bytes(str(tv),'utf8')) + channels = ['SLAAR21-LTIM01-EVR0:CALCX.INPE','SLAAR21-LTIM01-EVR0:CALCX.INPF'] + for tc,tv in zip(channels,norm_diodes[2:4]): + PV(tc).put(bytes(str(tv),'utf8')) + channels = ['SLAAR21-LTIM01-EVR0:CALCY.INPE','SLAAR21-LTIM01-EVR0:CALCY.INPF'] + for tc,tv in zip(channels,norm_diodes[0:2]): + PV(tc).put(bytes(str(tv),'utf8')) + + def get_calibration_values_position(self,calib_intensities,seconds=5,motion_range=.2): + self.x_diodes.set_limits(-motion_range/2-.1,+motion_range/2+.1) + self.y_diodes.set_limits(-motion_range/2-.1,+motion_range/2+.1) + self.x_diodes.set_target(0).wait() + self.y_diodes.set_target(0).wait() + raw = [] + for pos in [motion_range/2, -motion_range/2]: + self.x_diodes.set_target(pos).wait() + aqs = [ts.acquire(seconds=seconds) for ts in [self.signal_left, self.signal_right]] + vals = [np.mean(aq.wait())*calib for aq,calib in zip(aqs,calib_intensities[0:2])] + raw.append((vals[0]-vals[1])/(vals[0]+vals[1])) + grad = motion_range/np.diff(raw)[0] + # xcalib = [np.diff(calib_intensities[0:2])[0]/np.sum(calib_intensities[0:2]), grad] + xcalib = [0, grad] + self.x_diodes.set_target(0).wait() + raw = [] + for pos in [motion_range/2, -motion_range/2]: + self.y_diodes.set_target(pos).wait() + aqs = [ts.acquire(seconds=seconds) for ts in [self.signal_up, self.signal_down]] + vals = [np.mean(aq.wait())*calib for aq,calib in zip(aqs,calib_intensities[2:4])] + raw.append((vals[0]-vals[1])/(vals[0]+vals[1])) + grad = motion_range/np.diff(raw)[0] + # ycalib = [np.diff(calib_intensities[2:4])[0]/np.sum(calib_intensities[2:4]), grad] + ycalib = [0, grad] + self.y_diodes.set_target(0).wait() + return xcalib,ycalib + + def set_calibration_values_position(self,xcalib,ycalib): + channels = ['SLAAR21-LTIM01-EVR0:CALCX.INPJ','SLAAR21-LTIM01-EVR0:CALCX.INPI'] + # txcalib = [-1*xcalib[0],-1*xcalib[1]] + for tc,tv in zip(channels,xcalib): + PV(tc).put(bytes(str(tv),'utf8')) + channels = ['SLAAR21-LTIM01-EVR0:CALCY.INPJ','SLAAR21-LTIM01-EVR0:CALCY.INPI'] + for tc,tv in zip(channels,ycalib): + PV(tc).put(bytes(str(tv),'utf8')) + + + def calibrate(self,seconds=5): + c = self.get_calibration_values(seconds=seconds) + self.set_calibration_values(c) + xc,yc = self.get_calibration_values_position(c,seconds=seconds) + self.set_calibration_values_position(xc,yc) + + + + + def __repr__(self): s = f"**Intensity monitor {self.name}**\n\n"