pyiron_base.utils.parser.LogTag#

class pyiron_base.utils.parser.LogTag(tag_dict: Dict[str, Any], h5_dict: Dict[str, str] | None = None, key_dict: Dict[str, str] | None = None)[source]#

Bases: object

LogTag object to parse for a specific pattern in the output file

Parameters:
  • tag_dict (Dict[str, Any]) –

    Dictionary with tags/patterns as key and an additional dictionary to describe the data structure. The data structure dictionary can contain the following keys:

    • ”arg”: position of the argument - or dimension (“:”, “:,:”)

    • ”type”: Python data type

    • ”h5”: HDF5 key to store the information

    • ”rows”: number of rows from the line where the tag was found

    • ”splitTag”: split the tag - [True/False]

    • ”splitArg”: split the argument - [True/False]

    • ”lineSkip”: skip a line

    • ”func”: function to convert the data

  • h5_dict (Optional[Dict[str, str]]) – Translation dictionary of output tags as keys to the tags used on the HDF5 file as values. Defaults to None.

  • key_dict (Optional[Dict[str, str]]) – Translation dictionary of python internal tags as keys to the output tags as values. Defaults to None.

__init__(tag_dict: Dict[str, Any], h5_dict: Dict[str, str] | None = None, key_dict: Dict[str, str] | None = None) None[source]#

Methods

__init__(tag_dict[, h5_dict, key_dict])

apply_func(val)

Apply the function on a given value

arg()

Get tag argument

get_item(item, default)

If item is part of the current dictionary keys the corresponding value is returned otherwise the default is returned.

h5()

Translate current tag to HDF5 tag using the tag dictionary

is_func()

Check if a function is defined to convert the data - if "func" is included in the tag_dict dictionary

is_item(item_line[, start])

Check if the current line - item_line - matches one of the provided tags, if that is the case set the tag to be the current tag and update the val_list with the corresponding values.

line_skip()

Check how many lines should be skipped.

resolve_dynamic_variable(val)

Resolve dynamic variable using the key_dict dictionary

rows()

Number of rows to parse

set_item(tag_vals, log_file)

Set LogTag item

test_split()

Check if the argument or the tag should be split - if "splitArg" or "splitTag" is included in the tag_dict dictionary.

translate(item)

Translate current tag to HDF5 tag using the h5_dict dictionary

Attributes

current

Get the current tag

dyn_tags

Get dynamic tags

h5_dict

Get translation dictionary of output tags as keys to the tags used on the HDF5 file as values.

key_dict

Get translation dictionary of python internal tags as keys to the output tags as values.

tag_dict

Get tag dictionary with tags/patterns as key and an additional dictionary to describe the data structure.

tag_first_word

Get first word of the tag

tag_name

Get tag name

apply_func(val: list | dict | int | float) list | dict | int | float[source]#

Apply the function on a given value

Parameters:

val (dict, list, float, int) – value to apply the function on

Returns:

result of applying the function

Return type:

dict, list, float, int

arg() str[source]#

Get tag argument

Returns:

tag arguments

Return type:

str

property current: Dict[str, Any]#

Get the current tag

Returns:

current tag

Return type:

dict

property dyn_tags: dict#

Get dynamic tags

Returns:

dynamic tags

Return type:

dict

get_item(item: str, default: Any) list | dict | int | float[source]#

If item is part of the current dictionary keys the corresponding value is returned otherwise the default is returned.

Parameters:
  • item (str) – dictionary key

  • default (list, dict, int, float) – Default value

Returns:

The values connected to the key item in the current dictionary and if item is not a

key in the current dictionary return the default value.

Return type:

list, dict, int, float

h5() str[source]#

Translate current tag to HDF5 tag using the tag dictionary

Returns:

hdf5 key name

Return type:

str

property h5_dict: dict#

Get translation dictionary of output tags as keys to the tags used on the HDF5 file as values.

Returns:

h5 dictionary

Return type:

dict

is_func() bool[source]#

Check if a function is defined to convert the data - if “func” is included in the tag_dict dictionary

Returns:

[True/ False]

Return type:

bool

is_item(item_line: str, start: int = 0) bool[source]#

Check if the current line - item_line - matches one of the provided tags, if that is the case set the tag to be the current tag and update the val_list with the corresponding values.

Parameters:
  • item_line (str) – Line of the output file

  • start (int) – Character to start with when parsing the item_line - default=0

Returns:

[True/False]

Return type:

bool

property key_dict: dict#

Get translation dictionary of python internal tags as keys to the output tags as values.

Returns:

key dictionary

Return type:

dict

line_skip() bool[source]#

Check how many lines should be skipped.

Returns:

[True/ False]

Return type:

bool

resolve_dynamic_variable(val: list) None[source]#

Resolve dynamic variable using the key_dict dictionary

Parameters:

val – values to resolve

rows() int | str[source]#

Number of rows to parse

Returns:

number of rows

Return type:

int, str

set_item(tag_vals: dict, log_file: Logstatus) Tuple[str, dict, int, bool][source]#

Set LogTag item

Parameters:
  • tag_vals (dict) – tag value dictionary

  • log_file (Logstatus) – Logstatus object

Returns:

tag name, tag values, rows, line skip [True/False]

Return type:

list

property tag_dict: dict#

Get tag dictionary with tags/patterns as key and an additional dictionary to describe the data structure. The data structure dictionary can contain the following keys: - “arg”: position of the argument - or dimension (“:”, “:,:”) - “type”: Python data type - “h5”: HDF5 key to store the information - “rows”: number of rows from the line where the tag was found - “splitTag”: split the tag - [True/False] - “splitArg”: split the argument - [True/False] - “lineSkip”: skip a line - “func”: function to convert the data

Returns:

tag dictionary

Return type:

dict

property tag_first_word: str#

Get first word of the tag

Returns:

first word

Return type:

str

property tag_name: str#

Get tag name

Returns:

tag name

Return type:

str

test_split() bool[source]#

Check if the argument or the tag should be split - if “splitArg” or “splitTag” is included in the tag_dict dictionary.

Returns:

[True/ False]

Return type:

bool

translate(item: str) str[source]#

Translate current tag to HDF5 tag using the h5_dict dictionary

Parameters:

item (str) – Python tag

Returns:

HDF5 tag

Return type:

str