From d22622dd28d8269a9cbe1f065da0eda395e4f397 Mon Sep 17 00:00:00 2001 From: Daniel Fernandes Date: Tue, 13 Aug 2024 10:56:23 +0100 Subject: [PATCH] Auto format --- .../bimorph_optimisation_plan/data_saver.py | 25 +++++---- .../pencil_beam_scan_2d_slit_plan.py | 52 ++++++++++--------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/src/mx_bluesky/bimorph_optimisation_plan/data_saver.py b/src/mx_bluesky/bimorph_optimisation_plan/data_saver.py index 0b0e6dbdf..6c52af1cb 100644 --- a/src/mx_bluesky/bimorph_optimisation_plan/data_saver.py +++ b/src/mx_bluesky/bimorph_optimisation_plan/data_saver.py @@ -1,13 +1,16 @@ from datetime import datetime from typing import Callable -def generate_filename(file_prefix:str = None, file_timestamp_format:str = None) -> str: + +def generate_filename( + file_prefix: str = None, file_timestamp_format: str = None +) -> str: """Generated a filename (without path) for plan output csv Args: file_prefix (optional): Prefix for filename file_timestamp_format (optional): datetime library timestamp format for filename - + Returns: A string fiename without full path """ @@ -17,12 +20,12 @@ def generate_filename(file_prefix:str = None, file_timestamp_format:str = None) filename += file_prefix else: filename += "pencilbeam-data-" - - if file_timestamp_format is not None: + + if file_timestamp_format is not None: filename += datetime.now().strftime(file_timestamp_format) else: filename += datetime.now().strftime("%d-%m-%Y-%H-%M") - + filename += ".csv" return filename @@ -34,7 +37,7 @@ def make_csv(docs: list) -> str: Args: docs: A list of RunEngine docs - + Returms: A string of given list's csv equivalent """ @@ -69,7 +72,7 @@ def define_data_aggregator(filepath: str, filename: str) -> tuple[list, Callable Args: filepath: Directory to save file into filename: Filename for output csv - + Returns: A list that aggregates data, a function to give as sub to Run Engine """ @@ -80,11 +83,7 @@ def aggregate_docs(_, doc): data_list.append(doc) csv = make_csv(data_list) - with open(filepath + '/' + filename, 'w') as file: + with open(filepath + "/" + filename, "w") as file: file.write(csv) - - return data_list, aggregate_docs - - - + return data_list, aggregate_docs diff --git a/src/mx_bluesky/bimorph_optimisation_plan/pencil_beam_scan_2d_slit_plan.py b/src/mx_bluesky/bimorph_optimisation_plan/pencil_beam_scan_2d_slit_plan.py index 176b2709a..01ba1ef0b 100644 --- a/src/mx_bluesky/bimorph_optimisation_plan/pencil_beam_scan_2d_slit_plan.py +++ b/src/mx_bluesky/bimorph_optimisation_plan/pencil_beam_scan_2d_slit_plan.py @@ -20,7 +20,8 @@ class SlitDimension(Enum): X: Represents X dimension Y: Represents Y dimension """ - X = "X", + + X = ("X",) Y = "Y" @@ -32,12 +33,9 @@ class CentroidDevice(Device): centroid_y_rbv: An EpicsSignalRO for the centroid Y readback value valutes_to_average: Number of reads centroid will do, then take mean """ - centroid_x_rbv: EpicsSignalRO = Component( - EpicsSignalRO, "CentroidX_RBV" - ) - centroid_y_rbv: EpicsSignalRO = Component( - EpicsSignalRO, "CentroidY_RBV" - ) + + centroid_x_rbv: EpicsSignalRO = Component(EpicsSignalRO, "CentroidX_RBV") + centroid_y_rbv: EpicsSignalRO = Component(EpicsSignalRO, "CentroidY_RBV") values_to_average = 1 @@ -47,23 +45,29 @@ def read(self): for _ in range(self.values_to_average): centroid_x_read = self.centroid_x_rbv.read() centroid_y_read = self.centroid_y_rbv.read() - centroid_x_summation += centroid_x_read[self.name+"_centroid_x_rbv"]["value"] - centroid_y_summation += centroid_y_read[self.name+"_centroid_y_rbv"]["value"] - - centroid_x_mean = centroid_x_summation / self.values_to_average + centroid_x_summation += centroid_x_read[self.name + "_centroid_x_rbv"][ + "value" + ] + centroid_y_summation += centroid_y_read[self.name + "_centroid_y_rbv"][ + "value" + ] + + centroid_x_mean = centroid_x_summation / self.values_to_average centroid_y_mean = centroid_y_summation / self.values_to_average - centroid_x_read[self.name+"_centroid_x_rbv"]["value"] = centroid_x_mean - centroid_y_read[self.name+"_centroid_y_rbv"]["value"] = centroid_y_mean + centroid_x_read[self.name + "_centroid_x_rbv"]["value"] = centroid_x_mean + centroid_y_read[self.name + "_centroid_y_rbv"]["value"] = centroid_y_mean od = OrderedDict() - - od[self.name+"_centroid_x_rbv"] = centroid_x_read[self.name+"_centroid_x_rbv"] - od[self.name+"_centroid_y_rbv"] = centroid_y_read[self.name+"_centroid_y_rbv"] - - return od + od[self.name + "_centroid_x_rbv"] = centroid_x_read[ + self.name + "_centroid_x_rbv" + ] + od[self.name + "_centroid_y_rbv"] = centroid_y_read[ + self.name + "_centroid_y_rbv" + ] + return od def voltage_list_generator(initial_list, increment): @@ -72,11 +76,11 @@ def voltage_list_generator(initial_list, increment): The generator takes an initial list of voltages and an increment. It will apply this increment once to each element fron 0..n in turn. This is how a pencil scan applies voltages. - + Args: initial_list: the pre-increment list of voltages increment: float to increment each element by in turn - + Yields: A list of floats to apply to bimorph mirror """ @@ -97,7 +101,6 @@ def slit_position_generator_2d( number_of_slit_positions: int, slit_dimension: SlitDimension, ): - """Generator that yields positions to write to a 2d slit for a pencil beam scan. Yields positions that vary across one dimension, while keeping the other constant. @@ -179,7 +182,9 @@ def pencil_beam_scan_2d_slit( print("Turning bimorph on...") bimorph.protected_set(bimorph.on_off, 1) - start_voltages = bimorph.read_from_all_channels_by_attribute(ChannelAttribute.VOUT_RBV) + start_voltages = bimorph.read_from_all_channels_by_attribute( + ChannelAttribute.VOUT_RBV + ) # By default, if no initial voltages supplied, use current voltages as start: if initial_voltage_list is None: @@ -209,9 +214,8 @@ def pencil_beam_scan_2d_slit( inactive_slit_center, inactive_slit_size, number_of_slit_positions, - active_dimension + active_dimension, ): - yield from bps.mv(slit, slit_position) yield from bps.create()