diff --git a/eco/endstations/bernina_sample_environments.py b/eco/endstations/bernina_sample_environments.py index 627c2d7..acb8760 100644 --- a/eco/endstations/bernina_sample_environments.py +++ b/eco/endstations/bernina_sample_environments.py @@ -398,7 +398,7 @@ class High_field_thz_chamber(Assembly): # mot.stage_type(config["type"]) mot.motor_parameters.sensor_type_num(config["sensor"]) mot.direction(config["direction"]) - mot.motor_parameters.max_frequency(config > ["speed"]) + mot.motor_parameters.max_frequency(config["speed"]) sleep(0.5) mot.calibrate_sensor() @@ -678,6 +678,7 @@ class Organic_crystal_breadboard(Assembly): mot.motor_parameters.sensor_type_num(config["sensor"]) mot.direction(config["direction"]) mot.motor_parameters.max_frequency(config["speed"]) + mot.speed(0) sleep(0.5) mot.calibrate_sensor() @@ -852,16 +853,16 @@ class Electro_optic_sampling(Assembly): "home_direction": "back", }, "rx": { - "id": "SARES23-USR:MOT_11", - "pv_descr": "Motor4:2 EOS Rx", + "id": "SARES23-USR:MOT_8", + "pv_descr": "Motor3:2 EOS Rx", "sensor": 53, "speed": 250, "direction": 0, "home_direction": "back", }, "x": { - "id": "SARES23-USR:MOT_12", - "pv_descr": "Module4:3 EOS x", + "id": "SARES23-USR:MOT_9", + "pv_descr": "Module3:3 EOS x", "sensor": 42, "speed": 250, "direction": 0, diff --git a/eco/timing/timing_diag.py b/eco/timing/timing_diag.py index 04f0e55..b42d439 100644 --- a/eco/timing/timing_diag.py +++ b/eco/timing/timing_diag.py @@ -20,6 +20,7 @@ import numpy as np import pylab as plt from epics import PV from bsread import source +from pathlib import Path # from time import sleep @@ -32,6 +33,7 @@ class TimetoolBerninaUSD(Assembly): name=None, processing_pipeline="SARES20-CAMS142-M5_psen_db", edge_finding_pipeline="SAROP21-ATT01_proc", + pv_writing_pipeline="Bernina_tt_kb_populate_pvs", processing_instance="SARES20-CAMS142-M5_psen_db", spectrometer_camera_channel="SARES20-CAMS142-M5:FPICTURE", spectrometer_pvname="SARES20-CAMS142-M5", @@ -74,6 +76,16 @@ class TimetoolBerninaUSD(Assembly): ) except Exception as e: print(f"Timetool edge finding pipeline initialization failed with: \n{e}") + try: + self.proc_pipeline_pv_writing = pv_writing_pipeline + self._append( + Pipeline, + self.proc_pipeline_pv_writing, + name="pipeline_pv_writing", + is_setting=True, + ) + except Exception as e: + print(f"Timetool pv writing pipeline initialization failed with: \n{e}") self.spectrometer_camera_channel = spectrometer_camera_channel self._append( Target_xyz, @@ -180,7 +192,7 @@ class TimetoolBerninaUSD(Assembly): self._append( DetectorBsStream, "SAROP21-ATT01:edge_pos", - cachannel="SLAAR21-SPECTT:AT", + cachannel="SLAAR21-SPECTT:PX", name="edge_position_px", is_setting=False, is_display=True, @@ -188,7 +200,7 @@ class TimetoolBerninaUSD(Assembly): self._append( DetectorBsStream, "SAROP21-ATT01:xcorr_ampl", - cachannel="SLAAR21-SPATTT:AT", + cachannel="SLAAR21-SPECTT:MX", name="edge_amplitude", is_setting=False, is_display=True, @@ -196,7 +208,7 @@ class TimetoolBerninaUSD(Assembly): self._append( DetectorBsStream, "SAROP21-ATT01:arrival_time", - cachannel="SLAAR21-LTIM01-EVR0:CALCZ.INPE", + cachannel="SLAAR21-SPECTT:AT", name="edge_position_fs", is_setting=False, is_display=True, @@ -246,48 +258,83 @@ class TimetoolBerninaUSD(Assembly): print(f"Andor spectrometer initialization failed with: \n{e}") def get_calibration_values( - self, seconds=5, scan_range=.8e-12, plot=False, pipeline=True + self, seconds=5, scan_range=.8e-12, plot=False, pipeline=True, to_elog=False ): t0 = self.delay() x = np.linspace(t0 - scan_range / 2, t0 + scan_range / 2, 20) y = [] + ymean = [] yerr = [] try: for pos in x: print(f"Moving to {pos*1e15} fs") self.delay.set_target_value(pos).wait() if pipeline: + #needed due to delay of data arrival sleep(2) ys = self.edge_position_px.acquire(seconds=seconds).wait() - y.append(np.mean(ys)) - yerr.append(np.std(ys)) + y.append(ys) + ymean.append(np.mean(ys)) + yerr.append(np.std(ys)/np.sqrt(len(ys))) except Exception as e: print(e) print(f"Moving back to inital value of {t0}") self.delay.set_target_value(t0) - p = np.polyfit(y, x, 2) + p = np.polyfit(ymean, x, 2, w=1/np.array(yerr)) + fpath = "" if plot: + binmin = np.min([np.min(step) for step in y]) + binmax = np.max([np.max(step) for step in y]) + bins = np.arange(binmin, binmax, 1) + bins_center = bins[:-1]+0.5 + hists = np.array([np.histogram(step, bins=bins)[0]for step in y]).T plt.close("tt_calib") fig = plt.figure("tt_calib") - line = plt.errorbar(x, y, yerr) - fit = plt.plot(np.polyval(p, y), y, label=p) + plt.pcolor(x, bins_center, hists) + line = plt.errorbar(x, ymean, yerr, color="red", marker=".", linestyle="") + fit = plt.plot(np.polyval(p, ymean), ymean, label=p, color="yellow") + plt.xlabel("tt_kb.delay (s)") + plt.ylabel("edge position (px)") plt.legend() plt.show() - print(f"Fit results c0 + c1*px + c2*px^2:\n{p}") + if to_elog: + fpath = "/photonics/home/gac-bernina/tt_calib.jpg" + fig.savefig(fpath, dpi=200) + fpath = Path(fpath) + if to_elog: + try: + msg = f"