iprPy.tools package

Module contents

aslist(term: Any) list

Create list representation of term. Treats a str term as a single item.

Parameters:

term (any) – Term to convert into a list, if needed.

Returns:

All items in term as a list.

Return type:

list

dict_insert(d: dict, key: Any, value: Any, **kwargs)

Adds a new key, value pair into a dictionary by inserting it relative to a known key.

Parameters:
  • d (dict) – The dict to add the new key, value to.

  • key (any) – The new dict key to insert.

  • value (any) – The dict value to assign to d[key].

  • before (any, optional) – If given, then the new key will be inserted before this key. Cannot be given with after.

  • after (any, optional) – If given, then the new key will be inserted after this key. Cannot be given with before

dynamic_import(module_name: str, ignorelist: list | None = None) Tuple[dict, dict]

Dynamically imports classes stored in submodules and makes them directly accessible by style name within the returned loaded dictionary.

Parameters:
  • module_name (str) – The name of the module to start from

  • ignorelist (list, optional) – A list of submodules that should be excluded from the import.

Returns:

  • loaded (dict) – Contains the derived classes that were successfully loaded and accessible by style name (root submodule).

  • failed (dict) – Contains the raised error messages for each class that failed to load.

filltemplate(template: str | IOBase, variable: dict, s_delimiter: str, e_delimiter: str) str

Takes a template and fills in values for delimited template variables.

Parameters:
  • template (string or file-like object) – The template file or file content to fill in.

  • variable (dict) – Dictionary with keys defining the delimited template variable terms, and values the values to replace the variable terms with.

  • s_delimiter (str) – The leading delimiter for identifying the template variable terms.

  • e_delimiter (str) – The trailing delimiter for identifying the template variable terms.

Returns:

The template with all delimited variable terms replaced with their corresponding defined values from variable.

Return type:

str

Raises:
  • KeyError – If delimited term found in template that has no value in variable.

  • ValueError – If parsing of s_delimiter, e_delimiter pairs fails.

iaslist(term: Any) Generator[Any, None, None]

Iterate over items in term as if term was a list. Treats a str term as a single item.

Parameters:

term (any) – Term to iterate over.

Yields:

any – Items in the list representation of term.

num_deriv_3_point(x: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], y: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) ndarray

Evaluates the numerical derivative of a tabulated series using three values per point, i.e. fits a second order polynomial and finds the derivative at the point in question. For equally spaced points, this is the 3 point central difference for the intermediate points and 3 point forward/backward difference for the end points.

Parameters:
  • x (array-like object) – The x coordinates where the y values are evaluated. Should be in order and evenly spaced.

  • y (array-like object) – The y coordinates to find derivatives of.

Returns:

The computed numerical derivative of dy/dx.

Return type:

numpy.ndarray

read_calc_file(parent_module: str, filename: str) str

Loads a file from the working directory if it is there, or from within iprPy if not. Allows for quick modifications.

Parameters:
  • parent_module (str) – The name of the parent module where the file resource should be located.

  • filename (str) – The name of the file to read/get content for.

screen_input(prompt: str = '') str

Replacement input function that is compatible with the mingw terminal.

Parameters:

prompt (str, optional) – The screen prompt to use for asking for the input.

Returns:

The user input.

Return type:

str