diff --git a/scripts/camera_stat_thread.py b/scripts/camera_stat_thread.py index 32619675..5f444731 100644 --- a/scripts/camera_stat_thread.py +++ b/scripts/camera_stat_thread.py @@ -416,16 +416,6 @@ def get_latest_image_stats(): return None -def get_latest_image_stats(): - """Get the latest image statistics including radial profile""" - global stats_receiver - - if stats_receiver and stats_receiver.latest_stats: - with stats_receiver.stats_lock: - return stats_receiver.latest_stats.copy() - return None - - def get_radial_profile(): """Get just the radial profile data""" global stats_receiver @@ -442,31 +432,3 @@ def save_current_radial_profile(filename: str = None): if stats_receiver: return stats_receiver.save_radial_profile_to_file(filename) return None - - -# # Auto-start when daq.py is imported/run -# if __name__ == "__main__": -# # If running daq.py directly -# start_image_stats_receiver() -# -# try: -# # Your existing daq.py code continues here -# print("DAQ system running with image statistics monitoring...") -# -# # Keep the program running -# while True: -# time.sleep(1) -# -# # Optional: Access latest stats in your main code -# latest = get_latest_image_stats() -# if latest and latest['message_count'] % 10 == 0: # Every 10th message -# print(f"Main thread sees: Mean={latest['mean']:.1f}") -# -# except KeyboardInterrupt: -# print("\nShutting down...") -# finally: -# stop_image_stats_receiver() -# -# else: -# # If daq.py is imported as a module, auto-start the receiver -# start_image_stats_receiver() diff --git a/src/aare/daq/auth.py b/src/aare/daq/auth.py index 8a147f40..927478b2 100644 --- a/src/aare/daq/auth.py +++ b/src/aare/daq/auth.py @@ -1,5 +1,4 @@ import grp -import ipaddress import logging import os import pwd @@ -9,7 +8,6 @@ from datetime import UTC, datetime, timedelta from typing import List import jwt -from aarecommon.config.beamline import MXBeamline, mx_beamline from aarecommon.errors.exception_handler import ( AuthenticationException, AuthErrorCode, diff --git a/src/aare/daq/server.py b/src/aare/daq/server.py index 55756fd5..9a305cdf 100644 --- a/src/aare/daq/server.py +++ b/src/aare/daq/server.py @@ -368,7 +368,7 @@ async def sample_geometry(token: str = Depends(oauth2_scheme)) -> SampleGeometry @app.put("/beamline/omega") -async def omega(val: float, token: str = Depends(oauth2_scheme)): +async def set_omega_abs(val: float, token: str = Depends(oauth2_scheme)): """ Set the omega angle of the goniometer. @@ -386,7 +386,7 @@ async def omega(val: float, token: str = Depends(oauth2_scheme)): @app.put("/beamline/omega_rel") -async def omega(val: float, token: str = Depends(oauth2_scheme)): +async def set_omega_rel(val: float, token: str = Depends(oauth2_scheme)): """ Move the omega angle relatively. @@ -835,28 +835,6 @@ async def local_contact_set_config( return daq.set_local_contact_config(payload) -@app.get("/local_contact/config") -async def local_contact_config(token: str = Depends(oauth2_scheme)) -> LocalContactConfigModel: - """ - Return Local Contact config values. Staff only. - """ - data = auth.parse_token(token) - auth.check_jwt_staff_only(data) - return daq.get_local_contact_config() - - -@app.put("/local_contact/config") -async def local_contact_set_config( - payload: LocalContactConfigModel, token: str = Depends(oauth2_scheme) -) -> LocalContactConfigModel: - """ - Update Local Contact config values. Staff only. - """ - data = auth.parse_token(token) - auth.check_jwt_staff_only(data) - return daq.set_local_contact_config(payload) - - @app.post("/beamline/goto_abr_meas_pos") async def goto_abr_meas_pos(token: str = Depends(oauth2_scheme)): """ @@ -1341,7 +1319,7 @@ async def dewar_exchange(token: str = Depends(oauth2_scheme)): @app.post("/state/sample_exchange") -async def dewar_exchange(token: str = Depends(oauth2_scheme)): +async def sample_exchange(token: str = Depends(oauth2_scheme)): """ Transition beamline state to SampleExchange. @@ -1432,7 +1410,7 @@ async def data_collection(token: str = Depends(oauth2_scheme)): @app.post("/state/robot_sample_exchange") -async def dewar_exchange(token: str = Depends(oauth2_scheme)): +async def robot_sample_exchange(token: str = Depends(oauth2_scheme)): """ Transition beamline state to SampleExchange. @@ -1463,7 +1441,7 @@ async def xray_fluorescence(token: str = Depends(oauth2_scheme)): @app.post("/state/xtal_snapshot") -async def beam_location(token: str = Depends(oauth2_scheme)): +async def xtal_snapshot(token: str = Depends(oauth2_scheme)): """ Transition beamline state to BeamLocation. Staff only. @@ -1474,23 +1452,6 @@ async def beam_location(token: str = Depends(oauth2_scheme)): daq.state = BeamlineStateEnum.XtalSnapshot -@app.post("/state/maintenance") -async def maintenance(token: str = Depends(oauth2_scheme)) -> str: - """ - Transition beamline state to Maintenance. Staff only. - - Args: - token: OAuth2 access token. - - Returns: - "OK" on success. - """ - auth.check_jwt_staff(cfg, auth.parse_token(token)) - cfg.state = BeamlineStateEnum.Maintenance - logger.warning("Beamline state set to Maintenance via protected endpoint.") - return "OK" - - @app.post("/access/take_over_beamline") async def take_over_beamline( payload: RecoveryActionRequest, token: str = Depends(oauth2_scheme) diff --git a/src/aare/devices/area_detector.py b/src/aare/devices/area_detector.py index 7dd4a120..b5104ed2 100644 --- a/src/aare/devices/area_detector.py +++ b/src/aare/devices/area_detector.py @@ -61,7 +61,8 @@ class epicsAD(object): try: epics.ca.pend_io() - except: + except Exception as e: + print(f"EPICS error: {e}") pass def _init_auto_exp(self, settings: AutoExposureSettings = AutoExposureSettings()): diff --git a/src/aare/devices/bec_worker.py b/src/aare/devices/bec_worker.py index a7f37e2f..dff3010e 100644 --- a/src/aare/devices/bec_worker.py +++ b/src/aare/devices/bec_worker.py @@ -12,6 +12,9 @@ from bec_ipython_client.signals import OperationMode from bec_lib.device import RPCError, ScanRequestError from bec_lib.procedures.helper import FrontendProcedureHelper from bec_lib.service_config import ServiceConfig +from pxii_bec.macros.build_devices import save_and_reload, save_current_position +from pxii_bec.macros.init_beamline import init_beamline_environment +from pxii_bec.macros.pxii_energy import bl_energy, get_current_energy, mono_pitch_scan logger = setup_logger("aareDAQ") diff --git a/src/aare/devices/jfjoch.py b/src/aare/devices/jfjoch.py index f6f8edff..d4ecf250 100644 --- a/src/aare/devices/jfjoch.py +++ b/src/aare/devices/jfjoch.py @@ -9,6 +9,8 @@ from aarecommon.models.beamline import MXBeamline from aarecommon.models.models import DAQStatusModel, FluorescenceSpectrumOutputModel from aarecommon.models.raster_grid import RasterGridRequest from aarecommon.models.rotation_scan import RotationScanRequest +from jfjoch_client.api.default_api import DefaultApi +from jfjoch_client.api_client import ApiClient class ScanTypeEnum(Enum): @@ -26,8 +28,10 @@ class JFJochWrapper: self._url = get_jfjoch_url(bl) if self._url == "simulated": - self._client = None - self._api = None + from unittest.mock import MagicMock + + self._client = MagicMock(spec=ApiClient) + self._api = MagicMock(spec=DefaultApi) return self._client = jfjoch_client.ApiClient(jfjoch_client.Configuration(host=self._url))