Skip to content

Commit

Permalink
Beamtime code
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Oct 3, 2024
1 parent 54b1a4b commit ffb224e
Show file tree
Hide file tree
Showing 24 changed files with 328 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- The deployment used live both times lives in: `/dls_sw/i24/software/bluesky/jungfrau`
- .venv in `./jungfrau_commissioning`
- executable `jungfrau_commissioning` loads an iPython terminal
- executable `jungfrau_commissioning` loads an iPython terminal with some more instructions
- don't install stuff pls - this environment has dependencies which no longer exist like `python-artemis`
- changing the code is fine
- if you mess up the environment the dependencies can be found in current_deps.txt
Expand Down
13 changes: 13 additions & 0 deletions jungfrau_params/acnir.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.0005,
"acquire_time_s": 0.0005,
"rotation_direction": "Negative",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.3,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"data_filename": "acnir"
}
13 changes: 13 additions & 0 deletions jungfrau_params/cuhf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.0005,
"acquire_time_s": 0.0005,
"rotation_direction": "Negative",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.3,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"data_filename": "cuhf"
}
13 changes: 13 additions & 0 deletions jungfrau_params/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.025,
"storage_directory": "/dls/i24/data/2023/cm37275-4/jungfrau_commissioning",
"nexus_filename": "test"
}
13 changes: 13 additions & 0 deletions jungfrau_params/generic_360_rotation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 10.0,
"image_width_deg": 0.01,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.25,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "glass"
}
12 changes: 12 additions & 0 deletions jungfrau_params/glass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"shutter_opening_time_s": 0.6,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "glass"
}
13 changes: 13 additions & 0 deletions jungfrau_params/glycerol.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 10.0,
"image_width_deg": 0.002,
"omega_start_deg": 0.0,
"exposure_time_s": 0.0005,
"acquire_time_s": 0.0005,
"rotation_direction": "Negative",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.3,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"data_filename": "glycerol"
}
13 changes: 13 additions & 0 deletions jungfrau_params/insulin_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.0005,
"acquire_time_s": 0.0005,
"rotation_direction": "Negative",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.3,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"data_filename": "insulin"
}
13 changes: 13 additions & 0 deletions jungfrau_params/insulin_1440.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 1440.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.27,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "insulin"
}
13 changes: 13 additions & 0 deletions jungfrau_params/insulin_200Hz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.005,
"acquire_time_s": 0.005,
"rotation_direction": "Negative",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.3,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"data_filename": "insulin"
}
13 changes: 13 additions & 0 deletions jungfrau_params/insulin_2khz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.000475,
"acquire_time_s": 0.0005,
"rotation_direction": "NEGATIVE",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.27,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "insulin"
}
13 changes: 13 additions & 0 deletions jungfrau_params/insulin_500Hz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.002,
"acquire_time_s": 0.002,
"rotation_direction": "Negative",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.3,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"data_filename": "insulin"
}
13 changes: 13 additions & 0 deletions jungfrau_params/manual_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"rotation_axis": "omega",
"scan_width_deg": 100.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"offset_deg": 10.0,
"shutter_opening_time_s": 0.27,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "test_1"
}
12 changes: 12 additions & 0 deletions jungfrau_params/params_for_blank_test_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"shutter_opening_time_s": 0.6,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "blank_test_run"
}
12 changes: 12 additions & 0 deletions jungfrau_params/peg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.001,
"acquire_time_s": 0.001,
"rotation_direction": "NEGATIVE",
"shutter_opening_time_s": 0.6,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "glycerol"
}
12 changes: 12 additions & 0 deletions jungfrau_params/peg_2khz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rotation_axis": "omega",
"scan_width_deg": 360.0,
"image_width_deg": 0.1,
"omega_start_deg": 0.0,
"exposure_time_s": 0.000475,
"acquire_time_s": 0.0005,
"rotation_direction": "NEGATIVE",
"shutter_opening_time_s": 0.6,
"storage_directory": "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning",
"nexus_filename": "glycerol"
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ def event(self, doc: dict): # type: ignore
self.flux_xbpm2 = data.get("beam_params_flux_xbpm2")
self.flux_xbpm3 = data.get("beam_params_flux_xbpm3")
self.wavelength = data.get("beam_params_wavelength")
self.energy_kev = data.get("beam_params_energy")
self.detector_distance = data.get("beam_params_det_distance")
LOGGER.info(
f"Nexus handler received beam parameters, transmission: {self.transmission}, flux: {self.flux}, wavelength: {self.wavelength}." # noqa
f"Nexus handler received beam parameters, transmission: {self.transmission}, flux: {self.flux}, wavelength: {self.wavelength}, det distance: {self.detector_distance}." # noqa
)

