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

Set up i24 serial to run on procserv #577

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def setup_logging():
log.config(logfile)


def _create_directory_for_eiger_collection(filepath: str):
logger.debug(f"Creating the directory for the collection in {filepath}.")
Path(filepath).mkdir(parents=True)


def flush_print(text):
sys.stdout.write(str(text))
sys.stdout.flush()
Expand Down Expand Up @@ -269,23 +274,8 @@ def main_extruder_plan(
elif parameters.detector_name == "eiger":
logger.info("Using Eiger detector")

logger.warning(
"""TEMPORARY HACK!
Running a Single image pilatus data collection to create directory."""
) # See https://github.com/DiamondLightSource/mx_bluesky/issues/45
num_shots = 1
sup.pilatus(
"quickshot-internaltrig",
[filepath, parameters.filename, num_shots, parameters.exposure_time_s],
)
logger.debug("Sleep 2s waiting for pilatus to arm")
sleep(2.5)
caput(pv.pilat_acquire, "0") # Disarm pilatus
sleep(0.5)
caput(pv.pilat_acquire, "1") # Arm pilatus
logger.debug("Pilatus data collection DONE")
sup.pilatus("return to normal", None)
logger.info("Pilatus back to normal. Single image pilatus data collection DONE")
# STILL TO BE TESTED!!!
_create_directory_for_eiger_collection(filepath)

caput(pv.eiger_seqID, int(caget(pv.eiger_seqID)) + 1)
logger.info(f"Eiger quickshot setup: filepath {filepath}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
log.config(logfile)


def _create_directory_for_eiger_collection(filepath: str):
logger.debug(f"Creating the directory for the collection in {filepath}.")
Path(filepath).mkdir(parents=True)

Check warning on line 72 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#L71-L72

Added lines #L71 - L72 were not covered by tests


def calculate_collection_timeout(parameters: FixedTargetParameters) -> float:
"""Give an estimation of the time the plan should wait for the data collection \
to be finished.
Expand Down Expand Up @@ -474,24 +479,8 @@
elif parameters.detector_name == "eiger":
logger.info("Using Eiger detector")

logger.warning(
"""TEMPORARY HACK!
Running a Single image pilatus data collection to create directory."""
)
num_imgs = 1
sup.pilatus(
"quickshot-internaltrig",
[filepath, filename, num_imgs, parameters.exposure_time_s],
)
logger.debug("Sleep 2s waiting for pilatus to arm")
sleep(2)
sleep(0.5)
caput(pv.pilat_acquire, "0") # Disarm pilatus
sleep(0.5)
caput(pv.pilat_acquire, "1") # Arm pilatus
logger.debug("Pilatus data collection DONE")
sup.pilatus("return to normal", None)
logger.info("Pilatus back to normal. Single image pilatus data collection DONE")
# STILL TO BE TESTED!!!
_create_directory_for_eiger_collection(filepath)

logger.info(f"Triggered Eiger setup: filepath {filepath}")
logger.info(f"Triggered Eiger setup: filename {filename}")
Expand Down
16 changes: 16 additions & 0 deletions src/mx_bluesky/beamlines/i24/serial/iocStart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Starts a blueapi server on a python IOC to run with procserv

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

# Source modules environment
source /dls_sw/etc/profile

# Activate virtual environment
source $current_directory/.venv/bin/activate

# Start blueapi server
blueapi -c "${current_directory}/blueapi_config.yaml" serve
29 changes: 23 additions & 6 deletions src/mx_bluesky/beamlines/i24/serial/run_extruder.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
#!/bin/bash

NO_PROCESERV_TEST=false

case "$2" in
-t | --test)
echo "Will run serial in test mode without procserv."
NO_PROCESERV_TEST=true
;;
esac


# Get edm path from input
edm_path=$1

# 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
# Run script to start blueapi serve
. $current/start_blueapi.sh
fi

# Open the edm screen for an extruder serial collection
echo "Starting extruder edm screen."
edm -x "${edm_path}/EX-gui/DiamondExtruder-I24-py3v1.edl"

echo "Edm screen closed, bye!"

pgrep blueapi | xargs kill
echo "Blueapi process killed"
if [[ $NO_PROCESERV_TEST == true ]]; then
# In this case blueapi server needs to be killed.
pgrep blueapi | xargs kill
echo "Blueapi process killed"
fi
28 changes: 22 additions & 6 deletions src/mx_bluesky/beamlines/i24/serial/run_fixed_target.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
#!/bin/bash

NO_PROCESERV_TEST=false

case "$2" in
-t | --test)
echo "Will run serial in test mode without procserv."
NO_PROCESERV_TEST=true
;;
esac

# Get edm path from input
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
# Run script to start blueapi serve
. $current/start_blueapi.sh
fi

# Open the edm screen for a fixed target serial collection
echo "Starting fixed target edm screen."
edm -x "${edm_path}/FT-gui/DiamondChipI24-py3v1.edl"

echo "Edm screen closed, bye!"

pgrep blueapi | xargs kill
echo "Blueapi process killed"
if [[ $NO_PROCESERV_TEST == true ]]; then
# In this case blueapi server needs to be killed.
pgrep blueapi | xargs kill
echo "Blueapi process killed"
fi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2 import (
TTL_EIGER,
TTL_PILATUS,
_create_directory_for_eiger_collection,
collection_aborted_plan,
collection_complete_plan,
enter_hutch,
Expand Down Expand Up @@ -82,6 +83,12 @@ def test_initialise_extruder(
assert fake_caget.call_count == 1


@patch("mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.Path")
def test_create_directory_for_eiger_collection(fake_path):
_create_directory_for_eiger_collection("")
fake_path.assert_called_once()


@patch(
"mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.setup_logging"
)
Expand Down Expand Up @@ -139,7 +146,11 @@ async def test_laser_check(
"mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.setup_logging"
)
@patch("mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.bps.rd")
@patch(
"mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2._create_directory_for_eiger_collection"
)
def test_run_extruder_quickshot_with_eiger(
fake_mkdir,
fake_read,
fake_log_setup,
mock_quickshot_plan,
Expand Down Expand Up @@ -180,9 +191,9 @@ def test_run_extruder_quickshot_with_eiger(
assert fake_dcid.generate_dcid.call_count == 1
assert fake_dcid.notify_start.call_count == 1
assert fake_sup.setup_beamline_for_collection_plan.call_count == 1
# Check temporary piilatus hack is in there
assert fake_sup.pilatus.call_count == 2
mock_quickshot_plan.assert_called_once()
assert fake_mkdir.call_count == 1
fake_mkdir.assert_called_with(dummy_params.collection_directory.as_posix())


@patch("mx_bluesky.beamlines.i24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sleep")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
PumpProbeSetting,
)
from mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1 import (
calculate_collection_timeout,
datasetsizei24,
finish_i24,
get_chip_prog_values,
Expand All @@ -37,6 +38,25 @@ def fake_generator(value):
return value


def test_calculate_collection_timeout(dummy_params_without_pp):
dummy_params_without_pp.total_num_images = 400
expected_collection_time = (
dummy_params_without_pp.total_num_images
* dummy_params_without_pp.exposure_time_s
)
timeout = calculate_collection_timeout(dummy_params_without_pp)

assert timeout == expected_collection_time + 30.0


def test_calculate_collection_timeout_for_eava(dummy_params_with_pp):
dummy_params_with_pp.total_num_images = 400
expected_pump_and_probe_time = 12.05
timeout = calculate_collection_timeout(dummy_params_with_pp)

assert timeout == expected_pump_and_probe_time + 30.0


@patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.caput")
def test_datasetsizei24_for_one_block_and_two_exposures(
fake_caput, dummy_params_without_pp
Expand Down Expand Up @@ -134,7 +154,11 @@ def test_load_motion_program_data(
@patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.caget")
@patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.sup")
@patch("mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1.sleep")
@patch(
"mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Collect_py3v1._create_directory_for_eiger_collection"
)
def test_start_i24_with_eiger(
fake_mkdir,
fake_sleep,
fake_sup,
fake_caget,
Expand Down Expand Up @@ -165,9 +189,11 @@ def test_start_i24_with_eiger(
assert fake_sup.eiger.call_count == 1
assert fake_sup.setup_beamline_for_collection_plan.call_count == 1
assert fake_sup.move_detector_stage_to_position_plan.call_count == 1
# Pilatus gets called for hack to create directory
assert fake_sup.pilatus.call_count == 2
assert fake_dcid.generate_dcid.call_count == 1
assert fake_mkdir.call_count == 1
fake_mkdir.assert_called_with(
dummy_params_without_pp.collection_directory.as_posix()
)

shutter_call_list = [
call("Reset", wait=True, timeout=10.0),
Expand Down
Loading