load module

Define functions to load and preprocess the TraceWin files.

load_dat_file(dat_path, *, keep='none', instructions_to_insert=())[source]

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 (Literal['none', 'comments', 'empty lines', 'all'], default: 'none') – To determine which un-necessary lines in the dat file should be kept.

  • instructions_to_insert (Collection[Instruction], default: ()) – Some elements or commands that are not present in the DAT file but that you want to add.

Return type:

list[list[str]]

Returns:

List containing all the lines of dat_path.

_strip_comments(line)[source]

Remove comments from a line.

Parameters:

line (str)

Return type:

str

_split_named_elements(line)[source]

Split named elements from a line.

Parameters:

line (str)

Return type:

list[str]

_split_weighted_elements(line)[source]

Split elements with parentheses into separate parts.

Parameters:

line (str)

Return type:

list[str]

slice_dat_line(line)[source]

Slice a .dat line into its components.

Parameters:

line (str)

Return type:

list[str]

table_structure_file(path)[source]

Load the file produced by Data Save table to file.

Parameters:

path (Path)

Return type:

list[list[str]]

results(path, prop)[source]

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.

Return type:

ndarray

Returns:

Array containing the desired property.

transfer_matrices(path)[source]

Load the transfer matrix as calculated by TraceWin.

Parameters:

path (Path)

Return type:

tuple[ndarray, ndarray, ndarray]

_transfer_matrix(lines)[source]

Load a single element transfer matrix.

Parameters:

lines (list[str])

Return type:

ndarray