Skip to content

Commit

Permalink
Merge pull request #48 from DiamondLightSource/47_I24ssx_updates
Browse files Browse the repository at this point in the history
Pull in latest updates
  • Loading branch information
noemifrisina authored Sep 22, 2023
2 parents b9dc265 + 424c0c6 commit f5d68ac
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 45 deletions.
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ edm_serial/
# Parameter files that could be modified by hand by scientists
# or created during collection
**/parameters/*.json
**/parameters/fixed-target/*.txt
**/parameters/fixed-target/cs/fiducials_*.txt
**/parameters/fixed-target/*.json
**/parameters/fixed-target/*/*.map
**/parameters/*.txt
**/parameters/fixed_target/*.txt
**/parameters/fixed_target/cs/fiducial_*.txt
**/parameters/fixed_target/*.json
**/parameters/fixed_target/**/*.map
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=6.2", "wheel"]
requires = ["setuptools>=64", "setuptools_scm[toml]==7.1.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import argparse
import logging
import re
import sys
import time
from datetime import datetime
Expand Down Expand Up @@ -113,9 +114,9 @@ def write_parameter_file(param_path: Path | str = PARAM_FILE_PATH):

# If file name ends in a digit this causes processing/pilatus pain.
# Append an underscore
numbers = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
if det_type == "pilatus":
if filename.endswith(numbers):
m = re.search(r"\d+$", filename)
if m is not None:
# Note for future reference. Appending underscore causes more hassle and
# high probability of users accidentally overwriting data. Use a dash
filename = filename + "-"
Expand Down Expand Up @@ -278,6 +279,23 @@ def run_extruderi24(args=None):
sup.zebra1("quickshot", [gate_start, gate_width])

elif det_type == "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, filename, num_shots, exp_time])
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")
logger.info("Pilatus back to normal. Single image pilatus data collection DONE")

caput(pv.eiger_seqID, int(caget(pv.eiger_seqID)) + 1)
logger.info("Eiger quickshot setup: filepath %s" % filepath)
logger.info("Eiger quickshot setup: filepath %s" % filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,7 @@ offColor index 16
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:-10"
pressValue "#2J:10"
releaseValue "#2P"
3d
font "helvetica-medium-r-18.0"
Expand Down Expand Up @@ -2237,7 +2237,7 @@ offColor index 16
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:-60"
pressValue "#2J:60"
releaseValue "#2P"
offLabel "-3"
3d
Expand All @@ -2260,7 +2260,7 @@ offColor index 16
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:60"
pressValue "#2J:-60"
releaseValue "#2P"
offLabel "+3"
3d
Expand All @@ -2283,7 +2283,7 @@ offColor index 16
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:10"
pressValue "#2J:-10"
releaseValue "#2P"
3d
font "helvetica-medium-r-18.0"
Expand All @@ -2305,7 +2305,7 @@ offColor index 19
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:31750"
pressValue "#2J:-31750"
releaseValue "#2P"
onLabel "Y+Y"
offLabel "+Y+"
Expand Down Expand Up @@ -2377,7 +2377,7 @@ offColor index 19
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:-31750"
pressValue "#2J:31750"
releaseValue "#2P"
onLabel "Y-Y"
offLabel "-Y-"
Expand Down Expand Up @@ -2493,7 +2493,7 @@ offColor index 17
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:-3750"
pressValue "#2J:3750"
releaseValue "#2P"
offLabel "-3"
3d
Expand All @@ -2516,7 +2516,7 @@ offColor index 17
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:-1250"
pressValue "#2J:1250"
releaseValue "#2P"
offLabel "-1"
3d
Expand All @@ -2539,7 +2539,7 @@ offColor index 17
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:3750"
pressValue "#2J:-3750"
releaseValue "#2P"
offLabel "+3"
3d
Expand All @@ -2562,7 +2562,7 @@ offColor index 17
topShadowColor index 7
botShadowColor index 7
controlPv "ME14E-MO-CHIP-01:PMAC_STRING"
pressValue "#2J:1250"
pressValue "#2J:-1250"
releaseValue "#2P"
offLabel "+1"
3d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import argparse
import json
import logging
import re
import shutil
import sys
import time
Expand Down Expand Up @@ -125,16 +126,20 @@ def write_parameter_file(param_path: Path | str = PARAM_FILE_PATH_FT):
map_type = caget(pv.me14e_gp2)
chip_type = caget(pv.me14e_gp1)
det_type = caget(pv.me14e_gp101)

# If file name ends in a digit this causes processing/pilatus pain.
# Append an underscore
if det_type == "pilatus":
caput(pv.pilat_cbftemplate, 0)
numbers = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
if filename.endswith(numbers):
m = re.search(r"\d+$", filename)
if m is not None:
# Note for future reference. Appending underscore causes more hassle and
# high probability of users accidentally overwriting data. Use a dash
filename = filename + "-"
logger.warning(
logger.info(
"Requested filename ends in a number. Appended dash: %s" % filename
)

# historical - use chip_name instead of filename
chip_name = filename

Expand Down Expand Up @@ -744,7 +749,7 @@ def fiducial(point: int = 1, param_path: Path | str = CS_FILES_PATH):
logger.info("MTR\tRBV\tRAW\tCorr\tf_value")
logger.info("MTR1\t%1.4f\t%i\t%i\t%1.4f" % (rbv_1, raw_1, mtr1_dir, f_x))
logger.info("MTR2\t%1.4f\t%i\t%i\t%1.4f" % (rbv_2, raw_2, mtr2_dir, f_y))
logger.info("MTR3\t%1.4f\t%i\t%i\t%1.4f" % (rbv_3, raw_3, mtr3_dir, f_y))
logger.info("MTR3\t%1.4f\t%i\t%i\t%1.4f" % (rbv_3, raw_3, mtr3_dir, f_z))

with open(param_path / f"fiducial_{point}.txt", "w") as f:
f.write("MTR\tRBV\tRAW\tCorr\tf_value\n")
Expand Down Expand Up @@ -955,11 +960,17 @@ def pumpprobe_calc():
repeat3 = 6 * 20 * (movetime + (pumpexptime + exptime) / 2)
repeat5 = 10 * 20 * (movetime + (pumpexptime + exptime) / 2)
repeat10 = 20 * 20 * (movetime + (pumpexptime + exptime) / 2)
logger.info("repeat1 (%s): %s s" % (pv.me14e_gp104, round(repeat1, 4)))
logger.info("repeat2 (%s): %s s" % (pv.me14e_gp105, round(repeat2, 4)))
logger.info("repeat3 (%s): %s s" % (pv.me14e_gp106, round(repeat3, 4)))
logger.info("repeat5 (%s): %s s" % (pv.me14e_gp107, round(repeat5, 4)))
logger.info("repeat10 (%s): %s s" % (pv.me14e_gp108, round(repeat10, 4)))
for pv_name, repeat in (
(pv.me14e_gp104, repeat1),
(pv.me14e_gp105, repeat2),
(pv.me14e_gp106, repeat3),
(pv.me14e_gp107, repeat5),
(pv.me14e_gp108, repeat10),
):
rounded = round(repeat, 4)
caput(pv_name, rounded)
logger.info("Repeat (%s): %s s" % (pv_name, rounded))
# logger.info("repeat10 (%s): %s s" % (pv.me14e_gp108, round(repeat10, 4)))
logger.debug("PP calculations done")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MTR RBV RAW Corr f_value
MTR1 25.3970 254270 1 25.3970
MTR2 -0.3604 3608 -1 -0.3604
MTR1 25.3946 254246 1 25.3946
MTR2 -0.3833 3838 -1 -0.3833
MTR3 0.0000 0 -1 0.0000
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MTR RBV RAW Corr f_value
MTR1 0.3718 3722 1 0.3718
MTR2 25.3952 -254255 -1 25.3952
MTR1 0.3941 3946 1 0.3941
MTR2 25.3958 -254261 -1 25.3958
MTR3 0.0000 0 -1 0.0000
10 changes: 5 additions & 5 deletions src/mx_bluesky/I24/serial/parameters/fixed_target/parameters.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
visit /dls/i24/data/2023/cm33852-4/
chip_name beta
protein_name test2_20230912/test2
chip_name albion
protein_name test_20230919/eigertest3
n_exposures 1
chip_type 0
map_type 1
pump_repeat 0
pumpexptime 0
pumpdelay 0
prepumpexptime 0
exptime 0.005
dcdetdist 1300
det_type pilatus
exptime 0.01
dcdetdist 1480
det_type eiger
8 changes: 4 additions & 4 deletions src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Pilatus:
round(a * b, 3) for a, b in zip(image_size_pixels, pixel_size_mm)
)

det_y_threshold = 50.0
det_y_target = 0.0
det_y_threshold = 560.0
det_y_target = 566.0

class pv:
detector_distance = pv.pilat_detdist
Expand All @@ -48,8 +48,8 @@ class Eiger:
round(a * b, 3) for a, b in zip(image_size_pixels, pixel_size_mm)
)

det_y_threshold = 200.0
det_y_target = 220.0
det_y_threshold = -10.0
det_y_target = -22.0

class pv:
detector_distance = pv.eiger_detdist
Expand Down
2 changes: 1 addition & 1 deletion src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnknownDetectorType(Exception):

def get_detector_type() -> Detector:
det_y = caget(pv.det_y)
if float(det_y) > Eiger.det_y_threshold:
if float(det_y) < Eiger.det_y_threshold:
logger.info("Eiger detector in use.")
return Eiger()
elif float(det_y) > Pilatus.det_y_threshold:
Expand Down
4 changes: 2 additions & 2 deletions src/mx_bluesky/I24/serial/write_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def call_nexgen(
chip_prog_dict,
start_time,
param_file_tuple,
expt_type="fixed_target",
expt_type="fixed-target",
total_numb_imgs=None,
):
det_type = str(caget(pv.me14e_gp101))
print(f"det_type: {det_type}")

if expt_type == "fixed_target":
if expt_type == "fixed-target":
(
chip_name,
visit,
Expand Down
7 changes: 6 additions & 1 deletion tests/I24/serial/extruder/test_extruder_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def test_moveto_laseroff_for_pilatus(fake_caget, fake_caput, dummy_parser):
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caget")
@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sup")
def test_run_extruder(fake_sup, fake_caget, fake_caput, fake_nexgen, fake_dcid):
def test_run_extruder_with_eiger(
fake_sup, fake_caget, fake_caput, fake_nexgen, fake_dcid
):
run_extruderi24()
assert fake_nexgen.call_count == 1
assert fake_dcid.call_count == 1
# Check temporary piilatus hack is in there
assert fake_sup.pilatus.call_count == 2
21 changes: 20 additions & 1 deletion tests/I24/serial/fixed-target/test_chip_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from unittest.mock import MagicMock, mock_open, patch
from unittest.mock import ANY, MagicMock, call, mock_open, patch

import pytest

Expand All @@ -8,6 +8,7 @@
cs_reset,
moveto,
parse_args_and_run_parsed_function,
pumpprobe_calc,
scrape_mtr_directions,
scrape_mtr_fiducials,
)
Expand Down Expand Up @@ -168,3 +169,21 @@ def test_arg_parser_runs_define_current_chip_function_as_expected(
):
parse_args_and_run_parsed_function(["define_current_chip", "chip_id"])
mock_define_current_chip.assert_called_once_with("chip_id")


@patch("mx_bluesky.I24.serial.fixed_target.i24ssx_Chip_Manager_py3v1.caput")
@patch("mx_bluesky.I24.serial.fixed_target.i24ssx_Chip_Manager_py3v1.caget")
def test_pumpprobe_calc(fake_caget, fake_caput):
fake_caget.side_effect = [0.01, 0.005]
pumpprobe_calc()
assert fake_caget.call_count == 2
assert fake_caput.call_count == 5
fake_caput.assert_has_calls(
[
call(ANY, 0.62),
call(ANY, 1.24),
call(ANY, 1.86),
call(ANY, 3.1),
call(ANY, 6.2),
]
)
8 changes: 7 additions & 1 deletion tests/I24/serial/setup_beamline/test_setup_beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

@patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caget")
def test_get_detector_type(fake_caget):
fake_caget.return_value = 205
fake_caget.return_value = -22
assert setup_beamline.get_detector_type().name == "eiger"


@patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caget")
def test_get_detector_type_finds_pilatus(fake_caget):
fake_caget.return_value = 566
assert setup_beamline.get_detector_type().name == "pilatus"


@patch("mx_bluesky.I24.serial.setup_beamline.setup_beamline.caput")
def test_beamline_collect(fake_caput):
setup_beamline.beamline("collect")
Expand Down

0 comments on commit f5d68ac

Please sign in to comment.