Skip to content

Commit

Permalink
Merge branch 'main' into fixes_for_ophyd_async_0.9.0a1
Browse files Browse the repository at this point in the history
  • Loading branch information
olliesilvester authored Dec 10, 2024
2 parents 46e9633 + 5497217 commit b99e5c4
Show file tree
Hide file tree
Showing 16 changed files with 323 additions and 330 deletions.
6 changes: 0 additions & 6 deletions src/mx_bluesky/beamlines/i24/serial/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
moveto,
moveto_preset,
pumpprobe_calc,
save_screen_map,
upload_parameters,
write_parameter_file,
)
from .log import clean_up_log_config_at_end, setup_collection_logs
from .setup_beamline.setup_detector import setup_detector_stage
Expand All @@ -44,9 +41,6 @@
"load_lite_map",
"load_stock_map",
"pumpprobe_calc",
"save_screen_map",
"upload_parameters",
"write_parameter_file",
"setup_collection_logs",
"clean_up_log_config_at_end",
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
- March 21 added logging and Eiger functionality
"""

import json
import re
import shutil
import sys
import time
from datetime import datetime
Expand Down Expand Up @@ -40,10 +38,6 @@
log_on_entry,
)
from mx_bluesky.beamlines.i24.serial.parameters import ExtruderParameters
from mx_bluesky.beamlines.i24.serial.parameters.constants import (
PARAM_FILE_NAME,
PARAM_FILE_PATH,
)
from mx_bluesky.beamlines.i24.serial.setup_beamline import Pilatus, caget, caput, pv
from mx_bluesky.beamlines.i24.serial.setup_beamline import setup_beamline as sup
from mx_bluesky.beamlines.i24.serial.setup_beamline.setup_detector import (
Expand Down Expand Up @@ -141,12 +135,20 @@ def enter_hutch(


@log_on_entry
def write_parameter_file(
detector_stage: DetectorMotion, attenuator: ReadOnlyAttenuator
):
"""Writes a json parameter file that can later be parsed by the model."""
param_file: Path = PARAM_FILE_PATH / PARAM_FILE_NAME
SSX_LOGGER.debug(f"Writing Parameter File to: {param_file}\n")
def read_parameters(detector_stage: DetectorMotion, attenuator: ReadOnlyAttenuator):
""" Read the parameters from user input and create the parameter model for an \
extruder collection.
Args:
detector_stage (DetectorMotion): The detector stage device.
attenuator (ReadOnlyAttenuator): A read-only attenuator device to get the \
transmission value.
Returns:
ExtruderParameters: Parameter model for extruder collections
"""
SSX_LOGGER.info("Creating parameter model from input.")

det_type = yield from get_detector_type(detector_stage)
SSX_LOGGER.warning(f"DETECTOR TYPE: {det_type}")
Expand Down Expand Up @@ -182,12 +184,11 @@ def write_parameter_file(
"laser_dwell_s": pump_exp,
"laser_delay_s": pump_delay,
}
with open(param_file, "w") as f:
json.dump(params_dict, f, indent=4)

SSX_LOGGER.info("Parameters \n")
SSX_LOGGER.info(pformat(params_dict))
yield from bps.null()
return ExtruderParameters(**params_dict)


@log_on_entry
Expand Down Expand Up @@ -467,11 +468,6 @@ def collection_complete_plan(
dcid.collection_complete(end_time, aborted=False)
SSX_LOGGER.info(f"End Time = {end_time.ctime()}")

# Copy parameter file
shutil.copy2(
PARAM_FILE_PATH / PARAM_FILE_NAME,
collection_directory / PARAM_FILE_NAME,
)
yield from bps.null()


Expand All @@ -489,8 +485,9 @@ def run_extruder_plan(
start_time = datetime.now()
SSX_LOGGER.info(f"Collection start time: {start_time.ctime()}")

yield from write_parameter_file(detector_stage, attenuator)
parameters = ExtruderParameters.from_file(PARAM_FILE_PATH / PARAM_FILE_NAME)
parameters: ExtruderParameters = yield from read_parameters(
detector_stage, attenuator
)

beam_center_device = sup.get_beam_center_device(parameters.detector_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ beginScreenProperties
major 4
minor 0
release 1
x 1062
y 369
x 308
y 339
w 650
h 400
font "arial-medium-r-18.0"
Expand Down Expand Up @@ -179,50 +179,6 @@ font "arial-medium-r-18.0"
colorPv "ME14E-MO-IOC-01:GP67"
endObjectProperties

# (Shell Command)
object shellCmdClass
beginObjectProperties
major 4
minor 3
release 0
x 40
y 290
w 194
h 40
fgColor index 0
bgColor index 23
topShadowColor index 1
botShadowColor index 11
font "arial-medium-r-18.0"
buttonLabel "Save Screen Map"
numCmds 1
command {
0 "blueapi -c CONFIG_LOCATION controller run save_screen_map"
}
endObjectProperties

# (Shell Command)
object shellCmdClass
beginObjectProperties
major 4
minor 3
release 0
x 12
y 337
w 244
h 53
fgColor index 13
bgColor index 49
topShadowColor index 1
botShadowColor index 11
font "arial-medium-r-18.0"
buttonLabel "Upload Parameters"
numCmds 1
command {
0 "blueapi -c CONFIG_LOCATION controller run upload_parameters '\{\"pmac\":\"pmac\"\}'"
}
endObjectProperties

# (Message Button)
object activeMessageButtonClass
beginObjectProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
Fixed target data collection
"""

