Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I24 serial: commissioning fixes #645

Merged
merged 20 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions src/mx_bluesky/beamlines/i24/serial/dcid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import json
import logging
import math
import os
import re
Expand All @@ -10,6 +9,7 @@

import requests

from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER
from mx_bluesky.beamlines.i24.serial.parameters import SSXType
from mx_bluesky.beamlines.i24.serial.setup_beamline import (
Detector,
Expand All @@ -25,8 +25,6 @@
except ImportError:
pass

logger = logging.getLogger("I24ssx.DCID")


# Collection start/end script to kick off analysis
COLLECTION_START_SCRIPT = "/dls_sw/i24/scripts/RunAtStartOfCollect-i24-ssx.sh"
Expand All @@ -41,7 +39,7 @@
def get_auth_header() -> dict:
"""Read the credentials file and build the Authorisation header"""
if not os.path.isfile(CREDENTIALS_LOCATION):
logger.warning(
SSX_LOGGER.warning(

Check warning on line 42 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L42

Added line #L42 was not covered by tests
"Could not read %s; attempting to proceed without credentials",
CREDENTIALS_LOCATION,
)
Expand Down Expand Up @@ -205,12 +203,12 @@

# Log what we are doing here
try:
logger.info(
SSX_LOGGER.info(

Check warning on line 206 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L206

Added line #L206 was not covered by tests
"BRIDGE: POST /dc --data %s",
repr(json.dumps(data)),
)
except Exception:
logger.info(
SSX_LOGGER.info(

Check warning on line 211 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L211

Added line #L211 was not covered by tests
"Caught exception converting data to JSON. Data:\n%s\nVERBOSE:\n%s",
str({k: type(v) for k, v in data.items()}),
)
Expand All @@ -224,20 +222,20 @@
)
resp.raise_for_status()
self.dcid = resp.json()["dataCollectionId"]
logger.info("Generated DCID %s", self.dcid)
SSX_LOGGER.info("Generated DCID %s", self.dcid)

Check warning on line 225 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L225

Added line #L225 was not covered by tests
except requests.HTTPError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have some tests for this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding them in #627 , which is actually changing the code in this file so while I may add them here they would go away in a couple of hours?

self.error = True
logger.error(
SSX_LOGGER.error(

Check warning on line 228 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L228

Added line #L228 was not covered by tests
"DCID generation Failed; Reason from server: %s", e.response.text
)
if self.emit_errors:
raise
logger.exception("Error generating DCID: %s", e)
SSX_LOGGER.exception("Error generating DCID: %s", e)

Check warning on line 233 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L233

Added line #L233 was not covered by tests
except Exception as e:
self.error = True
if self.emit_errors:
raise
logger.exception("Error generating DCID: %s", e)
SSX_LOGGER.exception("Error generating DCID: %s", e)

Check warning on line 238 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L238

Added line #L238 was not covered by tests

def __int__(self):
return self.dcid
Expand All @@ -248,27 +246,27 @@
return None
try:
command = [COLLECTION_START_SCRIPT, str(self.dcid)]
logger.info("Running %s", " ".join(command))
SSX_LOGGER.info("Running %s", " ".join(command))

Check warning on line 249 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L249

Added line #L249 was not covered by tests
subprocess.Popen(command)
except Exception as e:
self.error = True
if self.emit_errors:
raise
logger.warning("Error starting start of collect script: %s", e)
SSX_LOGGER.warning("Error starting start of collect script: %s", e)

Check warning on line 255 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L255

Added line #L255 was not covered by tests

def notify_end(self):
"""Send notifications that the collection has now ended"""
if self.dcid is None:
return
try:
command = [COLLECTION_END_SCRIPT, str(self.dcid)]
logger.info("Running %s", " ".join(command))
SSX_LOGGER.info("Running %s", " ".join(command))

Check warning on line 263 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L263

Added line #L263 was not covered by tests
subprocess.Popen(command)
except Exception as e:
self.error = True
if self.emit_errors:
raise
logger.warning("Error running end of collect notification: %s", e)
SSX_LOGGER.warning("Error running end of collect notification: %s", e)

Check warning on line 269 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L269

Added line #L269 was not covered by tests

def collection_complete(
self, end_time: str | datetime.datetime | None = None, aborted: bool = False
Expand All @@ -285,7 +283,7 @@
# end_time might be a string from time.ctime
if isinstance(end_time, str):
end_time = datetime.datetime.strptime(end_time, "%a %b %d %H:%M:%S %Y")
logger.debug("Parsed end time: %s", end_time)
SSX_LOGGER.debug("Parsed end time: %s", end_time)

Check warning on line 286 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L286

Added line #L286 was not covered by tests

if not end_time:
end_time = datetime.datetime.now().astimezone()
Expand All @@ -302,13 +300,13 @@
if self.dcid is None:
# Print what we would have sent. This means that if something is failing,
# we still have the data to upload in the log files.
logger.info(
SSX_LOGGER.info(

Check warning on line 303 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L303

Added line #L303 was not covered by tests
'BRIDGE: No DCID but Would PATCH "/dc/XXXX" --data=%s',
repr(json.dumps(data)),
)
return

logger.info(
SSX_LOGGER.info(

Check warning on line 309 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L309

Added line #L309 was not covered by tests
'BRIDGE: PATCH "/dc/%s" --data=%s', self.dcid, repr(json.dumps(data))
)
response = requests.patch(
Expand All @@ -318,7 +316,7 @@
headers=get_auth_header(),
)
response.raise_for_status()
logger.info("Successfully updated end time for DCID %d", self.dcid)
SSX_LOGGER.info("Successfully updated end time for DCID %d", self.dcid)

Check warning on line 319 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L319

Added line #L319 was not covered by tests
except Exception as e:
resp_obj = getattr(e, "response", None)
try:
Expand All @@ -333,7 +331,7 @@
self.error = True
if self.emit_errors:
raise
logger.warning("Error completing DCID: %s (%s)", e, resp_str)
SSX_LOGGER.warning("Error completing DCID: %s (%s)", e, resp_str)

Check warning on line 334 in src/mx_bluesky/beamlines/i24/serial/dcid.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/dcid.py#L334

Added line #L334 was not covered by tests


def get_pilatus_filename_template_from_pvs() -> str:
Expand Down Expand Up @@ -385,9 +383,9 @@
h_mode = caget("BL24I-OP-MFM-01:G1:TARGETAPPLY")
# Validate these and note an error otherwise
if not v_mode.startswith("VMFM") or v_mode[4:] not in focus_modes:
logger.error("Unrecognised vertical beam mode %s", v_mode)
SSX_LOGGER.error("Unrecognised vertical beam mode %s", v_mode)
if not h_mode.startswith("HMFM") or h_mode[4:] not in focus_modes:
logger.error("Unrecognised horizontal beam mode %s", h_mode)
SSX_LOGGER.error("Unrecognised horizontal beam mode %s", h_mode)
_, h, _ = focus_modes.get(h_mode[4:], (None, None, None))
_, _, v = focus_modes.get(v_mode[4:], (None, None, None))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def main_extruder_plan(
SSX_LOGGER.info("Using Eiger detector")

SSX_LOGGER.debug(f"Creating the directory for the collection in {filepath}.")
Path(filepath).mkdir(parents=True)
Path(filepath).mkdir(parents=True, exist_ok=True)

caput(pv.eiger_seqID, int(caget(pv.eiger_seqID)) + 1)
SSX_LOGGER.info(f"Eiger quickshot setup: filepath {filepath}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
Returns:
The estimated collection time, in s.
"""
buffer = PMAC_MOVE_TIME * parameters.total_num_images + 2
buffer = PMAC_MOVE_TIME * parameters.total_num_images + 600
pump_setting = parameters.pump_repeat
collection_time = parameters.total_num_images * parameters.exposure_time_s
if pump_setting in [
Expand All @@ -97,7 +97,7 @@
)
if pump_setting == PumpProbeSetting.Medium1:
# Long delay between pump and probe, with fast shutter opening and closing.
timeout = timeout + SHUTTER_OPEN_TIME
timeout = timeout + SHUTTER_OPEN_TIME * parameters.total_num_images

Check warning on line 100 in src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py#L100

Added line #L100 was not covered by tests
return timeout


Expand Down Expand Up @@ -426,7 +426,11 @@
)

SSX_LOGGER.debug("Arm Pilatus. Arm Zebra.")
shutter_time_offset = SHUTTER_OPEN_TIME if PumpProbeSetting.Medium1 else 0.0
shutter_time_offset = (

Check warning on line 429 in src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py#L429

Added line #L429 was not covered by tests
SHUTTER_OPEN_TIME
if parameters.pump_repeat is PumpProbeSetting.Medium1
else 0.0
)
yield from setup_zebra_for_fastchip_plan(
zebra,
parameters.detector_name,
Expand All @@ -449,7 +453,7 @@
SSX_LOGGER.info("Using Eiger detector")

SSX_LOGGER.debug(f"Creating the directory for the collection in {filepath}.")
Path(filepath).mkdir(parents=True)
Path(filepath).mkdir(parents=True, exist_ok=True)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we only create the directory for the eiger and not the pilatus?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the Pilatus creates its own directories, while the Eiger doesn't, so there's no need to explicitly create it. Until a few weeks ago - when we started running as i24detector on procserv - this one line was actually triggering a one image collection from the Pilatus just to get the directory....

SSX_LOGGER.info(f"Triggered Eiger setup: filepath {filepath}")
SSX_LOGGER.info(f"Triggered Eiger setup: filename {filename}")
Expand Down Expand Up @@ -485,7 +489,11 @@
)

SSX_LOGGER.debug("Arm Zebra.")
shutter_time_offset = SHUTTER_OPEN_TIME if PumpProbeSetting.Medium1 else 0.0
shutter_time_offset = (
SHUTTER_OPEN_TIME
if parameters.pump_repeat is PumpProbeSetting.Medium1
else 0.0
)
yield from setup_zebra_for_fastchip_plan(
zebra,
parameters.detector_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
sleep(0.1)
SSX_LOGGER.info("Clearing General Purpose PVs 1-120")
for i in range(4, 120):
if i == 100:
# Do not clear visit PV
continue
pvar = "ME14E-MO-IOC-01:GP" + str(i)
caput(pvar, 0)
sys.stdout.write(".")
Expand Down Expand Up @@ -840,13 +843,13 @@
sleep(2.5)
yield from set_pmac_strings_for_cs(pmac, {"cs1": cs1, "cs2": cs2, "cs3": cs3})
yield from bps.trigger(pmac.to_xyz_zero)
sleep(0.1)
sleep(2.5)

Check warning on line 846 in src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py#L846

Added line #L846 was not covered by tests
yield from bps.trigger(pmac.home, wait=True)
sleep(0.1)
sleep(2.5)

Check warning on line 848 in src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py#L848

Added line #L848 was not covered by tests
SSX_LOGGER.debug(f"Chip_type is {chip_type}")
if chip_type == 0:
yield from bps.abs_set(pmac.pmac_string, "!x0.4y0.4", wait=True)
sleep(0.1)
sleep(2.5)

Check warning on line 852 in src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py#L852

Added line #L852 was not covered by tests
yield from bps.trigger(pmac.home, wait=True)
else:
yield from bps.trigger(pmac.home, wait=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Robin Owen 12 Jan 2021
"""

import logging
from collections.abc import Sequence

import bluesky.plan_stubs as bps
Expand All @@ -17,10 +16,9 @@
i24ssx_Chip_Manager_py3v1 as manager,
)
from mx_bluesky.beamlines.i24.serial.fixed_target.ft_utils import Fiducials
from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER
from mx_bluesky.beamlines.i24.serial.parameters.constants import OAV1_CAM

logger = logging.getLogger("I24ssx.moveonclick")


def _get_beam_centre(oav: OAV):
"""Extract the beam centre x/y positions from the display.configuration file.
Expand Down Expand Up @@ -53,7 +51,7 @@
x, y = clicked_position
xmove = -1 * (beamX - x) * zoomcalibrator
ymove = 1 * (beamY - y) * zoomcalibrator
logger.info(f"Moving X and Y {xmove} {ymove}")
SSX_LOGGER.info(f"Moving X and Y {xmove} {ymove}")
xmovepmacstring = "#1J:" + str(xmove)
ymovepmacstring = "#2J:" + str(ymove)
yield from bps.abs_set(pmac.pmac_string, xmovepmacstring, wait=True)
Expand All @@ -66,7 +64,7 @@
RE = param[0]
pmac = param[1]
oav = param[2]
logger.info(f"Clicked X and Y {x} {y}")
SSX_LOGGER.info(f"Clicked X and Y {x} {y}")
RE(_move_on_mouse_click_plan(oav, pmac, (x, y)))


Expand Down Expand Up @@ -159,7 +157,7 @@
cv.namedWindow("OAV1view")
cv.setMouseCallback("OAV1view", onMouse, param=[RE, pmac, oav]) # type: ignore

logger.info("Showing camera feed. Press escape to close")
SSX_LOGGER.info("Showing camera feed. Press escape to close")

Check warning on line 160 in src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py#L160

Added line #L160 was not covered by tests
# Read captured video and store them in success and frame
success, frame = cap.read()

Expand Down
7 changes: 4 additions & 3 deletions src/mx_bluesky/beamlines/i24/serial/run_fixed_target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ edm_path=$1
# Export env variable for the stages edm to work properly
export EDMDATAFILES="/dls_sw/prod/R3.14.12.3/support/motor/6-7-1dls14/motorApp/opi/edl"

# Get the directory of this script
current=$( realpath "$( dirname "$0" )" )


if [[ $NO_PROCESERV_TEST == true ]]; then
echo "Start the blueapi sever"

# Get the directory of this script
current=$( realpath "$( dirname "$0" )" )

# Run script to start blueapi serve
. $current/start_blueapi.sh
fi
Expand Down
Loading
Loading