style: ruff format

This commit is contained in:
2026-07-27 14:45:12 +02:00
parent 5f1a09a1e9
commit 0451b8cebb
14 changed files with 114 additions and 77 deletions
+5 -6
View File
@@ -42,11 +42,8 @@ from aarecommon.models.models import (
)
from aare.daq.config_model import LocalContactConfigModel
#TODO WHAT SHOULD THIS BE? This should be in the YAMl file it is beamline specific
ABR_POS_MOUNT = AerotechCoordinate(
at_mm=Coordinate(x=0, y=0, z=0),
omega_deg=0
)
# TODO WHAT SHOULD THIS BE? This should be in the YAMl file it is beamline specific
ABR_POS_MOUNT = AerotechCoordinate(at_mm=Coordinate(x=0, y=0, z=0), omega_deg=0)
# TODO WHAT SHOULD THIS BE? This should be in the YAMl file it is beamline specific
@@ -1261,7 +1258,9 @@ class BeamlineConfig:
logger.warning(f"Failed to read Local Contact config from Redis: {e}")
return default
def set_local_contact_config(self, config: LocalContactConfigModel | dict) -> LocalContactConfigModel:
def set_local_contact_config(
self, config: LocalContactConfigModel | dict
) -> LocalContactConfigModel:
validated = LocalContactConfigModel.model_validate(config)
try:
redis_key = f"{self.__bl}:local_contact_config"
+33 -23
View File
@@ -1385,8 +1385,9 @@ class AareDAQ:
)
return None
def _execute_rotation_sequence(self, rotation_request: RotationScanRequest) -> CompletedRotationScan | None:
def _execute_rotation_sequence(
self, rotation_request: RotationScanRequest
) -> CompletedRotationScan | None:
"""
Execute rotation scan.
@@ -1574,19 +1575,21 @@ class AareDAQ:
self.last_time = end - start
def _expand_macros(self, name: str) -> str:
name = name.replace('{date}', datetime.now().strftime('%Y%m%d'))
name = name.replace('{sample}', self.sample.sample_name)
name = name.replace('{CrystalName}', self.sample.sample_name)
name = name.replace('{puck}', self.sample.puck_name)
name = name.replace('{position}', f"{self.sample.pin:02d}")
name = name.replace('{sample_id}', f"{self.sample.db_id}")
name = name.replace('{beamline}', f"{self._beamline.value.lower()}")
name = name.replace('{prefix}', f"{self.sample.puck_name}/{self.sample.pin:02d}/{self.sample.sample_name}")
#TODO work out why clean_filename is removing slahses
#name = clean_filename(name)
name = name.replace("{date}", datetime.now().strftime("%Y%m%d"))
name = name.replace("{sample}", self.sample.sample_name)
name = name.replace("{CrystalName}", self.sample.sample_name)
name = name.replace("{puck}", self.sample.puck_name)
name = name.replace("{position}", f"{self.sample.pin:02d}")
name = name.replace("{sample_id}", f"{self.sample.db_id}")
name = name.replace("{beamline}", f"{self._beamline.value.lower()}")
name = name.replace(
"{prefix}", f"{self.sample.puck_name}/{self.sample.pin:02d}/{self.sample.sample_name}"
)
# TODO work out why clean_filename is removing slahses
# name = clean_filename(name)
return name
def spreadsheet_params(self) -> tuple[Optional[SimpleScanParameters], str|None]:
def spreadsheet_params(self) -> tuple[Optional[SimpleScanParameters], str | None]:
file_prefix = None
if self.status.sample is None:
@@ -1979,7 +1982,7 @@ class AareDAQ:
self.save_screenshot_db(sample_id, screenshot_name)
if request.transmission is not None and request.transmission != self.__devs.transmission:
logger.info(f'requesting transmission to move to {request.transmission}')
logger.info(f"requesting transmission to move to {request.transmission}")
self.__devs.transmission = request.transmission
start_pos = getattr(request, "start", None)
@@ -2700,7 +2703,9 @@ class AareDAQ:
if raster_params.filename is not None:
logger.info(f"Using filename {raster_params.filename}")
sample_prefix = "{filename}/{prefix}".format(filename=raster_params.filename, prefix=sample.sample_name)
sample_prefix = "{filename}/{prefix}".format(
filename=raster_params.filename, prefix=sample.sample_name
)
raster_grid = RasterGridRequest(
exp_time_s=raster_params.exp_time_s,
@@ -2767,17 +2772,20 @@ class AareDAQ:
update_sample = self.sample
if (
update_sample is not None
and update_sample.db_id is not None
and update_sample.db_id == sample.db_id
update_sample is not None
and update_sample.db_id is not None
and update_sample.db_id == sample.db_id
):
logger.info(f"Updating sample info {sample.db_id} old run_number"
f" sample.run_number {sample.run_number} new run_number {update_sample.run_number}")
logger.info(
f"Updating sample info {sample.db_id} old run_number"
f" sample.run_number {sample.run_number} new run_number {update_sample.run_number}"
)
if params.filename is not None:
logger.info(f"Using filename {params.filename}")
sample_prefix = "{filename}/{prefix}".format(filename=params.filename, prefix=sample.sample_name)
sample_prefix = "{filename}/{prefix}".format(
filename=params.filename, prefix=sample.sample_name
)
rotation_request = RotationScanRequest(
start_omega_deg=start_omega,
@@ -3492,7 +3500,9 @@ class AareDAQ:
finally:
self.__cfg.state_busy = False
def fluorimeter_take_spectrum(self, fm: FluorescenceSpectrumParameterModel) -> FluorescenceSpectrumOutputModel:
def fluorimeter_take_spectrum(
self, fm: FluorescenceSpectrumParameterModel
) -> FluorescenceSpectrumOutputModel:
self.__cfg.try_set_busy(timeout=360)
try:
+1 -5
View File
@@ -120,11 +120,7 @@ class PShellTellBackend:
if e.response is not None and e.response.text:
msg = e.response.text.strip()
raise TellCommunicationError(
msg,
base_url=self._url,
endpoint=endpoint,
operation=operation,
critical=True,
msg, base_url=self._url, endpoint=endpoint, operation=operation, critical=True
) from e
def eval(self, expr: str):
+3 -1
View File
@@ -359,7 +359,9 @@ class TellClient:
raise
except Exception as e:
logger.error(f"Exception occurred: {e}")
raise TellCommunicationError(message=f"Error during mount {segment}{puck}-{sample}: {e}", critical=True)
raise TellCommunicationError(
message=f"Error during mount {segment}{puck}-{sample}: {e}", critical=True
)
def unmount(self, force=False, wait=False, timeout=360.0):
if self.is_busy():
+1 -1
View File
@@ -2493,6 +2493,6 @@ class MainWindow(QMainWindow):
"Idle timeout reached, but GUI remains open because beamline is busy or automation is active."
)
return
#TODO deny communication from GUI to DAQ while IDLE for too long rather than kill the GUI
# TODO deny communication from GUI to DAQ while IDLE for too long rather than kill the GUI
logger.warning("Closing GUI after inactivity timeout.")
self.close()
+10 -8
View File
@@ -86,14 +86,16 @@ class FilePathPanel(QWidget):
def _expand_macros(self, base: str, rn: int) -> str:
name = f"{base}_{rn:03d}"
name = name.replace('{date}', self.__formatted_date)
name = name.replace('{sample}', self.__sample_name)
name = name.replace('{CrystalName}', self.__sample_name)
name = name.replace('{puck}', self.__puck_name)
name = name.replace('{position}', f"{self.__puck_pos:02d}")
name = name.replace('{sample_id}', f"{self.__sample_id}")
name = name.replace('{beamline}', f"{self.__beamline}")
name = name.replace('{prefix}', f"{self.__puck_name}/{self.__puck_pos:02d}/{self.__sample_name}")
name = name.replace("{date}", self.__formatted_date)
name = name.replace("{sample}", self.__sample_name)
name = name.replace("{CrystalName}", self.__sample_name)
name = name.replace("{puck}", self.__puck_name)
name = name.replace("{position}", f"{self.__puck_pos:02d}")
name = name.replace("{sample_id}", f"{self.__sample_id}")
name = name.replace("{beamline}", f"{self.__beamline}")
name = name.replace(
"{prefix}", f"{self.__puck_name}/{self.__puck_pos:02d}/{self.__sample_name}"
)
return name
def _effective_dataset_base(self, base_no_run: str) -> str:
+15 -4
View File
@@ -22,7 +22,7 @@ from PySide6.QtWidgets import (
QTabWidget,
QTextEdit,
QVBoxLayout,
QWidget,
QWidget,
)
from aare.gui.constants import LOGGER_NAME
@@ -333,11 +333,22 @@ class LocalContactPanel(QFrame):
tools_layout.addWidget(tools)
tools_layout.addWidget(
self._make_button("Load BEC user macros", self._daq.bec_load_user_macros, "Loading BEC user macros."))
self._make_button(
"Load BEC user macros", self._daq.bec_load_user_macros, "Loading BEC user macros."
)
)
tools_layout.addWidget(
self._make_button("Show BEC user macros", self._daq.bec_list_all_user_macros, "Listing BEC user macros."))
self._make_button(
"Show BEC user macros",
self._daq.bec_list_all_user_macros,
"Listing BEC user macros.",
)
)
tools_layout.addWidget(
self._make_button("Show BEC position devices", self._daq.bec_list_all_devices, "Listing BEC devices."))
self._make_button(
"Show BEC position devices", self._daq.bec_list_all_devices, "Listing BEC devices."
)
)
tools_layout.addWidget(
self._make_button(
"Reinitialise BEC planner/devices",
@@ -31,15 +31,14 @@ class RasterDataCollectionPanel(ScanSettingsPanel):
raster_alpha_changed = Signal(int)
def __init__(
self,
raster_mgr: RasterGridManager,
diffraction: DiffractionGeometry,
parent=None,
self, raster_mgr: RasterGridManager, diffraction: DiffractionGeometry, parent=None
):
super().__init__(diffraction=diffraction,
default_dtz=raster_mgr.active_grid.dtz,
default_transmission=raster_mgr.active_grid.transmission,
parent=parent)
super().__init__(
diffraction=diffraction,
default_dtz=raster_mgr.active_grid.dtz,
default_transmission=raster_mgr.active_grid.transmission,
parent=parent,
)
self._previous_sample_was_none_raster = True
+30 -11
View File
@@ -39,8 +39,13 @@ class RotationDataCollectionPanel(ScanSettingsPanel):
super().__init__(
parent=parent,
diffraction=diffraction,
default_dtz=cfg_get("daq.data_collection_settings.default_rotation_settings.dtz", default_dtz),
default_transmission=cfg_get("daq.data_collection_settings.default_rotation_settings.transmission", default_transmission),
default_dtz=cfg_get(
"daq.data_collection_settings.default_rotation_settings.dtz", default_dtz
),
default_transmission=cfg_get(
"daq.data_collection_settings.default_rotation_settings.transmission",
default_transmission,
),
)
self.__beamline_state = None
@@ -71,8 +76,12 @@ class RotationDataCollectionPanel(ScanSettingsPanel):
self._layout.addWidget(QLabel("°", parent=self), 5, 4)
self._layout.addWidget(QLabel("Image time", parent=self), 6, 0)
default_screening_exp_time = cfg_get("daq.data_collection_settings.default_screening_settings.exp_time_s", 0.1)
self.screening_image_time_enter = NumberLineEdit(0.0005, 10.0, default_screening_exp_time, decimals=4, parent=self)
default_screening_exp_time = cfg_get(
"daq.data_collection_settings.default_screening_settings.exp_time_s", 0.1
)
self.screening_image_time_enter = NumberLineEdit(
0.0005, 10.0, default_screening_exp_time, decimals=4, parent=self
)
self._layout.addWidget(self.screening_image_time_enter, 6, 1, 1, 3)
self._layout.addWidget(QLabel("s", parent=self), 6, 4)
@@ -96,22 +105,32 @@ class RotationDataCollectionPanel(ScanSettingsPanel):
)
self._layout.addWidget(QLabel("Total angle", parent=self), 10, 0)
default_steps = cfg_get("daq.data_collection_settings.default_rotation_settings.steps", 1800)
default_increment_omega = cfg_get("daq.data_collection_settings.default_rotation_settings.increment_omega_deg", 0.2)
default_total_angle = default_steps*default_increment_omega
self.total_angle = DbOverrideLineEdit(0, 9999.0, default=default_total_angle, decimals=3, parent=self)
default_steps = cfg_get(
"daq.data_collection_settings.default_rotation_settings.steps", 1800
)
default_increment_omega = cfg_get(
"daq.data_collection_settings.default_rotation_settings.increment_omega_deg", 0.2
)
default_total_angle = default_steps * default_increment_omega
self.total_angle = DbOverrideLineEdit(
0, 9999.0, default=default_total_angle, decimals=3, parent=self
)
self._layout.addWidget(self.total_angle, 10, 1, 1, 3)
self._layout.addWidget(QLabel("°", parent=self), 10, 4)
self._register_override_field(self.total_angle)
self._layout.addWidget(QLabel("Image angle", parent=self), 11, 0)
self.image_angle = DbOverrideLineEdit(0, 10.0, default=default_increment_omega, decimals=3, parent=self)
self.image_angle = DbOverrideLineEdit(
0, 10.0, default=default_increment_omega, decimals=3, parent=self
)
self._layout.addWidget(self.image_angle, 11, 1, 1, 3)
self._layout.addWidget(QLabel("°", parent=self), 11, 4)
self._register_override_field(self.image_angle)
# TODO add protection on X10SA to prevent too short exposure time/ too high detector rep rate
self._layout.addWidget(QLabel("Image time", parent=self), 12, 0)
default_image_exp_time = cfg_get("daq.data_collection_settings.default_rotation_settings.exp_time_s", 0.01)
default_image_exp_time = cfg_get(
"daq.data_collection_settings.default_rotation_settings.exp_time_s", 0.01
)
self.image_time_enter = DbOverrideLineEdit(
0.0005, 10.0, default=default_image_exp_time, decimals=4, parent=self
)
@@ -145,7 +164,7 @@ class RotationDataCollectionPanel(ScanSettingsPanel):
self.measurement_button.clicked.connect(self.run_measurement)
self._layout.addWidget(self.measurement_button, 16, 0, 1, 6)
self._reset_to_defaults()
@Slot()
def run_screening(self):
if self.__beamline_state != BeamlineStateEnum.SampleAlignment:
+1 -1
View File
@@ -196,7 +196,7 @@ class ScanSettingsPanel(QWidget):
else:
if not self._previous_sample_was_none:
logger.info("Sample cleared, resetting parameters to defaults")
#self._reset_to_defaults()
# self._reset_to_defaults()
self._previous_sample_was_none = True # Mark that sample is now None
self._sample = None
@@ -140,8 +140,12 @@ class RasterGridManager(QObject):
smargon_top_left=self.__geom.smargon,
grid_size_mm=Coordinate(x=0.8 * self.__beam_size_mm.x, y=0.8 * self.__beam_size_mm.y),
omega_deg=self.__geom.omega_deg,
exp_time_s=cfg_get("daq.data_collection_settings.default_raster_settings.exp_time_s", 0.01),
transmission=cfg_get("daq.data_collection_settings.default_raster_settings.transmission", 1.0),
exp_time_s=cfg_get(
"daq.data_collection_settings.default_raster_settings.exp_time_s", 0.01
),
transmission=cfg_get(
"daq.data_collection_settings.default_raster_settings.transmission", 1.0
),
dtz=cfg_get("daq.data_collection_settings.default_raster_settings.dtz", 200.0),
)
self.__completed_grids: List[CompletedRasterGridElem] = []
@@ -3,7 +3,6 @@ from aarecommon.models.rotation_scan import CompletedRotationScan
from PySide6.QtCore import QObject, Signal, Slot
class RotationScanManager(QObject):
file_ready = Signal(str, int)
+1 -6
View File
@@ -23,12 +23,7 @@ with patch.dict("os.environ", {"JWT_AAREDAQ_KEY": "test_secret"}):
respond_to_baton_request,
)
from aarecommon.errors.exception_handler import AuthenticationException, UserRightsException
from aarecommon.models.auth import (
BatonHolderInfo,
BatonRequest,
BatonRequestStatus,
BatonStatus,
)
from aarecommon.models.auth import BatonHolderInfo, BatonRequest, BatonRequestStatus, BatonStatus
from aarecommon.models.models import SessionsStateEnum
+1
View File
@@ -31,6 +31,7 @@ def test_timer_box_auto_accept(qtbot):
assert box.result() == QMessageBox.StandardButton.Yes
@pytest.mark.timeout(10)
def test_ring_current_low_check_ok(qtbot):
# Should return True immediately if current is high enough