dat_files module

Define functions to load, modify and create .dat structure files.

Todo

Insert line skip at each section change in the output.dat

dat_filecontent_from_file(dat_path, *, keep='none', filter_func=None, instructions_to_insert=())[source]

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

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

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

  • filter_func (Callable) – You can provide your own filters here. Takes precedence over keep.

  • instructions_to_insert (Collection[Instruction | DatLine], 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[DatLine]

_filter_lines(dat_filecontent, keep='none', filter_func=None)[source]

Remove some DatLine from dat_filecontent.

Parameters:
  • dat_filecontent (Sequence[DatLine]) – Content loaded from the .dat file.

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

  • filter_func (Callable[[DatLine], bool], optional) – You can provide your own filters here. Takes precedence over keep.

Returns:

Content of the .dat file without undesirable content.

Return type:

list[DatLine]

_insert_instructions(dat_filecontent, instructions_to_insert=())[source]

Insert the desired instructions in the dat_filecontent.

Parameters:
Return type:

None

dat_filecontent_from_smaller_list_of_elements(original_instructions, elts)[source]

Create a .dat with only elements of elts (and concerned commands).

Properties of the FIELD_MAP, i.e. amplitude and phase, remain untouched.

Parameters:
Return type:

tuple[list[DatLine], list[Instruction]]

_is_needed_element(instruction, indexes_to_keep)[source]

Tell if the instruction is an element that we must keep.

Parameters:
Return type:

bool

_is_useful_command(instruction, indexes_to_keep)[source]

Tell if the current command has an influence on our elements.

Parameters:
Return type:

bool

export_dat_filecontent(dat_filecontent, dat_path)[source]

Save the content of the updated dat to a .dat.

Parameters:
  • dat_filecontent (Collection[Collection[str]]) – Content of the .dat, line per line, word per word.

  • dat_path (pathlib.Path) – Where to save the .dat.

Return type:

None