From 41a4e281af40aa02fa83f5d1007b84d9415bc8c0 Mon Sep 17 00:00:00 2001 From: x06da Date: Sun, 4 Oct 2026 16:56:37 +0200 Subject: [PATCH] updated utiliry files --- pxiii_bec/macros/mxcomm_analysis.py | 6 ++-- pxiii_bec/macros/mxcomm_data.py | 37 ++++++++++++-------- pxiii_bec/macros/mxcomm_utils.py | 54 ++++++++++++++++------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/pxiii_bec/macros/mxcomm_analysis.py b/pxiii_bec/macros/mxcomm_analysis.py index f12d466..26c183e 100644 --- a/pxiii_bec/macros/mxcomm_analysis.py +++ b/pxiii_bec/macros/mxcomm_analysis.py @@ -166,8 +166,10 @@ def check_peak_fit(x_data, result, min_fwhm_steps=3): centre = result["centre"] fwhm = result["fwhm"] - step_size = np.mean(np.diff(x_data)) - fwhm_steps = result["fwhm"] / abs(step_size) + # step_size = np.mean(np.diff(x_data)) + # fwhm_steps = result["fwhm"] / abs(step_size) + + fwhm_steps = fwhm / step problems = [] diff --git a/pxiii_bec/macros/mxcomm_data.py b/pxiii_bec/macros/mxcomm_data.py index b01b6ba..a718c63 100644 --- a/pxiii_bec/macros/mxcomm_data.py +++ b/pxiii_bec/macros/mxcomm_data.py @@ -76,22 +76,31 @@ def get_value(dev_name, details=False): Returns: value or full details """ + # if dev_name == dev.scam: + # root = "scam" + # live_root = "scam" + # name = "scam_contrast" + # value = dev_name.read(cached=True)[name]["value"] + # else: + # try: + # name = live_root = root = dev_name.name + # value = dev_name.read(cached=True)[name]["value"] + # except: + # print("non-standard device") + # root = dev_name.dotted_name + # name = dev_name.full_name + # live_root = dev_name.parent.name + # value = dev_name.read(cached=True)[name]["value"] - if dev_name == dev.scam: - root = "scam" - live_root = "scam" - name = "scam_contrast" + try: + name = live_root = root = dev_name.name + value = dev_name.read(cached=True)[name]["value"] + except: + print("non-standard device") + root = dev_name.dotted_name + name = dev_name.full_name + live_root = dev_name.parent.name value = dev_name.read(cached=True)[name]["value"] - else: - try: - name = live_root = root = dev_name.name - value = dev_name.read(cached=True)[name]["value"] - except: - print("non-standard device") - root = dev_name.dotted_name - name = dev_name.full_name - live_root = dev_name.parent.name - value = dev_name.read(cached=True)[name]["value"] if details: return {"value": value, "root": root, "name": name, "live_root": live_root} diff --git a/pxiii_bec/macros/mxcomm_utils.py b/pxiii_bec/macros/mxcomm_utils.py index db6fc76..4d2c33e 100644 --- a/pxiii_bec/macros/mxcomm_utils.py +++ b/pxiii_bec/macros/mxcomm_utils.py @@ -4,44 +4,48 @@ import epics import time import numpy as np import matplotlib.pyplot as plt - +from pxiii_bec.scripts import beamline_context as bl +from pxiii_bec.macros.beamline_planner import BeamlineState # ============================================================================= # Camera utilities # ============================================================================= -def predict_scint_transmission(target_flux=None): - """Predict transmission required for a scintillator measurement.""" +# def predict_scint_transmission(target_flux=None): +# """ +# Predict transmission required for a scintillator measurement. +# Not required on PXIII +# """ - if target_flux is None: - target_flux = BeamMove.scint_target_flux +# if target_flux is None: +# target_flux = BeamMove.scint_target_flux - _, full_flux = bpm2flux() +# _, full_flux = bpm2flux() - if not np.isfinite(full_flux) or full_flux <= 0: - raise ValueError( - f"Cannot predict scintillator transmission: " - f"invalid full flux ({full_flux:.3g} ph/s)" - ) +# if not np.isfinite(full_flux) or full_flux <= 0: +# raise ValueError( +# f"Cannot predict scintillator transmission: " +# f"invalid full flux ({full_flux:.3g} ph/s)" +# ) - transmission = target_flux / full_flux +# transmission = target_flux / full_flux - # Prevent an unreasonable attenuator setting - transmission = np.clip(transmission, 0.001, 1.0) +# # Prevent an unreasonable attenuator setting +# transmission = np.clip(transmission, 0.001, 1.0) - return float(transmission) +# return float(transmission) def prepare_scint_measurement(autoexp=True, zoom=1000): """Prepare for taking a reading of the beam from the scintillator""" - # set transmission - transmission = predict_scint_transmission() - print( - f"Predicted scintillator transmission: " - f"{transmission:.2%}" - ) - dev.transm.put(transmission) - time.sleep(3) + # # set transmission + # transmission = predict_scint_transmission() + # print( + # f"Predicted scintillator transmission: " + # f"{transmission:.2%}" + # ) + # dev.transm.put(transmission) + # time.sleep(3) # set camera zoom @@ -49,8 +53,8 @@ def prepare_scint_measurement(autoexp=True, zoom=1000): umv(dev.scam_zoom, zoom) # move to beam visualisation - if not planner.is_state(BeamlineState.BEAM_VISUALISATION): - planner.move_to(BeamlineState.BEAM_VISUALISATION) + if not bl.planner.is_state(BeamlineState.BEAM_VISUALISATION): + bl.planner.move_to(BeamlineState.BEAM_VISUALISATION) # open shutter dev.bcu_shutter.put(1)