tracewin_utils.load module

Define functions to load and preprocess the TraceWin files.

FIELD_MAP_LOADERS = {'.edz': <function electric_field_1d>}
_get_number_of_cells(f_z: list[float]) int

Count number of times the array of z-electric field changes sign.

See SO.

_split_named_elements(line: str) list[str]

Split named elements from a line.

_split_weighted_elements(line: str) list[str]

Split weighted elements from a line.

_strip_comments(line: str) str

Remove comments from a line.

_transfer_matrix(lines: list[str]) ndarray

Load a single element transfer matrix.

electric_field_1d(path: Path) tuple[int, float, float, ndarray, int]

Load a 1D electric field (.edz extension).

Parameters:

path (Path) – The path to the .edz file to load.

Returns:

  • n_z (int) – Number of steps in the array.

  • zmax (float) – z position of the filemap end.

  • norm (float) – Electric field normalisation factor. It is different from k_e (6th argument of the FIELD_MAP command). Electric fields are normalised by k_e/norm, hence norm should be unity by default.

  • f_z (np.ndarray) – Array of electric field in MV/m.

  • n_cell (int) – Number of cells in the cavity.

load_dat_file(dat_path: Path, *, keep: Literal['none', 'comments', 'empty lines', 'all'] = 'none', instructions_to_insert: Collection[Instruction] = ()) list[list[str]]

Load the dat file and convert it into a list of lines.

Parameters:
  • dat_path (Path) – Filepath to the .dat file, as understood by TraceWin.

  • keep ({"none", "comments", "empty lines", "all"}, optional) – To determine which un-necessary lines in the dat file should be kept. The default is 'none'.

  • instructions_to_insert (Collection[Instruction], optional) – Some elements or commands that are not present in the .dat file but that you want to add. The default is an empty tuple.

Returns:

dat_filecontent – List containing all the lines of dat_path.

Return type:

list[list[str]]

results(path: Path, prop: str) ndarray

Load a property from TraceWin’s “Data” table.

Parameters:
  • path (Path) – Path to results file. It must be saved from TraceWin: Data > Save table to file.

  • prop (str) – Name of the desired property. Must be in d_property.

Returns:

data_ref – Array containing the desired property.

Return type:

numpy array

slice_dat_line(line: str) list[str]

Slices a .dat line into its components.

table_structure_file(path: Path) list[list[str]]

Load the file produced by Data Save table to file.

transfer_matrices(path: Path) tuple[ndarray, ndarray, ndarray]

Load the transfer matrix as calculated by TraceWin.