import shutil
from datetime import datetime
from pathlib import Path
from time import sleep

import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
import numpy as np
from bluesky.utils import MsgGenerator
from dodal.common import inject
from dodal.devices.attenuator import ReadOnlyAttenuator
Expand All @@ -35,18 +33,11 @@
PumpProbeSetting,
)
from mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_Chip_Manager_py3v1 import (
write_parameter_file,
read_parameters,
upload_chip_map_to_geobrick,
)
from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER, log_on_entry
from mx_bluesky.beamlines.i24.serial.parameters import (
ChipDescription,
FixedTargetParameters,
)
from mx_bluesky.beamlines.i24.serial.parameters.constants import (
LITEMAP_PATH,
PARAM_FILE_NAME,
PARAM_FILE_PATH_FT,
)
from mx_bluesky.beamlines.i24.serial.parameters import FixedTargetParameters
from mx_bluesky.beamlines.i24.serial.setup_beamline import caget, cagetstring, caput, pv
from mx_bluesky.beamlines.i24.serial.setup_beamline import setup_beamline as sup
from mx_bluesky.beamlines.i24.serial.setup_beamline.setup_zebra_plans import (
Expand Down Expand Up @@ -107,19 +98,6 @@ def calculate_collection_timeout(parameters: FixedTargetParameters) -> float:
return timeout


def copy_files_to_data_location(
dest_dir: Path | str,
param_path: Path = PARAM_FILE_PATH_FT,
map_file: Path = LITEMAP_PATH,
map_type: MappingType = MappingType.Lite,
):
if not isinstance(dest_dir, Path):
dest_dir = Path(dest_dir)
shutil.copy2(param_path / "parameters.txt", dest_dir / "parameters.txt")
if map_type == MappingType.Lite:
shutil.copy2(map_file / "currentchip.map", dest_dir / "currentchip.map")


def write_userlog(
parameters: FixedTargetParameters,
filename: str,
Expand Down Expand Up @@ -308,50 +286,18 @@ def get_prog_num(


@log_on_entry
def datasetsizei24(
n_exposures: int,
chip_params: ChipDescription,
map_type: MappingType,
) -> int:
# Calculates how many images will be collected based on map type and N repeats
SSX_LOGGER.info("Calculate total number of images expected in data collection.")

if map_type == MappingType.NoMap:
if chip_params.chip_type == ChipType.Custom:
total_numb_imgs = chip_params.x_num_steps * chip_params.y_num_steps
SSX_LOGGER.info(
f"Map type: None \tCustom chip \tNumber of images {total_numb_imgs}"
)
else:
chip_format = chip_params.chip_format[:4]
total_numb_imgs = int(np.prod(chip_format))
SSX_LOGGER.info(
f"""Map type: None \tOxford chip {chip_params.chip_type} \t \
Number of images {total_numb_imgs}"""
)

elif map_type == MappingType.Lite:
SSX_LOGGER.info(f"Using Mapping Lite on chip type {chip_params.chip_type}")
chip_format = chip_params.chip_format[2:4]
block_count = 0
with open(LITEMAP_PATH / "currentchip.map") as f:
for line in f.readlines():
entry = line.split()
if entry[2] == "1":
block_count += 1

SSX_LOGGER.info(f"Block count={block_count}")
SSX_LOGGER.info(f"Chip format={chip_format}")

SSX_LOGGER.info(f"Number of exposures={n_exposures}")

total_numb_imgs = int(np.prod(chip_format) * block_count * n_exposures)
SSX_LOGGER.info(f"Calculated number of images: {total_numb_imgs}")
def set_datasize(
parameters: FixedTargetParameters,
):
SSX_LOGGER.info("Setting PV to calculated total number of images")

SSX_LOGGER.info("Set PV to calculated number of images.")
caput(pv.me14e_gp10, int(total_numb_imgs))
SSX_LOGGER.debug(f"Map type: {parameters.map_type}")
SSX_LOGGER.debug(f"Chip type: {parameters.chip.chip_type}")
if parameters.map_type == MappingType.Lite:
SSX_LOGGER.debug(f"Num exposures: {parameters.num_exposures}")
SSX_LOGGER.debug(f"Block count: {len(parameters.chip_map)}")

return int(total_numb_imgs)
caput(pv.me14e_gp10, parameters.total_num_images)


@log_on_entry
Expand Down Expand Up @@ -622,9 +568,7 @@ def main_fixed_target_plan(
parameters.checker_pattern,
)

parameters.total_num_images = datasetsizei24(
parameters.num_exposures, parameters.chip, parameters.map_type
)
set_datasize(parameters)

start_time = yield from start_i24(
zebra,
Expand Down Expand Up @@ -695,8 +639,7 @@ def collection_complete_plan(
SSX_LOGGER.debug(f"Collection end time {end_time}")
dcid.collection_complete(end_time, aborted=False)

# Copy parameter file and eventual chip map to collection directory
copy_files_to_data_location(collection_directory, map_type=map_type)
# NOTE no files to copy anymore but shoud write userlog here
yield from bps.null()


Expand Down Expand Up @@ -749,29 +692,13 @@ def run_fixed_target_plan(
mirrors: FocusMirrorsMode = inject("focus_mirrors"),
attenuator: ReadOnlyAttenuator = inject("attenuator"),
) -> MsgGenerator:
# in the first instance, write params here
yield from write_parameter_file(detector_stage, attenuator)

SSX_LOGGER.info("Getting parameters from file.")
parameters = FixedTargetParameters.from_file(PARAM_FILE_PATH_FT / PARAM_FILE_NAME)

log_msg = f"""
Parameters for I24 serial collection: \n
Chip name is {parameters.filename}
visit = {parameters.visit}
sub_dir = {parameters.directory}
n_exposures = {parameters.num_exposures}
chip_type = {str(parameters.chip.chip_type)}
map_type = {str(parameters.map_type)}
dcdetdist = {parameters.detector_distance_mm}
exptime = {parameters.exposure_time_s}
det_type = {parameters.detector_name}
pump_repeat = {str(parameters.pump_repeat)}
pumpexptime = {parameters.laser_dwell_s}
pumpdelay = {parameters.laser_delay_s}
prepumpexptime = {parameters.pre_pump_exposure_s}
"""
SSX_LOGGER.info(log_msg)
# Read the parameters
parameters: FixedTargetParameters = yield from read_parameters(
detector_stage, attenuator
)

if parameters.chip_map:
upload_chip_map_to_geobrick(pmac, parameters.chip_map)

beam_center_device = sup.get_beam_center_device(parameters.detector_name)

Expand Down
Loading

0 comments on commit b99e5c4

Please sign in to comment.