diff --git a/beam_adjustment_notes.md b/beam_adjustment_notes.md new file mode 100644 index 0000000..be79a2f --- /dev/null +++ b/beam_adjustment_notes.md @@ -0,0 +1,15 @@ +For histo threshold beam location: + + # PV: Stats5:CentroidThreshold + # Get histogram, find index of 97th %ile, use it as threshold + # histo -> cumsum -> final value * 0.97 -> index where cumsum exceeds this -> this value should be the threshold + + +For profile fitting beam centre location: +- Make sure NDPluginXYProfile is enabled: + - X06DA-ES-MS:XYP1:EnableCallbacks + - X06DA-ES-MS:XYP1:X:Compute + - X06DA-ES-MS:XYP1:Y:Compute +- Then, gaussian peak from X06DA-ES-MS:XYP1:X:Mu_RBV X06DA-ES-MS:XYP1:Y:Mu_RBV +- This relies on filtering the green channel from the image only for better s/n + - This is in plugin ROI1/ROI11 - full image (0-10000 x+y, 1 only z), needs to be the input port for the XYP1 diff --git a/pxiii_bec/device_configs/fluo.yaml b/pxiii_bec/device_configs/fluo.yaml new file mode 100644 index 0000000..ce2e101 --- /dev/null +++ b/pxiii_bec/device_configs/fluo.yaml @@ -0,0 +1,11 @@ +fluorimeter: + readoutPriority: on_request + description: fluorimeter + deviceClass: pxiii_bec.devices.Fluorimeter + deviceConfig: + prefix: "X06DA-ES-XRF:" + deviceTags: + - xrf + enabled: true + readOnly: false + softwareTrigger: false diff --git a/pxiii_bec/device_configs/pxiii-beamline-states.yaml b/pxiii_bec/device_configs/pxiii-beamline-states.yaml index e8579d9..3921888 100644 --- a/pxiii_bec/device_configs/pxiii-beamline-states.yaml +++ b/pxiii_bec/device_configs/pxiii-beamline-states.yaml @@ -193,7 +193,7 @@ states: bl_bright: 'on' bs_pos: in bs_z: safe - coll_y: intermediate + coll_y: in cryo_pos: in det_cov: 'close' diag_y: out diff --git a/pxiii_bec/device_configs/pxiii-devices.yaml b/pxiii_bec/device_configs/pxiii-devices.yaml old mode 100644 new mode 100755 index 1c23e6b..320caf9 --- a/pxiii_bec/device_configs/pxiii-devices.yaml +++ b/pxiii_bec/device_configs/pxiii-devices.yaml @@ -55,8 +55,8 @@ aerotech: deviceConfig: prefix: http://mx-x06da-queue-01:5234 deviceTags: - - motors - aerotech + - motors enabled: true onFailure: buffer readoutPriority: baseline @@ -66,12 +66,12 @@ aerotech: work: 0 work: null x: - in: 0 + in: -0.0 out: -10 safe: -50 y: mount: 0 - work: 0 + work: -0.01 z: mount: 0 work: 0.022 @@ -246,6 +246,43 @@ bcu_sl_yt: enabled: true onFailure: buffer readoutPriority: baseline +beam_profile_centroid: + description: Beam location and size based on AD sample camera analysis with centroid + analysis + deviceClass: pxiii_bec.devices.CentroidBeamProfile + deviceConfig: + prefix: 'X06DA-ES-MS:Stats5:' + deviceTags: + - beam + enabled: true + readoutPriority: baseline +beam_profile_gaussian: + description: Beam location and size based on AD sample camera analysis with gaussiant + fitting + deviceClass: pxiii_bec.devices.GaussianBeamProfile + deviceConfig: + prefix: 'X06DA-ES-MS:XYP1:' + deviceTags: + - beam + enabled: true + readoutPriority: baseline +beam_steering: + description: Beam location and size based on AD sample camera analysis + deviceClass: pxiii_bec.devices.BeamSteerer + deviceConfig: + hfm_step_per_x_px: -0.00013 + prefix: '' + px_tolerance: 3 + sample_loc_x_px: 1020 + sample_loc_y_px: 1010 + step_fraction: 0.7 + vfm_step_per_y_px: -0.00033 + deviceTags: + - beam + enabled: true + readoutPriority: on_request + userParameter: + profile_provider: beam_profile_centroid bl_bright: description: Backlight Brightness deviceClass: ophyd.EpicsSignal @@ -401,7 +438,7 @@ coll_y: onFailure: buffer readoutPriority: baseline userParameter: - in: 25.40 + in: 25.4 intermediate: 15 out: 4.901 park: 0 @@ -616,8 +653,8 @@ det_z: onFailure: buffer readoutPriority: baseline userParameter: - vis: 150 mse: 800 + vis: 150 diag_y: description: Scintillator/diode Y deviceClass: ophyd_devices.EpicsMotor @@ -741,6 +778,15 @@ fl_bright: 'on': 3.0 type: continuous "\u201Ctol\u201D": 0.01 +fluorimeter: + description: fluorimeter + deviceClass: pxiii_bec.devices.Fluorimeter + deviceConfig: + prefix: 'X06DA-ES-XRF:' + deviceTags: + - xrf + enabled: true + readoutPriority: on_request hfm_bd: description: HFM Downstream Bender deviceClass: ophyd_devices.EpicsMotorEC @@ -1019,8 +1065,8 @@ smargon: deviceConfig: prefix: http://x06da-smargopolo.psi.ch:3000 deviceTags: - - smargon - motors + - smargon enabled: true onFailure: buffer readoutPriority: baseline diff --git a/pxiii_bec/devices/fluorimeter.py b/pxiii_bec/devices/fluorimeter.py new file mode 100644 index 0000000..dabc146 --- /dev/null +++ b/pxiii_bec/devices/fluorimeter.py @@ -0,0 +1,30 @@ +from ophyd import DeviceStatus, EpicsSignal, Component as Cpt + +from ophyd_devices import PSIDeviceBase + +class Fluorimeter(PSIDeviceBase): + + start = Cpt(EpicsSignal, suffix="mca1Start") + stop_signal = Cpt(EpicsSignal, suffix="mca1Stop") + erase_and_start = Cpt(EpicsSignal, suffix="mca1EraseStart") + erase = Cpt(EpicsSignal, suffix="mca1Erase") + preset_mode = Cpt(EpicsSignal, suffix="dxp1:PresetMode") + status = Cpt(EpicsSignal, suffix="mca1.ACQG") + real_time = Cpt(EpicsSignal, suffix="mca1.PRTM") + live_time = Cpt(EpicsSignal, suffix="mca1.PLTM") + elapsed_real_time = Cpt(EpicsSignal, suffix="mca1.ERTM") + elapsed_live_time = Cpt(EpicsSignal, suffix="mca1.ELTM") + elapsed_trigger_live_time = Cpt(EpicsSignal, suffix="dxp1:ElapsedTriggerLiveTime") + instant_dead_time = Cpt(EpicsSignal, suffix="mca1.IDTIM") + average_dead_time = Cpt(EpicsSignal, suffix="mca1.DTIM") + poll_time_rbv = Cpt(EpicsSignal, suffix="PollTime_RBV") + poll_time = Cpt(EpicsSignal, suffix="PollTime") + mca = Cpt(EpicsSignal, suffix="mca1") + data = Cpt(EpicsSignal, suffix="mca1.VAL") + background = Cpt(EpicsSignal, suffix="mca1.BG") + saveFile = Cpt(EpicsSignal, suffix="SaveSystemFile") + saveFile_name = Cpt(EpicsSignal, suffix="SaveSystem") + saveFile_rbv = Cpt(EpicsSignal, suffix="SaveSystem_RBV") + calibration_offset = Cpt(EpicsSignal, suffix="mca1.CALO") + calibration_slope = Cpt(EpicsSignal, suffix="mca1.CALS") + diff --git a/pxiii_bec/macros/build_devices.py b/pxiii_bec/macros/build_devices.py index f731107..e804f39 100644 --- a/pxiii_bec/macros/build_devices.py +++ b/pxiii_bec/macros/build_devices.py @@ -276,7 +276,7 @@ def save_current_position( old_value = axis_params[position] print(f"Old value is {old_value}") - current_value = get_current_value(device, axis=None) + current_value = get_current_value(device, axis) delta = abs(current_value - old_value) @@ -359,4 +359,4 @@ def get_current_value(device, axis=None): signal_name = next(iter(data)) - return round(data[signal_name]["value"],3) \ No newline at end of file + return round(data[signal_name]["value"],3) diff --git a/pxiii_bec/macros/knifehist.py b/pxiii_bec/macros/knifehist.py new file mode 100644 index 0000000..920c798 --- /dev/null +++ b/pxiii_bec/macros/knifehist.py @@ -0,0 +1,79 @@ +def knife_plothist(hindex: int, signal_name: str, isave=1): + """ + Get data for a completed scan from the BEC history, + and plot all the results. + + Args: + history_index (int): scan to fetch, e.g. -1 for the most recent scan + signal_name (str): the monitor + + Example: + data_x, data_y = knife_plothist(-1,"xidode") + + scanned with + scans.line_scan(dev.aerotech.y,-0.05,0.05, steps=101, settling_time=0.5, relative=True) + """ + + from lmfit.models import LinearModel, GaussianModel, VoigtModel, QuadraticModel, LorentzianModel + import matplotlib.pyplot as plt + import numpy as np + + if hindex < 0: + h = bec.history[hindex] + print('by scan number') + else: + h = bec.history.get_by_scan_number(hindex) + print('by scan number') + + md = h.metadata["bec"] + sno = md['dataset_number'] + print(f"number of scan = {sno}") + scanvar = list(md["args"].keys())[0] # string, returns the variable of the last performed scan + # data = h.devices[device_name][signal].read()["value"] + # data_x = h.devices.dcm_pitch.dcm_pitch.read()["value"] + # data_y = h.devices.lu_bpmsum.lu_bpmsum.read()["value"] + # data_x = h.devices[device_name][device_name].read()["value"] + + # that works ... + #print(list(md['args'].keys())) + val = list(md['args'].keys()) + #val[0] = 'aerotech.x' + devicenam = val[0] + print('device = ', devicenam) + data_xd = md["positions"] # last scan knows which device ... however, double array + data_x = data_xd.flatten() + print("dx = ", data_x) + #data_y = h.devices[signal_name][signal_name].read()["value"] + data_y = h.devices["xidiode"]["xidiode"].read()["value"] + print("dy = ", data_y) + + rev = 0 + if val[0][9] == 'x': + rev = 1 + smoothplotgrad(data_x, data_y, reverse = rev) + # g, xm = justfit(data_x, data_y, model=model, ibg=ibg) + +# plt.ion() +# plt.figure() +# plt.plot(data_x, data_y, "*") +# plt.plot(data_x, g.best_fit) +# plt.xlabel(scanvar) +# plt.ylabel(signal_name) +# plt.show() + +# gcen = g.pars["center"].value + + + if isave: + ans = "n" + ans = input("Store data in csv file? y/n ") + if ans == "y": + dirname = "/sls/x06da/config/commissioning/Data/" + # writing output to simple data file for later analysis: + combined = np.column_stack((data_x, data_y)) + filename = dirname + "Scan" + str(sno) + devicenam + ".txt" + with open(filename, "w") as f: + np.savetxt(f, combined, delimiter=",", fmt="%.9e") + + + return data_x, data_y diff --git a/pxiii_bec/macros/knifehist.py~ b/pxiii_bec/macros/knifehist.py~ new file mode 100644 index 0000000..bea8744 --- /dev/null +++ b/pxiii_bec/macros/knifehist.py~ @@ -0,0 +1,79 @@ +def knife_plothist(hindex: int, signal_name: str, isave=1): + """ + Get data for a completed scan from the BEC history, + and plot all the results. + + Args: + history_index (int): scan to fetch, e.g. -1 for the most recent scan + signal_name (str): the monitor + + Example: + data_x, data_y = knife_plothist(-1,"xidode") + + scanned with + scans.line_scan(dev.aerotech.y,-0.05,0.05, steps=101, settling_time=0.5, relative=True) + """ + + from lmfit.models import LinearModel, GaussianModel, VoigtModel, QuadraticModel, LorentzianModel + import matplotlib.pyplot as plt + import numpy as np + + if hindex < 0: + h = bec.history[hindex] + print('by scan number') + else: + h = bec.history.get_by_scan_number(hindex) + print('by scan number') + + md = h.metadata["bec"] + sno = md['dataset_number'] + print(f"number of scan = {sno}") + scanvar = list(md["args"].keys())[0] # string, returns the variable of the last performed scan + # data = h.devices[device_name][signal].read()["value"] + # data_x = h.devices.dcm_pitch.dcm_pitch.read()["value"] + # data_y = h.devices.lu_bpmsum.lu_bpmsum.read()["value"] + # data_x = h.devices[device_name][device_name].read()["value"] + + # that works ... + #print(list(md['args'].keys())) + val = list(md['args'].keys()) + #val[0] = 'aerotech.x' + devicenam = val[0] + print('device = ', devicenam) + data_xd = md["positions"] # last scan knows which device ... however, double array + data_x = data_xd.flatten() + print("dx = ", data_x) + #data_y = h.devices[signal_name][signal_name].read()["value"] + data_y = h.devices["xidiode"]["xidiode"].read()["value"] + print("dy = ", data_y) + + rev = 0 + if val[0][9] == 'x': + rev = 1 + smoothplotgrad(data_x, data_y, reverse = rev) + # g, xm = justfit(data_x, data_y, model=model, ibg=ibg) + +# plt.ion() +# plt.figure() +# plt.plot(data_x, data_y, "*") +# plt.plot(data_x, g.best_fit) +# plt.xlabel(scanvar) +# plt.ylabel(signal_name) +# plt.show() + +# gcen = g.pars["center"].value + + + if isave: + ans = "n" + ans = input("Store data in csv file? y/n ") + if ans == "y": + dirname = "/sls/x10sa/config/commissioning/Data/" + # writing output to simple data file for later analysis: + combined = np.column_stack((data_x, data_y)) + filename = dirname + "Scan" + str(sno) + devicenam + ".txt" + with open(filename, "w") as f: + np.savetxt(f, combined, delimiter=",", fmt="%.9e") + + + return data_x, data_y