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: Path, *, keep: Literal['none', 'comments', 'all'] = 'none', filter_func: Callable[[DatLine], bool] | None = None, instructions_to_insert: Collection[Instruction | DatLine] = ()) list[DatLine]
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: Sequence[DatLine], keep: Literal['none', 'comments', 'all'] = 'none', filter_func: Callable[[DatLine], bool] | None = None) list[DatLine]
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: list[DatLine], instructions_to_insert: Collection[Instruction | DatLine] = ()) None
Insert the desired instructions in the
dat_filecontent.
- dat_filecontent_from_smaller_list_of_elements(original_instructions: Sequence[Instruction], elts: Collection[Element]) tuple[list[DatLine], list[Instruction]]
Create a
.datwith only elements ofelts(and concerned commands).Properties of the FIELD_MAP, i.e. amplitude and phase, remain untouched.
- _is_needed_element(instruction: Instruction, indexes_to_keep: Container[int]) bool
Tell if the instruction is an element that we must keep.
- _is_useful_command(instruction: Instruction, indexes_to_keep: Iterable[int]) bool
Tell if the current command has an influence on our elements.
- export_dat_filecontent(dat_filecontent: Collection[Collection[str]] | Collection[DatLine], dat_path: Path) None
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.