utils

This module consists of a number of utils classes and functions

class pype_schema.utils.ContentsType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Class to represent any possible contents, whether they are sludge, water, or gas

class pype_schema.utils.DigesterType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enum to represent types of digesters

class pype_schema.utils.DosingType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enum to represent types of dosing

class pype_schema.utils.PumpType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Enum to represent constant vs. variable drive pumps

pype_schema.utils.count_args(func_str)[source]

Count the arguments for a lambda function string

Parameters:

func_str (str) – A string representation of a lambda function

Returns:

The lambda function’s number of arguments

Return type:

int

pype_schema.utils.get_tag_sum_lambda_func(unit_ids)[source]

Generate a lambda function string to sum tags

Parameters:

unit_ids (list) – A list of unit IDs to sum

Returns:

A string representation of a lambda function that sums tags

Return type:

str

pype_schema.utils.parse_quantity(value, units)[source]

Convert a value and unit string to a Pint quantity

Parameters:
  • value (float)

  • units (str)

Returns:

a Pint Quantity with the given value and units

Return type:

pint.Quantity

pype_schema.utils.parse_units(units)[source]

Convert a unit string to a Pint Unit object

Parameters:

units (str)

Returns:

a Pint Unit for the given string

Return type:

Unit

pype_schema.utils.recursive_get(key, dict_)[source]

Recursively search a nested dictionary for a key

Parameters:
  • key (str) – Key to search

  • dict_ (dict) – (nested) dictionary to search

Returns:

Value of the key if found, None otherwise

Return type:

any, None

pype_schema.utils.select_objs_helper(obj, obj_source_node=None, obj_dest_node=None, obj_source_unit_id=None, obj_dest_unit_id=None, obj_exit_point=None, obj_entry_point=None, source_id=None, dest_id=None, source_unit_id=None, dest_unit_id=None, exit_point_id=None, entry_point_id=None, source_node_type=None, dest_node_type=None, exit_point_type=None, entry_point_type=None, tag_type=None, recurse=False)[source]

Helper to select from objects which match source/destination node class, unit ID, and contents

Parameters:
  • obj ([Node, Connection, Tag]) – Object to check if it meets the specified filtering criteria

  • obj_source_node (Node) – Optional source Node to check the type and id of. None by default

  • obj_dest_node (Node) – Optional destination Node to check the type and id of. None by default

  • obj_source_unit_id (int, str) – Object’s source unit ID to match against. None by default

  • obj_dest_unit_id (int, str) – Object’s destination unit ID to match against. None by default

  • obj_exit_point (Node) – Optional exit_point Node to check the type and id of. None by default

  • obj_entry_point (Node) – Optional entry_point Node to check the type and id of. None by default

  • source_id (str) – Optional id of the source node to filter by. None by default

  • dest_id (str) – Optional id of the destination node to filter by. None by default

  • source_unit_id (int, str) – Optional unit id of the source to filter by. None by default

  • dest_unit_id (int, str) – Optional unit id of the destination to filter by. None by default

  • source_node_type (class) – Optional source Node subclass to filter by. None by default

  • dest_node_type (class) – Optional destination Node subclass to filter by. None by default

  • tag_type (TagType) – Optional tag type to filter by. None by default

  • recurse (bool) – Whether to search for objects within nodes. False by default

Raises:
  • ValueError – When a source/destination node type is provided to subset tags

  • TypeError – When the objects to select among are not of type {‘pype_schema.Tag’ or pype_schema.Connection}

Returns:

True if obj fits the filter criteria; False otherwise.

Return type:

bool