11import logging as log
22from math import ceil
3- from typing import Any , Dict , List
3+ from typing import Any
44
55import numpy as np
66from cothread import Sleep
@@ -29,7 +29,7 @@ def __init__(self, machine: Machine) -> None:
2929 """
3030 super ().__init__ (machine )
3131
32- def run (self , components_pair : List [Components ]) -> RawData :
32+ def run (self , components_pair : list [Components ]) -> RawData :
3333 """The Simultaneous Fast BBA Process.
3434
3535 Args:
@@ -38,8 +38,8 @@ def run(self, components_pair: List[Components]) -> RawData:
3838 Returns:
3939 The RawData object.
4040 """
41- rawdata : Dict [str , Any ] = {}
42- metadata : Dict [str , Any ] = {}
41+ rawdata : dict [str , Any ] = {}
42+ metadata : dict [str , Any ] = {}
4343 config = self ._machine .config .get_settings ()
4444 metadata .update (config )
4545 metadata ["method" ] = "SimFastBBA"
@@ -51,12 +51,15 @@ def run(self, components_pair: List[Components]) -> RawData:
5151
5252 log .info (f"BPM: { components_pair [0 ].bpm_name } " )
5353 for quadrupole , quad_name in zip (
54- components_pair [0 ].quadrupoles , components_pair [0 ].quadrupoles_names
54+ components_pair [0 ].quadrupoles ,
55+ components_pair [0 ].quadrupoles_names ,
56+ strict = True ,
5557 ):
5658 log .debug (f"BPM: { components_pair [0 ].bpm_name } " )
5759 log .debug (f"Quad: { quad_name } of { components_pair [0 ].quadrupoles_names } " )
5860 log .debug (
59- f"Corrector1: { components_pair [0 ].corrector_name } , Corrector2: { components_pair [1 ].corrector_name } "
61+ f"Corrector1: { components_pair [0 ].corrector_name } , "
62+ f"Corrector2: { components_pair [1 ].corrector_name } "
6063 )
6164 (
6265 quad_start ,
@@ -184,9 +187,9 @@ def select_data(
184187 self ,
185188 data : np .ndarray ,
186189 plane_index : int ,
187- exc_data : List [Excitation ],
190+ exc_data : list [Excitation ],
188191 decimated : bool ,
189- ) -> List [np .ndarray ]:
192+ ) -> list [np .ndarray ]:
190193 """Extract FA data that covers the excitations exc_high and exc_low.
191194
192195 The input data array should cover the full length of both excitations.
@@ -201,15 +204,12 @@ def select_data(
201204 """
202205 # Note: array data must include the timestamps.
203206 exc_high , exc_low = exc_data
204- log .debug ("Raw data shape: {}" .format (data .shape ))
207+ log .debug (f"Raw data shape: { data .shape } " )
208+ log .debug (f"Timestamp range in raw data: { data [0 , 0 , 0 ]} - { data [- 1 , 0 , 0 ]} " )
209+ log .debug (f"Excitation length: { exc_high .count } " )
205210 log .debug (
206- "Timestamp range in raw data: {} - {}" .format (data [0 , 0 , 0 ], data [- 1 , 0 , 0 ])
207- )
208- log .debug ("Excitation length: {}" .format (exc_high .count ))
209- log .debug (
210- "Trailing data to crop: {}." .format (
211- data [- 1 , 0 , 0 ] - (exc_low .start_time + exc_low .count )
212- )
211+ f"Trailing data to crop: "
212+ f"{ data [- 1 , 0 , 0 ] - (exc_low .start_time + exc_low .count )} ."
213213 )
214214 assert exc_high .count == exc_low .count , "Excitations different lengths"
215215 # Extract timestamps from data
@@ -222,7 +222,7 @@ def select_data(
222222 length = ceil (exc_high .count / 10 ) if decimated else exc_high .count
223223 high_data = data [high_start : high_start + length , :, plane_index ]
224224 low_data = data [low_start : low_start + length , :, plane_index ]
225- log .debug ("Selected data shape: {} {}" . format ( high_data .shape , low_data .shape ) )
225+ log .debug (f "Selected data shape: { high_data .shape } { low_data .shape } " )
226226 assert high_data .shape == low_data .shape
227227 return [high_data , low_data ]
228228
@@ -295,8 +295,8 @@ def analyse(self, rawdata: RawData) -> Results:
295295 bpm_index = bpm_number - np .sum (
296296 enabled_bpms [:bpm_number ] == False # noqa false positive
297297 )
298- results : Dict [str , List [float ]] = {}
299- plotting : Dict [str , Dict [str , np .ndarray ]] = {}
298+ results : dict [str , list [float ]] = {}
299+ plotting : dict [str , dict [str , np .ndarray ]] = {}
300300
301301 quad_names = []
302302 for key in data .keys ():
@@ -323,9 +323,13 @@ def analyse(self, rawdata: RawData) -> Results:
323323 good = q_diff .std (0 ) > q_diff .std (0 ).max () / 2
324324 q_diff_good = q_diff [:, good ]
325325
326- # Use a single fit operation, then transform with the straight line equation
326+ # Use a single fit operation, then transform with straight line equation
327+ oscillation_midpoint = (
328+ q_high_clean [:, bpm_index ] + q_low_clean [:, bpm_index ]
329+ ) / 2
330+ oscillation_size = q_diff_good
327331 fit = np .polynomial .polynomial .polyfit (
328- q_high_clean [:, bpm_index ], q_diff_good , 1
332+ oscillation_midpoint , oscillation_size , 1
329333 )
330334 p = np .array ([1 / fit [1 ], - fit [0 ] / fit [1 ]]).T
331335
@@ -335,8 +339,8 @@ def analyse(self, rawdata: RawData) -> Results:
335339
336340 # plotting data
337341 plotting [key ] = {
338- "x" : q_high_clean [:, bpm_index ] / NM_TO_MM_UNIT_CONV ,
339- "y" : q_diff_good / NM_TO_MM_UNIT_CONV ,
342+ "x" : oscillation_midpoint / NM_TO_MM_UNIT_CONV ,
343+ "y" : oscillation_size / NM_TO_MM_UNIT_CONV ,
340344 }
341345
342346 offsets = self .create_offsets_dict (results , metadata )
0 commit comments