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 (
Path) – Filepath to theDATfile, as understood by TraceWin.keep (
Literal['none','comments','all'], default:'none') – To determine which un-necessary lines in the dat file should be kept.filter_func (
Callable[[DatLine],bool] |None, default:None) – You can provide your own filters here. Takes precedence overkeep.instructions_to_insert (
Collection[Instruction|DatLine], default:()) – Some elements or commands that are not present in theDATfile but that you want to add. The default is an empty tuple.
- Return type:
- Returns:
List containing all the lines of dat_path.
- _filter_lines(dat_filecontent, keep='none', filter_func=None)[source]
Remove some
DatLinefromdat_filecontent.- Parameters:
dat_filecontent (
Sequence[DatLine]) – Content loaded from theDATfile.keep (
Literal['none','comments','all'], default:'none') – To determine which un-necessary lines in the dat file should be kept. The default is'none'.filter_func (
Callable[[DatLine],bool] |None, default:None) – You can provide your own filters here. Takes precedence overkeep.
- Return type:
- Returns:
Content of the
DATfile without undesirable content.
- _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]] |Collection[DatLine]) – Content of theDAT, line per line, word per word.dat_path (
Path) – Where to save theDAT.
- Return type: