Skip to content

Commit

Permalink
Auto format
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-fernandes committed Aug 13, 2024
1 parent b0d326c commit d22622d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
25 changes: 12 additions & 13 deletions src/mx_bluesky/bimorph_optimisation_plan/data_saver.py
Original file line number Diff line number Diff line change
@@ -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
"""
Expand All @@ -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
Expand All @@ -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
"""
Expand Down Expand Up @@ -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
"""
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class SlitDimension(Enum):
X: Represents X dimension
Y: Represents Y dimension
"""
X = "X",

X = ("X",)
Y = "Y"


Expand All @@ -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

Expand All @@ -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):
Expand All @@ -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
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d22622d

Please sign in to comment.