iprPy.input package

Module contents

boolean(value: str | bool) bool

Allows conversion of strings to Booleans.

Parameters:

value (str or bool) – If str, then ‘true’ and ‘t’ become True and ‘false’ and ‘f’ become false. If bool, simply return the value.

Returns:

Equivalent bool of value.

Return type:

bool

Raises:

ValueError – If value is unrecognized.

buildcombos(style: str, database, keys: list, content_dict: dict | None = None, **kwargs) Tuple[dict, dict]

Wrapper function for the modular buildcombos styles

Parameters:
  • style (str) – The buildcombos style to use

  • database (iprPy.database.Database) – The database to use in building combos

  • keys (list) – The calculation multikey set to build combos for

  • content_dict (dict, optional) – Contains loaded file content. If not given, an empty dict will be created

  • kwargs (any) – Additional keyword arguments will be used to limit which records from the database are used in building combos values.

Returns:

  • inputs (dict) – Contains the values generated for each key

  • content_dict (dict) – Contains loaded file content

dicttoterm(param_dict: dict) str

Takes a dictionary and converts it into a single str term that can be parsed by termtodict().

Parameters:

param_dict (dict) – The dictionary of separated parameter terms.

Returns:

The single str term representation.

Return type:

str

parse(inscript: str | IOBase, singularkeys: List[str] | None = None, allsingular: bool = False) dict

Parses an input file and returns a dictionary of parameter terms.

These are the parsing rules:

  • The first word in a line is taken as the key name of the parameter.

  • All other words are joined together into a single string value for the parameter.

  • Words that start with # indicate comments with that word and all words to the right of it in the same line being ignored.

  • Any lines with less than two non-comment terms are ignored. In other words, blank lines and lines with keys but not values are skipped over.

  • Multiple values can be assigned to the same term by repeating the key name on a different line.

  • The keyword arguments can be used to issue an error if multiple values are trying to be assigned to terms that should only have a single values.

Parameters:
  • inscript (string or file-like-object) – The file, path to file, or contents of the input script to parse.

  • singularkeys (list of str, optional) – List of term keys that should not have multiple values.

  • allsingular (bool, optional) – Indicates if all term keys should be singular (Default is False).

Returns:

params – Dictionary of parsed input key-value pairs

Return type:

dict

Raises:

ValueError – If both singularkeys and allsingular are given, or if multiple values found for a singular key.

termtodict(term: str, keys: List[str]) dict

Takes a str term and parses it into a dictionary of key-value pairs based on the supplied key list.

Parameters:
  • term (str) – The str term to parse.

  • keys (list of str) – The list of keys to parse by.

Returns:

Dictionary of parsed key-value terms.

Return type:

dict

Raises:

ValueError – If any key appears multiple times or the first word in term does not match a key.

value(input_dict: dict, key: str, default_unit: str | None = None, default_term: str | None = None) float

Interprets a calculation parameter by converting it from a string to a float in working units.

The parameter being converted is a str with one of two formats: - ‘<number>’ - ‘<number> <unit>’

Parameters:
  • input_dict (dict) – Dictionary containing input parameter key-value pairs.

  • key (str) – The key of input_dict to evaluate.

  • default_unit (str, optional) – Default unit to use if not specified in the parameter value. If not given, then no unit conversion will be done on unitless parameter values.

  • default_term (str, optional) – Default str parameter value to use if key not in input_dict. Can be specified as ‘<value> <unit>’ to ensure that the default value is always the same regardless of the working units or default_unit. If not given, then key must be in input_dict.

Returns:

The interpreted value of the input parameter’s str value in the working units.

Return type:

float