@@ -46,17 +46,17 @@ def read_tbt(file_path: str | Path, version: Version = Version.two) -> TbtData:
4646
4747 match version :
4848 case Version .one :
49- reader = VersionOne (file_path )
49+ read_data = VersionOneReader (file_path )
5050 case Version .two :
51- reader = VersionTwo (file_path )
51+ read_data = VersionTwoReader (file_path )
5252 case _:
5353 raise ValueError (f"Version { version } unknown for IOTA reader." )
5454
55- return reader .tbt_data
55+ return read_data .tbt_data
5656
5757
58- class Reader (abc .ABC ):
59- """ Class that reads the IOTA turn-by-turn data.
58+ class AbstractIotaReader (abc .ABC ):
59+ """Class that reads the IOTA turn-by-turn data.
6060
6161 This abstract class implements the whole reading in its `__init__`,
6262 but cannot run by itself, as the version specific functions (see below)
@@ -75,7 +75,7 @@ def __init__(self, path: Path):
7575 self .tbt_data = self ._read_turn_by_turn_data ()
7676
7777 def _prepare (self ):
78- """ Prepare attributes and check that the correct version is used. """
78+ """Prepare attributes and check that the correct version is used."""
7979 bpm_names = [self .map_bpm_name (key ) for key in self .hdf5_file if self .is_bpm_key (key )]
8080 if not bpm_names :
8181 msg = f"Wrong version of the IOTA-HDF5 format was used for file { self .path !s} !"
@@ -87,7 +87,7 @@ def _prepare(self):
8787 self .nturns : int = self ._get_number_of_turns ()
8888
8989 def _read_turn_by_turn_data (self ) -> TbtData :
90- """ Create the turn-by-turn data object. """
90+ """Read data and create the turn-by-turn data object."""
9191 return TbtData (
9292 bunch_ids = [1 ],
9393 nturns = self .nturns ,
@@ -112,8 +112,8 @@ def _read_turn_by_turn_data(self) -> TbtData:
112112 )
113113
114114 def _get_data_for_plane (self , plane : str ) -> np .ndarray :
115- """ Extract the turn-by-turn data for the given plane as numpy array,
116- truncated to the maximum common number of turns. """
115+ """Extract the turn-by-turn data for the given plane as numpy array,
116+ truncated to the maximum common number of turns."""
117117 data = np .zeros ((self .nbpms , self .nturns ))
118118 bpm_keys = [key for key in self .hdf5_file if self .is_bpm_key (key , plane )]
119119
@@ -123,8 +123,8 @@ def _get_data_for_plane(self, plane: str) -> np.ndarray:
123123 return data
124124
125125 def _get_number_of_turns (self ) -> int :
126- """ Get the maximum common number of tuns over all BPMs,
127- such that the arrays can be trimmed to be of equal lengths. """
126+ """Get the maximum common number of tuns over all BPMs,
127+ such that the arrays can be trimmed to be of equal lengths."""
128128 return min (
129129 len (self ._get_data_for_key (key , plane ))
130130 for plane in ("X" , "Y" )
@@ -133,59 +133,59 @@ def _get_number_of_turns(self) -> int:
133133 )
134134
135135 def _get_data_for_key (self , key : str , plane : Literal ["X" , "Y" ]) -> np .ndarray :
136- """ Extract the turn-by-turn data for the given key and plane as numpy array. """
136+ """Extract the turn-by-turn data for the given key and plane as numpy array."""
137137 ...
138138
139139 @staticmethod
140140 def map_bpm_name (key : str ) -> str :
141- """ Convert the given key to a BPM name. """
141+ """Convert the given key to a BPM name."""
142142 ...
143143
144144 @staticmethod
145145 def is_bpm_key (key : str , plane : Literal ["X" , "Y" ] | None = None ) -> bool :
146- """ Check if the entry of the file contains BPM data. """
146+ """Check if the entry of the file contains BPM data."""
147147 ...
148148
149149
150- class VersionOne ( Reader ):
151- """ Version 1 contains three keys per BPM: X, Y and Intensity. """
150+ class VersionOneReader ( AbstractIotaReader ):
151+ """Version 1 contains three keys per BPM: X, Y and Intensity."""
152152
153153 planes : dict [str , str ] = {"X" : "H" , "Y" : "V" }
154154
155155 def _get_data_for_key (self , key : str , plane : Literal ["X" , "Y" ]) -> np .ndarray :
156- """ Extract the turn-by-turn data for the given key and plane as numpy array. """
156+ """Extract the turn-by-turn data for the given key and plane as numpy array."""
157157 return self .hdf5_file [key ] # assumes plane is already in key name
158158
159159 @staticmethod
160160 def map_bpm_name (key : str ) -> str :
161- """ Convert the given key to a BPM name. """
161+ """Convert the given key to a BPM name."""
162162 return f"IBPM{ key [4 :- 1 ]} "
163163
164164 @staticmethod
165165 def is_bpm_key (key : str , plane : Literal ["X" , "Y" ] | None = None ) -> bool :
166- """ Check if the entry of the file contains BPM data. """
166+ """Check if the entry of the file contains BPM data."""
167167 is_bpm = ("state" not in key ) or key .startswith ("N:" )
168168 if plane is None :
169- return is_bpm and (key .endswith (VersionOne .planes ["X" ]) or key .endswith (VersionOne .planes ["Y" ]))
170- return is_bpm and key .endswith (VersionOne .planes [plane ])
169+ return is_bpm and (key .endswith (VersionOneReader .planes ["X" ]) or key .endswith (VersionOneReader .planes ["Y" ]))
170+ return is_bpm and key .endswith (VersionOneReader .planes [plane ])
171171
172172
173- class VersionTwo ( Reader ):
174- """ Version 2 contains a single key per BPM, which contains data for both planes
175- (and possibly more which we ignore). """
173+ class VersionTwoReader ( AbstractIotaReader ):
174+ """Version 2 contains a single key per BPM, which contains data for both planes
175+ (and possibly more which we ignore)."""
176176
177177 planes : dict [str , str ] = {"X" : "Horizontal" , "Y" : "Vertical" }
178178
179179 def _get_data_for_key (self , key : str , plane : Literal ["X" , "Y" ]) -> np .ndarray :
180- """ Extract the turn-by-turn data for the given key and plane as numpy array. """
180+ """Extract the turn-by-turn data for the given key and plane as numpy array."""
181181 return self .hdf5_file [key ][self .planes [plane ]]
182182
183183 @staticmethod
184184 def map_bpm_name (key : str ) -> str :
185- """ Convert the given key to a BPM name. """
185+ """Convert the given key to a BPM name."""
186186 return f"IBPM{ key } "
187187
188188 @staticmethod
189189 def is_bpm_key (key : str , plane : Literal ["X" , "Y" ] | None = None ) -> bool :
190- """ Check if the entry of the file contains BPM data. """
190+ """Check if the entry of the file contains BPM data."""
191191 return "NL" not in key and not key .startswith ("N:" ) # latter: filter v1 data to be safe
0 commit comments