def stop(self, doc: dict): # type: ignore
Expand All @@ -92,6 +94,8 @@ def stop(self, doc: dict): # type: ignore
"x": self.parameters.x_start_um,
"y": self.parameters.y_start_um,
"z": self.parameters.z_start_um,
"detector_distance": self.detector_distance,
"energy_kev": self.energy_kev,
}
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
check_and_clear_errors,
do_manual_acquisition,
set_software_trigger,
wait_for_writing,
setup_detector
)
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils import run_number
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils.jf_commissioning_devices import (
JungfrauM1,
)
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils.log import LOGGER
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils import i24


class GainMode(str, Enum):
Expand Down Expand Up @@ -63,6 +66,8 @@ def do_darks(
)
os.makedirs(directory_prefix, exist_ok=True)

LOGGER.info(f"Writing data to {directory_prefix}")

timeout_factor = max(10, timeout_factor * 0.001 / acq_time_s)

# TODO CHECK IF FILES EXIST
Expand Down Expand Up @@ -105,3 +110,60 @@ def do_darks(
yield from set_gain_mode(
jungfrau, GainMode.dynamic, check_for_errors=check_for_errors
)


def do_pedestal_darks(
jungfrau: JungfrauM1,
directory: str = "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning/",
check_for_errors=True,
exp_time_s=0.001,
acq_time_s=0.001,
focred_gain_ratio=10,
num_images=1000,
timeout_factor=6,
pedestal_frames=20,
pedestal_loops=200):

directory_prefix = (
Path(directory)
/ f"{run_number(Path(directory)):05d}_darks_{acq_time_s}s_per_frame_pedestal"
)
os.makedirs(directory_prefix, exist_ok=True)

LOGGER.info(f"Writing data to {directory_prefix}")

yield from set_software_trigger(jungfrau)

yield from setup_detector(jungfrau, exp_time_s, acq_time_s, pedestal_frames*pedestal_loops*2)

yield from set_gain_mode(
jungfrau, GainMode.dynamic, check_for_errors=check_for_errors
)
yield from abs_set(jungfrau.file_directory, directory_prefix.as_posix(), wait=True)
yield from abs_set(jungfrau.file_name, "Pedestal", wait=True)

yield from abs_set(jungfrau.pedestal_frames, pedestal_frames, wait=True)
yield from abs_set(jungfrau.pedestal_loops, pedestal_loops, wait=True)

yield from abs_set(jungfrau.pedestal_mode, 1, wait=True)

yield from abs_set(jungfrau.acquire_start, 1, wait=True)
yield from wait_for_writing(jungfrau, 1000)


# yield from do_manual_acquisition(
# jungfrau, exp_time_s, fg_acq_time, num_images, timeout_factor
# )

yield from sleep(0.3)

yield from abs_set(jungfrau.pedestal_mode, 0, wait=True)


def take_darks():
""""Take darks in pedestal and old style, at 1kHz and 2kHz"""
jf = i24.jungfrau()
for time in [0.001, 0.0005]:
LOGGER.info(f"Taking data at exposure time = {time}")
yield from do_pedestal_darks(jf, exp_time_s=time, acq_time_s=time)
yield from do_darks(jf, exp_time_s=time, acq_time_s=time)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
JungfrauM1,
TriggerMode,
)
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils import run_number
import os
from mx_bluesky.beamlines.i24.jungfrau_commissioning.utils.log import LOGGER

DIRECTORY = "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning/"
Expand Down Expand Up @@ -98,6 +100,33 @@ def do_manual_acq_with_new_filename(
)


def do_burst_mode(
jungfrau: JungfrauM1,
name: str,
exp_time_s: float,
acq_time_s: float,
n_frames: int,
directory: str = "/dls/i24/data/2024/cm37275-4/jungfrau_commissioning/",
timeout_times: float = 5,
):
directory_prefix = (
Path(directory)
/ f"{run_number(Path(directory)):05d}_burst_{n_frames}_frames_{acq_time_s}s_per_frame"
)
os.makedirs(directory_prefix, exist_ok=True)
LOGGER.info(
f"Using directory {directory_prefix.as_posix()}, setting directory and filename on detector..."
)
yield from bps.abs_set(jungfrau.file_name, name, wait=True)
yield from bps.abs_set(jungfrau.file_directory, directory_prefix.as_posix(), wait=True)
yield from bps.abs_set(jungfrau.burst_mode, 1)
yield from bps.sleep(0.2)
yield from do_manual_acquisition(
jungfrau, exp_time_s, acq_time_s, n_frames, timeout_times
)
yield from bps.abs_set(jungfrau.burst_mode, 0)


def setup_detector(
jungfrau: JungfrauM1,
exposure_time_s: float,
Expand All @@ -118,11 +147,11 @@ def setup_detector(
acquire_time_s,
group=group,
)
yield from bps.abs_set(
jungfrau.frame_count,
n_images,
group=group,
)
# yield from bps.abs_set(
# jungfrau.frame_count,
# n_images,
# group=group,
# )
if wait:
yield from bps.wait(group)

Expand Down
Loading

0 comments on commit ffb224e

Please sign in to comment.