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
DATfile, 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
DATfile 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:
- _filter_lines(dat_filecontent, keep='none', filter_func=None)[source]
Remove some
DatLinefromdat_filecontent.- Parameters:
dat_filecontent (Sequence[DatLine]) – Content loaded from the
DATfile.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
DATfile without undesirable content.- Return type:
- _insert_instructions(dat_filecontent, instructions_to_insert=())[source]
Insert the desired instructions in the
dat_filecontent.- Parameters:
instructions_to_insert (
Collection[Instruction|DatLine], default:())
- Return type:
- dat_filecontent_from_smaller_list_of_elements(original_instructions, elts)[source]
Create a
DATwith only elements ofelts(and concerned commands).Properties of the FIELD_MAP, i.e. amplitude and phase, remain untouched.
- Parameters:
original_instructions (
Sequence[Instruction])elts (
Collection[Element])
- 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:
instruction (
Instruction)
- Return type:
- _is_useful_command(instruction, indexes_to_keep)[source]
Tell if the current command has an influence on our elements.
- Parameters:
instruction (
Instruction)
- Return type:
- 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: