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 ssx: determine detector #17

Merged
merged 6 commits into from
Jun 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ def initialise_extruderi24():
visit = "/dls/i24/data/2023/cm33852-2/"
lg.info("%s Visit defined %s" % (name, visit))

# define detector using the below line
# Oct 2021. beta. Do not change from pilatus unless your name is Robin
det_type = "pilatus"
# det_type = "eiger"
# Define detector in use
det_type = sup.get_detector_type()

caput(pv.ioc12_gp1, str(visit))
caput(pv.ioc12_gp2, "test")
Expand All @@ -54,7 +52,7 @@ def initialise_extruderi24():
caput(pv.ioc12_gp8, 0) # status PV do not reuse gp8 for something else
caput(pv.ioc12_gp9, 0)
caput(pv.ioc12_gp10, 0)
caput(pv.ioc12_gp15, str(det_type))
caput(pv.ioc12_gp15, det_type.name)
caput(pv.pilat_cbftemplate, 0)
print("Done Done Done")
lg.info("%s Initialsation complete" % name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from mx_bluesky.I24.serial.fixed_target import i24ssx_Chip_Mapping_py3v1 as mapping
from mx_bluesky.I24.serial.fixed_target import i24ssx_Chip_StartUp_py3v1 as startup
from mx_bluesky.I24.serial.setup_beamline import caget, caput, pv
from mx_bluesky.I24.serial.setup_beamline import setup_beamline as sup

# Log should now change name daily.
lg.basicConfig(
Expand Down Expand Up @@ -89,10 +90,10 @@ def initialise():
caput(pv.me14e_pmac_str, "m708=100 m709=150")
caput(pv.me14e_pmac_str, "m808=100 m809=150")

# define detector using the below line
# det_type = "pilatus"
# Define detector in use
det_type = sup.get_detector_type()

caput(pv.pilat_cbftemplate, 0)
det_type = "eiger"

sleep(0.1)
print("Clearing")
Expand All @@ -105,7 +106,7 @@ def initialise():
sys.stdout.flush()

caput(pv.me14e_gp100, "press set params to read visit")
caput(pv.me14e_gp101, str(det_type))
caput(pv.me14e_gp101, det_type.name)

print("\n", "Initialisation Complete")
lg.info("%s Complete" % name)
Expand Down
8 changes: 8 additions & 0 deletions src/mx_bluesky/I24/serial/setup_beamline/pv_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class Pilatus:
id = 58
name = "pilatus"

# fast, slow / width, height
image_size_pixels = (2463, 2527)
Expand All @@ -21,6 +22,9 @@ 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

class pv:
detector_distance = pv.pilat_detdist
wavelength = pv.pilat_wavelength
Expand All @@ -35,6 +39,7 @@ class pv:

class Eiger:
id = 94
name = "eiger"

pixel_size_mm = (0.075, 0.075)
image_size_pixels = (3108, 3262)
Expand All @@ -43,6 +48,9 @@ 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
Comment on lines +51 to +52
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice place to store these!


class pv:
detector_distance = pv.eiger_detdist
wavelength = pv.eiger_wavelength
Expand Down
15 changes: 15 additions & 0 deletions src/mx_bluesky/I24/serial/setup_beamline/setup_beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

from mx_bluesky.I24.serial.setup_beamline import pv
from mx_bluesky.I24.serial.setup_beamline.ca import caget, caput
from mx_bluesky.I24.serial.setup_beamline.pv_abstract import Detector, Eiger, Pilatus


class UnknownDetectorType(Exception):
pass


def get_detector_type() -> Detector:
det_y = caget(pv.det_y)
if float(det_y) > Eiger.det_y_threshold:
return Eiger()
elif float(det_y) > Pilatus.det_y_threshold:
return Pilatus()
else:
raise UnknownDetectorType("Detector not found.")


def modechange(action):
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 @@ -6,6 +6,7 @@
run_extruderi24,
scrape_parameter_file,
)
from mx_bluesky.I24.serial.setup_beamline import Eiger

params_file_str = """visit foo
directory bar
Expand All @@ -30,7 +31,11 @@ def test_scrape_parameter_file():


@patch("mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.caput")
def test_initialise_extruder(fake_caput):
@patch(
"mx_bluesky.I24.serial.extruder.i24ssx_Extruder_Collect_py3v2.sup.get_detector_type"
)
def test_initialise_extruder(fake_det, fake_caput):
fake_det.return_value = Eiger()
initialise_extruderi24()
assert fake_caput.call_count == 11

Expand Down
6 changes: 6 additions & 0 deletions tests/I24/serial/setup_beamline/test_setup_beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from mx_bluesky.I24.serial.setup_beamline import setup_beamline


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


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