pype_schema package

Subpackages

Submodules

pype_schema.connection module

class pype_schema.connection.Connection[source]

Bases: ABC

Abstract class for all connections

Variables:
  • id (str) – Connection ID

  • contents (ContentsType) – Contents moving through the node

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • tags (dict of Tag) – Data tags associated with this connection

  • bidirectional (bool) – Whether flow can go from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

add_tag(tag)[source]

Adds a tag to the node

Parameters:

tag (Tag) – Tag object to add to the node

bidirectional: bool = False
contents: ContentsType = NotImplemented
destination: Node = NotImplemented
entry_point: Node = None
exit_point: Node = None
get_dest_id()[source]
Returns:

name of the destination node

Return type:

str

get_dest_node(recurse=False)[source]

Gets a connection’s destination node, returning its entry point if recurse is True

Parameters:

recurse (bool) – Return entry_point if True. Otherwise just return destination

Returns:

The destination node corresponding to connection

Return type:

pype_schema.Node

get_entry_point()[source]
Returns:

name of the entry point Node (if it exists - None otherwise)

Return type:

str

get_exit_point()[source]
Returns:

name of the exit point Node (if it exists - None otherwise)

Return type:

str

get_num_dest_units()[source]
Returns:

number of units in the destination node

Return type:

int

get_num_source_units()[source]
Returns:

number of units in the source node

Return type:

int

get_source_id()[source]
Returns:

name of the source node

Return type:

str

get_source_node(recurse=False)[source]

Gets a connection’s source node returning its exit point if recurse is True

Parameters:

recurse (bool) – Return exit_point if True. Otherwise just return source

Returns:

The source node corresponding to connection

Return type:

pype_schema.Node

get_tag(tag_name)[source]

Adds a tag to the node

Parameters:

tag_name (str) – Name of the tag to receive

id: str = NotImplemented
remove_tag(tag_name)[source]

Removes a tag from the node

Parameters:

tag_name (str) – name of tag to remove

source: Node = NotImplemented
tags: dict = NotImplemented
class pype_schema.connection.Delivery(id, contents, source, destination, frequency=None, tags={}, bidirectional=False, exit_point=None, entry_point=None)[source]

Bases: Connection

A class to represent a connection via delivery, such as monthly chemical deliveries or weekly trash disposal.

Parameters:
  • id (str) – Delivery ID

  • contents (ContentsType) – Contents moving through the connection

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • frequency (pint.Quantity or float) – If a pint quantity it will be interpreted based on units. E.g., 0.25 days will be interpreted as 0.25 days between deliveries, or in other words 4 deliveries per day. Whereas 0.25 / day would indicate there is a quarter of a delivery per day, or more intuitively 4 days between each delivery. If unitless, assumed to be number of days between delivery

  • tags (dict of Tag) – Data tags associated with this pump

  • bidirectional (bool) – Whether deliveries are made from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

Variables:
  • id (str) – Pipe ID

  • contents (ContentsType) – Contents moving through the connection.

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • tags (dict of Tag) – Data tags associated with this pipe

  • bidirectional (bool) – Whether deliveries are made from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

class pype_schema.connection.Pipe(id, contents, source, destination, min_flow, max_flow, design_flow, diameter=None, friction=None, min_pres=None, max_pres=None, design_pres=None, lower_heating_value=None, higher_heating_value=None, tags={}, bidirectional=False, exit_point=None, entry_point=None)[source]

Bases: Connection

A generic class for pipes that transport any fluid, such as drinking water, natural gas, or industrial wastewater.

Parameters:
  • id (str) – Pipe ID

  • contents (ContentsType) – Contents moving through the connection

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • min_flow (pint.Quantity or int) – Minimum flow rate through the pipe

  • max_flow (pint.Quantity or int) – Maximum flow rate through the pipe

  • avg_flow (pint.Quantity or int) – Average flow rate through the pipe

  • diameter (pint.Quantity or int) – Pipe diameter

  • friction (float) – Friction coefficient for the pipe

  • min_pres (pint.Quantity or int) – Minimum pressure inside the pipe

  • max_pres (pint.Quantity or int) – Maximum pressure inside the pipe

  • design_pres (pint.Quantity or int) – Design pressure of the pipe

  • lower_heating_value (float) – Lower heating value of gas in the pipe

  • higher_heating_value (float) – Higher heating value of gas in the pipe

  • tags (dict of Tag) – Data tags associated with this pipe

  • bidirectional (bool) – Whether flow can go from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

Variables:
  • id (str) – Pipe ID

  • contents (ContentsType) – Contents moving through the connection

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • min_flow (pint.Quantity or int) – Minimum flow rate through the pipe

  • max_flow (pint.Quantity or int) – Maximum flow rate through the pipe

  • design_flow (pint.Quantity or int) – Design flow rate through the pipe

  • diameter (pint.Quantity or int) – Pipe diameter

  • friction_coeff (int) – Friction coefficient for the pipe

  • min_pressure (pint.Quantity or int) – Minimum pressure inside the pipe

  • max_pressure (pint.Quantity or int) – Maximum pressure inside the pipe

  • design_pressure (pint.Quantity or int) – Design pressure of the pipe

  • heating_values (tuple) – The lower and higher heating values of the gas in the pipe. None if the pipe is not transporting gas

  • tags (dict of Tag) – Data tags associated with this pipe

  • bidirectional (bool) – Whether flow can go from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

del_design_flow()[source]
del_design_pressure()[source]
del_max_flow()[source]
del_max_pressure()[source]
del_min_flow()[source]
del_min_pressure()[source]
property design_flow
property design_pressure
get_design_flow()[source]
get_design_pressure()[source]
get_max_flow()[source]
get_max_pressure()[source]
get_min_flow()[source]
get_min_pressure()[source]
property max_flow
property max_pressure
property min_flow
property min_pressure
set_design_flow(design_flow)[source]
set_design_pressure(design_pressure)[source]
set_flow_rate(min, max, design)[source]

Set the minimum, maximum, and average flow rate through the connection

Parameters:
  • min (int) – Minimum flow rate through the connection

  • max (int) – Maximum flow rate through the connection

  • design (int) – Design flow rate through the connection

set_heating_values(lower, higher)[source]

Set the lower and higher heating values for gas in the connection

Parameters:
  • lower (float) – Lower heating value of gas in the pipe

  • higher (float) – Higher heating value of gas in the pipe

set_max_flow(max_flow)[source]
set_max_pressure(max_pressure)[source]
set_min_flow(min_flow)[source]
set_min_pressure(min_pressure)[source]
set_pressure(min, max, design)[source]

Set the minimum, maximum, and average pressure inside the connection

Parameters:
  • min (int) – Minimum pressure inside the connection

  • max (int) – Maximum pressure inside the connection

  • design (int) – Design pressure inside the connection

class pype_schema.connection.Wire(id, contents, source, destination, tags={}, bidirectional=False, exit_point=None, entry_point=None)[source]

Bases: Connection

A class for representing electrical connections.

Parameters:
  • id (str) – Wire ID

  • contents (ContentsType) – Contents moving through the connection.

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • tags (dict of Tag) – Data tags associated with this wire

  • bidirectional (bool) – Whether electricity can flow from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

Variables:
  • id (str) – Pipe ID

  • contents (ContentsType) – Contents moving through the connection.

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • tags (dict of Tag) – Data tags associated with this pipe

  • bidirectional (bool) – Whether electricity can flow from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

class pype_schema.connection.Wireless(id, contents, source, destination, tags={}, bidirectional=False, exit_point=None, entry_point=None)[source]

Bases: Connection

A class for representing electrical connections.

Parameters:
  • id (str) – Wireless connection ID

  • contents (ContentsType) – Contents moving through the connection.

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • tags (dict of Tag) – Data tags associated with this wire

  • bidirectional (bool) – Whether data can flow from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

Variables:
  • id (str) – Pipe ID

  • contents (ContentsType) – Contents moving through the connection.

  • source (Node) – Starting point of the connection

  • destination (Node) – Endpoint of the connection

  • tags (dict of Tag) – Data tags associated with this pipe

  • bidirectional (bool) – Whether data can flow from destination to source. False by default

  • exit_point (Node) – The child node from which this connection leaves its source. Default is None, indicating the source does not have any children

  • entry_point (Node) – The child node at which this connection enters its destination. Default is None, indicating the destination does not have any children

pype_schema.epyt_utils module

class pype_schema.epyt_utils.NpEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

Custom JSON encoder for numpy types

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return super().default(o)
pype_schema.epyt_utils.epyt2pypes(inp_file, out_file, add_nodes=False, use_name_as_id=False, content_placeholder='DrinkingWater')[source]

Convert an EPANET input file to a PYPES JSON file

Parameters:
  • inp_file (str) – Path to the EPANET input file

  • out_file (str) – Path to the PYPES JSON file

  • add_nodes (bool) – Whether to add additional nodes of Pumps

  • use_name_as_id (bool) – Whether to use the node name as the node id. False by default, and ignored if add_nodes is True

Returns:

dictionary of Node, Connection, and VirtualTag objects with keys “nodes”, “connections”, and “virtual_tags”

Return type:

dict

pype_schema.logbook module

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

Bases: Enum

Enum to represent codes associated with logbook entries

Critical = 4
Error = 3
Info = 1
Warning = 2
class pype_schema.logbook.LogEntry(timestamp, text, code=LogCode.Info)[source]

Bases: object

A single text log entry in the digital Logbook with associated timestamp and code (e.g., info or error)

Parameters:
  • timestamp (datetime.datetime) – The timestamp for the entry

  • text (str) – The text portion of the entry

  • code (LogCode) – The code associated with the entry. Default is Info

Variables:
  • timestamp (datetime.datetime) – The timestamp for the entry

  • text (str) – The text portion of the entry

  • code (LogCode) – The code associated with the entry. Default is Info

pprint()[source]

Pretty print this entry

class pype_schema.logbook.Logbook(entries=None)[source]

Bases: object

A digital logbook with built-in querying.

Parameters:

entries (dict) – Dictionary of the form { int : LogEntry }. Default is an empty dictionary

Variables:

entries (dict) – Dictionary of the form { int : LogEntry }

add_entry(timestamp, text, code=LogCode.Info)[source]

Modifies self.entries to add the desired text with associated timestamp and code (e.g., info or error). Entries are saved with an automatically incremented counter as their ID.

Parameters:
  • timestamp (datetime.datetime) – The timestamp for the entry to be added

  • text (str) – Plaintext logbook entry

  • code (LogCode) – Code associated with the entry. Default is Info

load_entries(filepath)[source]

Adds all the logbook entries from the given filepath. Supports both JSON and CSV file formats.

Parameters:

filpath (str) – The path to the file to load logbook entries from

Raises:

ValueError – When file extension is not json or csv

next_entry_id()[source]

Gets the next entry ID by checking the current maximum ID

Returns:

ID for the next logbook entry

Return type:

int

print_query(start_dt, end_dt=None, keyword=None, code=None)[source]

Queries logbook entries based on timestamp, keywords, and code. Pretty prints the queried entries, and then also returns them

Parameters:
  • start_dt (datetime.datetime) – First datetime to include in the timestamps of log entries to return.

  • end_dt (datetime.datetime) – Final datetime to include in the timestamps of log entries to return. None by default, meaning that all entries after start_dt will be returned

  • keyword (str) – Keyword to find in the log entry. None by default

  • code (LogCode) – The code associated with desired logbook entries. None by default, meaning all codes will be included

Returns:

Dictionary of logbook entries between start_dt and end_dt that contain keyword and have a matching code

Return type:

dict

query(start_dt, end_dt=None, keyword=None, code=None)[source]

Queries logbook entries based on timestamp, keywords, and code.

Parameters:
  • start_dt (datetime.datetime) – First datetime to include in the timestamps of log entries to return.

  • end_dt (datetime.datetime) – Final datetime to include in the timestamps of log entries to return. None by default, meaning that all entries after start_dt will be returned

  • keyword (str) – Keyword to find in the log entry. None by default

  • code (LogCode) – The code associated with desired logbook entries. None by default, meaning all codes will be included

Returns:

Dictionary of logbook entries between start_dt and end_dt that contain keyword and have a matching code

Return type:

dict

remove_entry(entry_id)[source]

Modifies self.entries

Parameters:

timestamp (datetime.datetime) – The timestamp for the entry to be removed

save_query(start_dt, end_dt=None, keyword=None, code=None, outpath='')[source]

Queries logbook entries based on timestamp, keywords, and code. Saves the queried entries, and then also returns them

Parameters:
  • start_dt (datetime.datetime) – First datetime to include in the timestamps of log entries to return.

  • end_dt (datetime.datetime) – Final datetime to include in the timestamps of log entries to return. None by default, meaning that all entries after start_dt will be returned

  • keyword (str) – Keyword to find in the log entry. None by default

  • code (LogCode) – The code associated with desired logbook entries. None by default, meaning all codes will be included

  • outpath (str) – Path where logbook will be saved. Supported filetypes are JSON and CSV. Default path is “”, meaning that no file will be written

Returns:

Dictionary of logbook entries between start_dt and end_dt that contain keyword and have a matching code

Return type:

dict

to_csv(outpath='')[source]

Save the current Logbook as a CSV file

Parameters:

outpath (str) – Path where logbook will be saved. Default is “”, meaning no file will be saved

Returns:

csv in DataFrame format

Return type:

pandas.DataFrame

to_json(outpath='', indent=4)[source]

Save the current Logbook as a JSON file

Parameters:
  • outpath (str) – Path where logbook will be saved. Default is “”, meaning that no file will be written

  • indent (int) – number of spaces to indent the JSON file. Default is 4

Returns:

json in dictionary format

Return type:

dict

pype_schema.node module

class pype_schema.node.Aeration(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, tags={})[source]

Bases: Node

A generic class for an aeration basin.

Parameters:
  • id (str) – Aerator ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the aeration basin

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the aeration basin

  • min_flow (pint.quantity or float) – Minimum flow rate of a single aeration basin

  • max_flow (pint.quantity or float) – Maximum flow rate of a single aeration basin

  • design_flow (pint.quantity or float) – Design flow rate of a single aeration basin

  • num_units (int) – Number of aeration basins running in parallel

  • volume (pint.quantity or float) – Volume of a single aeration basin in cubic meters

  • tags (dict of Tag) – Data tags associated with this aerator

Variables:
  • id (str) – Aerator ID

  • input_contents (list of ContentsType) – Contents entering the aeration basin

  • output_contents (list of ContentsType) – Contents leaving the aeration basin

  • num_units (int) – Number of aeration basins running in parallel

  • volume (pint.quantity or float) – Volume of a single aeration basin in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single aeration basin

  • max_flow (pint.quantity or float) – Maximum flow rate of a single aeration basin

  • design_flow (pint.quantity or float) – Design flow rate of a single aeration basin

  • tags (dict of Tag) – Data tags associated with this aerator

class pype_schema.node.Battery(id, energy_capacity, charge_rate, discharge_rate, rte, leakage, tags={})[source]

Bases: Node

A generic battery with metadata such as roundtrip efficiency (RTE), energy capacity, and charge/discharge rates.

Parameters:
  • id (str) – Battery ID

  • energy_capacity (int) – Energy storage capacity of the battery in kWh

  • charge_rate (int) – Maximum charge rate of the battery in kW

  • discharge_rate (int) – Maximum discharge rate of the battery in kW

  • rte (float) – Round trip efficiency of the battery

  • leakage (pint.Quantity or float) – Leakage of the battery as a Pint Quantity

  • tags (dict of Tag) – Data tags associated with this battery

Variables:
  • id (str) – Battery ID

  • input_contents (list of ContentsType) – Contents entering the battery.

  • output_contents (list of ContentsType) – Contents leaving the battery.

  • energy_capacity (int) – Energy storage capacity of the battery in kWh

  • charge_rate (int) – Maximum discharge rate of the battery in kW

  • discharge_rate (int) – Maximum discharge rate of the battery in kW

  • rte (float) – Round trip efficiency of the battery

  • leakage (pint.Quantity or float) – Leakage of the battery as a Pint Quantity

  • tags (dict of Tag) – Data tags associated with this battery

property charge_rate
del_charge_rate()[source]
del_energy_capacity()[source]
del_leakage()[source]
del_rte()[source]
property energy_capacity
get_charge_rate()[source]
get_energy_capacity()[source]
get_leakage()[source]
get_rte()[source]
property leakage
property rte
set_charge_rate(charge_rate)[source]
set_energy_capacity(energy_capacity)[source]
set_leakage(leakage)[source]
set_rte(rte)[source]
class pype_schema.node.Boiler(id, input_contents, min_gen, max_gen, design_gen, num_units, tags={})[source]

Bases: Node

A class representing a boiler that produces heat through natural gas combustion.

Parameters:
  • id (str) – Boiler ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the boiler

  • min_gen (int) – Minimum generation capacity of a single boiler

  • max_gen (int) – Maximum generation capacity of a single boiler

  • design_gen (int) – Design generation capacity of a single boiler

  • num_units (int) – Number of boiler units running in parallel

  • tags (dict of Tag) – Data tags associated with this boiler

Variables:
  • id (str) – Boiler ID

  • input_contents (list of ContentsType) – Contents entering the boiler (biogas, natural gas, or a blend of the two)

  • output_contents (list of ContentsType) – Contents leaving the boiler (Electricity)

  • min_gen (int) – Minimum generation capacity of a single boiler

  • max_gen (int) – Maximum generation capacity of a single boiler

  • design_gen (int) – Design generation capacity of a single boiler

num_unitsint

Number of boiler units running in parallel

tagsdict of Tag

Data tags associated with this boiler

thermal_efficiencyfunction

Function which takes in the current kWh and returns the efficiency as a fraction

del_design_gen()[source]
del_max_gen()[source]
del_min_gen()[source]
property design_gen
get_design_gen()[source]
get_max_gen()[source]
get_min_gen()[source]
property max_gen
property min_gen
set_design_gen(design_gen)[source]
set_gen_capacity(min, max, design)[source]

Set the minimum, maximum, and average generation capacity

Parameters:
  • min (int) – Minimum generation by a single cogenerator

  • max (int) – Maximum generation by a single cogenerator

  • design (int) – Design generation by a single cogenerator

set_max_gen(max_gen)[source]
set_min_gen(min_gen)[source]
set_thermal_efficiency(efficiency_curve)[source]

Set the cogeneration efficiency to the given function

Parameters:

efficiency_curve (function) – function takes in the current kWh and returns the fractional efficency

class pype_schema.node.Chlorination(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, dosing_rate={}, residence_time=None, tags={})[source]

Bases: Disinfection

A class for a chlorination basin.

Parameters:
  • id (str) – Chlorinator ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the chlorinator

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the chlorinator

  • min_flow (pint.quantity or float) – Minimum flow rate of a single chlorinator

  • max_flow (pint.quantity or float) – Maximum flow rate of a single chlorinator

  • design_flow (pint.quantity or float) – Design flow rate of a single chlorinator

  • num_units (int) – Number of chlorinators running in parallel

  • volume (pint.quantity or float) – Volume of a single chlorinator in cubic meters

  • dosing_rate (dict of DosingType:float) – Dosing information for the chlorinator (key: DosingType, value: rate)

  • residence_time (pint.Quantity or float) – Residence time of the chlorinator

  • tags (dict of Tag) – Data tags associated with this chlorinator

Variables:
  • id (str) – Chlorinator ID

  • input_contents (list of ContentsType) – Contents entering the chlorinator

  • output_contents (list of ContentsType) – Contents leaving the chlorinator

  • num_units (int) – Number of chlorinators running in parallel

  • volume (pint.quantity or float) – Volume of a single chlorinator in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single chlorinator

  • max_flow (pint.quantity or float) – Maximum flow rate of a single chlorinator

  • design_flow (pint.quantity or float) – Design flow rate of a single chlorinator

  • dosing_rate (dict of DosingType:float) – Dosing information for the chlorinator (key: DosingType, value: rate)

  • residence_time (pint.Quantity or float) – Residence time of the chlorinator

  • tags (dict of Tag) – Data tags associated with this chlorinator

class pype_schema.node.Clarification(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, tags={})[source]

Bases: Node

A class representing a generic clarifier, sedimentation tank, or settling basin.

Parameters:
  • id (str) – Clarifier ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the clarifier

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the clarifier

  • min_flow (pint.quantity or float) – Minimum flow rate of a single clarifier

  • max_flow (pint.quantity or float) – Maximum flow rate of a single clarifier

  • design_flow (pint.quantity or float) – Design flow rate of a single clarifier

  • num_units (int) – Number of clarifiers running in parallel

  • volume (pint.quantity or float) – Volume of the clarifier in cubic meters

  • tags (dict of Tag) – Data tags associated with this clarifier

Variables:
  • id (str) – Clarifier ID

  • input_contents (list of ContentsType) – Contents entering the clarifier

  • output_contents (list of ContentsType) – Contents leaving the clarifier

  • num_units (int) – Number of clarifiers running in parallel

  • volume (pint.quantity or float) – Volume of a single clarifier in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single clarifier

  • max_flow (pint.quantity or float) – Maximum flow rate of a single clarifier

  • design_flow (pint.quantity or float) – Design flow rate of a single clarifier

  • tags (dict of Tag) – Data tags associated with this clarifier

class pype_schema.node.Cogeneration(id, input_contents, min_gen, max_gen, design_gen, num_units, tags={})[source]

Bases: Node

A class representing a cogeneration engine that produces both heat and electricity through biogas and/or natural gas combustion.

Parameters:
  • id (str) – Cogenerator ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the cogenerator

  • min_gen (int) – Minimum generation capacity of a single cogenerator

  • max_gen (int) – Maximum generation capacity of a single cogenerator

  • design_gen (int) – Design generation capacity of a single cogenerator

  • num_units (int) – Number of cogenerator units running in parallel

  • tags (dict of Tag) – Data tags associated with this cogenerator

Variables:
  • id (str) – Cogenerator ID

  • input_contents (list of ContentsType) – Contents entering the cogenerator (biogas, natural gas, or a blend of the two)

  • output_contents (list of ContentsType) – Contents leaving the cogenerator (Electricity)

  • min_gen (int) – Minimum generation capacity of a single cogenerator

  • max_gen (int) – Maximum generation capacity of a single cogenerator

  • design_gen (int) – Average generation capacity of a single cogenerator

  • num_units (int) – Number of cogenerator units running in parallel

  • tags (dict of Tag) – Data tags associated with this cogenerator

  • electrical_efficiency (function) – Function which takes in the current kWh and returns the electrical efficiency as a fraction

  • thermal_efficiency (function) – Function which takes in the current kWh and returns the thermal efficiency as a fraction

del_design_gen()[source]
del_max_gen()[source]
del_min_gen()[source]
property design_gen
get_design_gen()[source]
get_max_gen()[source]
get_min_gen()[source]
property max_gen
property min_gen
set_design_gen(design_gen)[source]
set_electrical_efficiency(efficiency_curve)[source]

Set the cogeneration efficiency to the given function

Parameters:

efficiency_curve (function) – function takes in the current kWh and returns the fractional efficency

set_gen_capacity(min, max, design)[source]

Set the minimum, maximum, and average generation capacity

Parameters:
  • min (int) – Minimum generation by a single cogenerator

  • max (int) – Maximum generation by a single cogenerator

  • design (int) – Design generation by a single cogenerator

set_max_gen(max_gen)[source]
set_min_gen(min_gen)[source]
set_thermal_efficiency(efficiency_curve)[source]

Set the cogeneration efficiency to the given function

Parameters:

efficiency_curve (function) – function takes in the current kWh and returns the fractional efficency

class pype_schema.node.Conditioning(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, tags={})[source]

Bases: Node

A class for representing biogas conditioners. The conditioner prepares ‘raw’ biogas from the digester by removing impurities and readying it for combustion for Cogeneration.

Parameters:
  • id (str) – Conditioner ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the biogas conditioner

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the biogas conditioner

  • min_flow (pint.quantity or float) – Minimum flow rate of a single biogas conditioner

  • max_flow (pint.quantity or float) – Maximum flow rate of a single biogas conditioner

  • design_flow (pint.quantity or float) – Design flow rate of a single biogas conditioner

  • num_units (int) – Number of biogas conditioners running in parallel

  • tags (dict of Tag) – Data tags associated with this biogas conditioner

Variables:
  • id (str) – Conditioner ID

  • input_contents (list of ContentsType) – Contents entering the biogas conditioner

  • output_contents (list of ContentsType) – Contents leaving the biogas conditioner

  • num_units (int) – Number of biogas conditioners running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate of a single biogas conditioner

  • max_flow (pint.quantity or float) – Maximum flow rate of a single biogas conditioner

  • design_flow (pint.quantity or float) – Design flow rate of a single biogas conditioner

  • tags (dict of Tag) – Data tags associated with this screen

class pype_schema.node.Digestion(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, digester_type, tags={})[source]

Bases: Node

A class representing a sludge digester, either aerobic or anaerobic.

Parameters:
  • id (str) – Digester ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the digester (e.g. biogas or wastewater)

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the digester (e.g. biogas or wastewater)

  • min_flow (pint.quantity or float) – Minimum flow rate through the digester

  • max_flow (pint.quantity or float) – Maximum flow rate through the digester

  • design_flow (pint.quantity or float) – Design flow rate through the digester

  • num_units (int) – Number of digesters running in parallel

  • volume (pint.quantity or float) – Volume of the digester in cubic meters

  • digester_type (DigesterType) – Type of digestion (aerobic or anaerobic)

  • tags (dict of Tag) – Data tags associated with this digester

Variables:
  • id (str) – Digester ID

  • input_contents (list of ContentsType) – Contents entering the digester (e.g. biogas or wastewater)

  • output_contents (list of ContentsType) – Contents leaving the digester (e.g. biogas or wastewater)

  • num_units (int) – Number of digesters running in parallel

  • volume (pint.quantity or float) – Volume of the digester in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate through the digester

  • max_flow (pint.quantity or float) – Maximum flow rate through the digester

  • design_flow (pint.quantity or float) – Design flow rate through the digester

  • digester_type (DigesterType) – Type of digestion (aerobic or anaerobic)

  • tags (dict of Tag) – Data tags associated with this digester

class pype_schema.node.Disinfection(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, dosing_rate={}, residence_time=None, tags={})[source]

Bases: Node

A generic class for a disinfection process, such as chlorination, ozone, or UV light.

Parameters:
  • id (str) – Disinfector ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the disinfector

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the disinfector

  • min_flow (pint.quantity or float) – Minimum flow rate of a single disinfector

  • max_flow (pint.quantity or float) – Maximum flow rate of a single disinfector

  • design_flow (pint.quantity or float) – Design flow rate of a single disinfector

  • num_units (int) – Number of disinfectors running in parallel

  • volume (pint.quantity or float) – Volume of a single disinfectors in cubic meters

  • dosing_rate (dict of DosingType:float) – Dosing information for the disinfector (key: DosingType, value: rate)

  • residence_time (pint.Quantity or float) – Residence time of the disinfector

  • tags (dict of Tag) – Data tags associated with this disinfector

Variables:
  • id (str) – Disinfector ID

  • input_contents (list of ContentsType) – Contents entering the disinfector

  • output_contents (list of ContentsType) – Contents leaving the disinfector

  • num_units (int) – Number of disinfector running in parallel

  • volume (pint.quantity or float) – Volume of a single disinfector in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single disinfector

  • max_flow (pint.quantity or float) – Maximum flow rate of a single disinfector

  • design_flow (pint.quantity or float) – Design flow rate of a single disinfector

  • dosing_rate (dict of DosingType:float) – Dosing information for the disinfector (key: DosingType, value: rate)

  • residence_time (pint.Quantity or float) – Residence time of the disinfector

  • tags (dict of Tag) – Data tags associated with this disinfector

del_dosing_rate()[source]
del_residence_time()[source]
property dosing_rate
get_dosing_rate()[source]
get_residence_time()[source]
property residence_time
set_dosing_rate(dosing_rate)[source]
set_residence_time(residence_time)[source]
class pype_schema.node.Facility(id, input_contents, output_contents, elevation, min_flow, max_flow, design_flow, tags={}, nodes={}, connections={})[source]

Bases: Network

A class representing any industrial facility from wastewater treatment to desalination to solid waste management.

Parameters:
  • id (str) – Facility ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the network.

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the network.

  • elevation (pint.quantity or float) – Elevation of the facility

  • min_flow (pint.quantity or float) – Minimum flow rate through the facility

  • max_flow (pint.quantity or float) – Maximum flow rate through the facility

  • design_flow (pint.quantity or float) – Design flow rate through the facility

  • tags (dict of Tag) – Data tags associated with this facility

  • nodes (dict of Node) – nodes in the facility, e.g. pumps, tanks, or processes

  • connections (dict of Connections) – connections in the facility, e.g. pipes

Variables:
  • id (str) – Facility ID

  • input_contents (list of ContentsType) – Contents entering the facility.

  • output_contents (list of ContentsType) – Contents leaving the facility.

  • elevation (pint.quantity or float) – Elevation of the facility in meters above sea level

  • tags (dict of Tag) – Data tags associated with this facility

  • min_flow (pint.quantity or float) – Minimum flow rate through the facility

  • max_flow (pint.quantity or float) – Maximum flow rate through the facility

  • design_flow (pint.quantity or float) – Design flow rate through the facility

  • nodes (dict of Node) – nodes in the facility, e.g. pumps, tanks, or processes

  • connections (dict of Connections) – connections in the facility, e.g. pipes

class pype_schema.node.Filtration(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, dosing_rate={}, settling_time=0.0, tags={})[source]

Bases: Node

The parent class for a wide range of filtration methods, such as sand filters, trickling filters, or reverse osmosis membranes.

Parameters:
  • id (str) – Filter ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the filter

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the filter

  • min_flow (pint.quantity or float) – Minimum flow rate of a single filter

  • max_flow (pint.quantity or float) – Maximum flow rate of a single filter

  • design_flow (pint.quantity or float) – Design flow rate of a single filter

  • num_units (int) – Number of filters running in parallel

  • volume (pint.quantity or float) – Volume of a single filter in cubic meters

  • dosing_rate (dict of DosingType:float) – Dosing information for the filter (key: DosingType, value: rate)

  • settling_time (pint.quantity or float) – time it takes for the filter to reach the desired operation mode in seconds

  • tags (dict of Tag) – Data tags associated with this filter

Variables:
  • id (str) – Filter ID

  • input_contents (list of ContentsType) – Contents entering the filter

  • output_contents (list of ContentsType) – Contents leaving the filter

  • num_units (int) – Number of filters running in parallel

  • volume (pint.quantity or float) – Volume of a single filter in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single filter

  • max_flow (pint.quantity or float) – Maximum flow rate of a single filter

  • design_flow (pint.quantity or float) – Design flow rate of a single filter

  • dosing_rate (dict of DosingType:float) – Dosing information for the filter (key: DosingType, value: rate)

  • settling_time (pint.quantity or float) – time it takes for the filter to reach the desired operation mode

  • tags (dict of Tag) – Data tags associated with this filter

del_dosing_rate()[source]
property dosing_rate
get_dosing_rate()[source]
set_dosing_rate(dosing_rate)[source]
class pype_schema.node.Flaring(id, num_units, min_flow, max_flow, design_flow, tags={})[source]

Bases: Node

The process of combusting biogas to convert the methane to carbon dioxide before venting it to the atmosphere.

Parameters:
  • id (str) – Flare ID

  • num_units (int) – Number of flares running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate of a single flare

  • max_flow (pint.quantity or float) – Maximum flow rate of a single flare

  • design_flow (pint.quantity or float) – Design flow rate of a single flare

  • tags (dict of Tag) – Data tags associated with this flare

Variables:
  • id (str) – Flare ID

  • input_contents (list of ContentsType) – Contents entering the flare

  • num_units (int) – Number of flares running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate of a single flare

  • max_flow (pint.quantity or float) – Maximum flow rate of a single flare

  • design_flow (pint.quantity or float) – Design flow rate of a single flare

  • tags (dict of Tag) – Data tags associated with this flare

class pype_schema.node.Junction(id, input_contents, output_contents, diameter=None, tags={})[source]

Bases: Node

A junction in the network where multiple pipes meet.

Parameters:
  • id (str) – Junction ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the junction

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the junction

  • diamater (pint.Quantity) – Diameter of the junction

  • tags (dict of Tag) – Data tags associated with this junction

class pype_schema.node.ModularUnit(id, input_contents, output_contents, num_units, tags={}, nodes={}, connections={})[source]

Bases: Network

Modular Unit in the network, such as a reverse osmosis skid.

Parameters:
  • id (str) – ModularUnit ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the ModularUnit.

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the ModularUnit.

  • tags (dict of Tag) – Data tags associated with this ModularUnit

  • nodes (dict of Node) – nodes in the ModularUnit, e.g. pumps, tanks, or filters

  • connections (dict of Connections) – connections in the ModularUnit, e.g. pipes

  • num_units (int) – Number of units running in parallel

Variables:
  • id (str) – ModularUnit ID

  • input_contents (list of ContentsType) – Contents entering the ModularUnit.

  • output_contents (list of ContentsType) – Contents leaving the ModularUnit.

  • tags (dict of Tag) – Data tags associated with this ModularUnit

  • nodes (dict of Node) – nodes in the ModularUnit, e.g. pumps, tanks, or filters

  • num_units (int) – Number of units running in parallel

  • connections (dict of Connections) – connections in the ModularUnit, e.g. pipes

class pype_schema.node.Network(id, input_contents, output_contents, tags={}, nodes={}, connections={}, num_units=1)[source]

Bases: Node

A water utility represented as a set of connections and nodes

Parameters:
  • id (str) – Network ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the network.

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the network.

  • tags (dict of Tag) – Data tags associated with this network

  • nodes (dict of Node) – nodes in the network, e.g. pumps, tanks, or facilities

  • connections (dict of Connections) – connections in the network, e.g. pipes

  • num_units (int, default 1) – Number of units in the network

Variables:
  • id (str) – Network ID

  • input_contents (list of ContentsType) – Contents entering the network.

  • output_contents (list of ContentsType) – Contents leaving the network.

  • tags (dict of Tag) – Data tags associated with this network

  • nodes (dict of Node) – nodes in the network, e.g. pumps, tanks, or facilities

  • connections (dict of Connections) – connections in the network, e.g. pipes

  • num_units (int) – Number of networks running in parallel

add_connection(connection)[source]

Adds a connection to the network

Parameters:

connection (Connection) – Connection object to add to the network

add_node(node)[source]

Adds a node to the network

Parameters:

node (Node) – Node object to add to the network

get_list_of_type(desired_type, recurse=False)[source]

Searches the Facility and returns a list of all objects of desired_type

Parameters:
  • desired_type (Node or Connection subclass)

  • recurse (bool) – Whether or not to get objects recursively. Default is False, meaning that only direct children will be returned.

Returns:

Objects of desired_type inside this Facility. If recurse is True, all children, grandchildren, etc. are returned. If False, only direct children are returned.

Return type:

list of desired_type

remove_connection(connection_name, recurse=False)[source]

Removes a connection from the network

Parameters:
  • connection_name (str) – name of connection to remove

  • recurse (bool)

Raises:

KeyError – if connection_name is not found

remove_node(node_name, recurse=False)[source]

Removes a node from the network

Parameters:
  • node_name (str) – name of node to remove

  • recurse (bool) – Whether or not to removed nodes recursively. Default is False, meaning that only direct children will be removed.

Raises:

KeyError – if node_name is not found

class pype_schema.node.Node[source]

Bases: ABC

Abstract class for all nodes

Variables:
  • id (str) – Node ID

  • input_contents (list of ContentsType) – Contents entering the node.

  • output_contents (list of ContentsType) – Contents leaving the node.

  • tags (dict of Tag) – Data tags associated with this node

add_tag(tag)[source]

Adds a tag to the node

Parameters:

tag (Tag) – Tag object to add to the node

del_design_flow()[source]
del_max_flow()[source]
del_min_flow()[source]
property design_flow
get_all_connections(recurse=False)[source]

Gets all Connection objects associated with this Node

Parameters:

recurse (bool) – Whether or not to get connections recursively. Default is False, meaning that only direct children will be returned.

Returns:

Connection objects inside this Node. If recurse is True, all children, grandchildren, etc. are returned. If False, only direct children are returned.

Return type:

list of Connection

get_all_connections_from(node)[source]

Gets all connections leaving the specified Node, including those from a different level of the hierarchy with exit_point specified.

Paremeters

nodeNode

pype_schema Node object for which we want to get connections

returns:

List of Connection objects leaving the specified node

rtype:

list of Connection

get_all_connections_to(node)[source]

Gets all connections entering the specified Node, including those from a different level of the hierarchy with entry_point specified.

Paremeters

nodeNode

pype_schema Node object for which we want to get connections

returns:

List of Connection objects entering the specified node

rtype:

list of Connection

get_all_nodes(recurse=False)[source]

Gets all Node objects associated with this Node

Parameters:

recurse (bool) – Whether or not to get nodes recursively. Default is False, meaning that only direct children will be returned.

Returns:

Node objects inside this Node. If recurse is True, all children, grandchildren, etc. are returned. If False, only direct children are returned.

Return type:

list of Node

get_all_tags(virtual=True, recurse=False)[source]

Gets all Tag objects associated with this Node

Parameters:
  • virtual (bool) – Whether to include VirtualTag objects or just regular Tag. True by default.

  • recurse (bool) – Whether or not to get tags recursively. Default is False, meaning that only tags involving direct children (and this Node itself) will be returned.

Returns:

Tag objects inside this Node. If recurse is True, all children, grandchildren, etc. are returned. If False, only direct children are returned.

Return type:

list of Tag and VirtualTag

get_capacities()[source]

Gets a dictionary of capacity-related attributes

Returns:

Dictionary of attribute names and values

Return type:

dict

get_connection(connection_name, recurse=False)[source]

Get a connection from the network

Parameters:
  • connection_name (str) – name of connection to retrieve

  • recurse (bool) – Whether or not to get connections recursively. Default is False, meaning that only direct children will be returned.

Returns:

Connection object if node is found. None otherwise

Return type:

Connection or None

get_design_flow()[source]
get_efficiencies()[source]

Gets a dictionary of efficiency-related attributes

Returns:

Dictionary of attribute names and values

Return type:

dict

get_max_flow()[source]
get_min_flow()[source]
get_node(node_name, recurse=False)[source]

Get a node from the network

Parameters:
  • node_name (str) – name of node to retrieve

  • recurse (bool) – Whether or not to get nodes recursively. Default is False, meaning that only direct children will be returned.

Returns:

Node object if node is found. None otherwise

Return type:

Node or None

get_node_or_connection(obj_id, recurse=False)[source]

Gets the Node or Connection object with name obj_id

Parameters:
  • obj_id (str) – name of the object to query

  • recurse (bool) – Whether or not to get connections or nodes recursively. Default is False, meaning that only direct children will be returned.

Returns:

object with the name obj_id

Return type:

Node or Connection

get_parent(child_obj)[source]

Gets the parent object of a Tag, Connection, or Node object, as long as both child_obj and its parent object are children of self

Parameters:

child_obj (Tag, VirtualTag, Connection, or Node) – object for which we want the parent object

Returns:

parent object of child_obj

Return type:

Node or Connection

get_parent_from_tag(tag)[source]

Gets the parent object of a Tag object, as long as both the tag and its parent object are children of self

Parameters:

tag (Tag or VirtualTag) – object for which we want the parent object

Returns:

parent object of the Tag

Return type:

Node or Connection

get_tag(tag_name, recurse=False)[source]

Gets the Tag object associated with tag_name

Parameters:
  • tag_name (str)

  • recurse (bool) – Whether or not to get tags recursively. Default is False, meaning that only tags involving direct children (and this Node itself) will be returned.

Returns:

pype_schema Tag object associated with the variable name. Returns None if the tag_name is not found

Return type:

Tag or VirtualTag

id: str = NotImplemented
input_contents: list[pype_schema.utils.ContentsType] = NotImplemented
property max_flow
property min_flow
output_contents: list[pype_schema.utils.ContentsType] = NotImplemented
remove_tag(tag_name)[source]

Removes a tag from the node

Parameters:

tag_name (str) – name of tag to remove

select_objs(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, contents_type=None, tag_type=None, obj_type=None, recurse=False)[source]

Selects from this Node all Node, Connection, or Tag objects which match source/destination node class, unit ID, and contents. (If none given, returns all objects in self)

Parameters:
  • 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

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

  • entry_point_id (str) – Optional id of the entry_point node 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

  • exit_point_type (class) – Optional exit_point Node subclass to filter by. None by default

  • entry_point_type (class) – Optional entry_point Node subclass to filter by. None by default

  • contents_type (ContentsType) – Optional contents to filter by. None by default

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

  • obj_type ([Node, Connection, VirtualTag, Tag]) – The type of object 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, pype_schema.Connection, pype_schema.Node}

Returns:

List of Tag, Connection, or Node objects subset according to source/destination id and contents_type

Return type:

list

select_tags(tag, 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, virtual=False)[source]

Helper function for selecting Tag objects from inside a Node.

Parameters:
  • tag (Tag) – Tag object to check against the search criteria

  • 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

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

  • entry_point_id (str) – Optional id of the entry_point node 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

  • exit_point_type (class) – Optional exit_point Node subclass to filter by. None by default

  • entry_point_type (class) – Optional entry_point 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

  • virtual (bool) – True if tag is being queried as part of a VirtualTag. False by default

Returns:

True if tag meets the filtering criteria

Return type:

bool

select_virtual_tags(virtual_tag, 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 function for selecting VirtualTag objects from inside a Node.

Parameters:
  • virtual_tag (VirtualTag) – VirtualTag object to check against the search criteria

  • 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

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

  • entry_point_id (str) – Optional id of the entry_point node 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

  • exit_point_type (class) – Optional exit_point Node subclass to filter by. None by default

  • entry_point_type (class) – Optional entry_point Node subclass to filter by. None by default

  • contents_type (ContentsType) – Optional contents 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

Returns:

True if virtual_tag meets the filtering criteria

Return type:

bool

set_contents(contents, attribute='input_contents')[source]

Set the input or output contents of a node

Parameters:
  • contents (ContentsType or list of ContentsType) – Single value or list of ContentsType entering/exiting the node.

  • attribute ([“input_contents”, “output_contents”]) – Attribute to set (either input_contents or output_contents)

set_design_flow(design_flow)[source]
set_dosing(dose_rate, mode='rate')[source]

Set the dosing rate of the node

Parameters:
  • dose_rate (dict of str:float) – Dosing rate of the chemical in the node

  • mode (str) – whether or not the dosing is defined as a volumetric ‘rate’ or by ‘area’

set_flow_rate(min, max, design)[source]

Set the minimum, maximum, and design flow rate of the node

Parameters:
  • min (int) – Minimum flow rate through the node

  • max (int) – Maximum flow rate through the node

  • design (int) – Design flow rate through the node

set_max_flow(max_flow)[source]
set_min_flow(min_flow)[source]
tags: dict = NotImplemented
class pype_schema.node.PRV(id, input_contents, output_contents, diameter=None, pressure_setting=None, tags={})[source]

Bases: Valve

A pressure reducing valve.

Parameters:
  • id (str) – Pressure release valve ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the pressure release valve

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the pressure release valve

  • diameter (pint.Quantity) – Diameter of the pressure release valve

  • pressure_setting (pint.Quantity) – Rated or set pressure of the valve

  • tags (dict of Tag) – Data tags associated with this valve

class pype_schema.node.Pump(id, input_contents, output_contents, elevation, min_flow, max_flow, design_flow, power_rating, num_units, pump_type=PumpType.Constant, efficiency=None, tags={})[source]

Bases: Node

Any kind of pump, such as constant speed, variable frequency drive (VFD), energy recovery device (ERD), and air blower.

Parameters:
  • id (str) – Pump ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the pump

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the pump

  • elevation (pint.quantity or float) – Elevation of the pump in meters above sea level

  • power_rating (pint.quantity or float) – Rated power of a single pump (in horsepower)

  • num_units (int) – Number of pumps running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate supplied by the pump

  • max_flow (pint.quantity or float) – Maximum flow rate supplied by the pump

  • design_flow (pint.quantity or float) – Design flow rate supplied by the pump

  • pump_type (PumpType) – Type of pump (either VFD, ERD, AirBlower or Constant)

  • efficiency (float) – efficiency of the pump

  • tags (dict of Tag) – Data tags associated with this pump

Variables:
  • id (str) – Pump ID

  • input_contents (list of ContentsType) – Contents entering the pump

  • output_contents (list of ContentsType) – Contents leaving the pump

  • elevation (pint.quantity or float) – Elevation of the pump in meters above sea level

  • power_rating (pint.quantity or float) – Rated power of a single pump (in horsepower)

  • num_units (int) – Number of pumps running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate supplied by the pump

  • max_flow (pint.quantity or float) – Maximum flow rate supplied by the pump

  • design_flow (pint.quantity or float) – Design flow rate supplied by the pump

  • pump_type (PumpType) – Type of pump (either VFD, ERD, AirBlower or Constant)

  • tags (dict of Tag) – Data tags associated with this pump

  • pump_curve (function) – Function which takes in the current flow rate and returns the energy required to pump at that rate

del_efficiency()[source]
del_power_rating()[source]
property efficiency
get_efficiency()[source]
get_power_rating()[source]
property power_rating
set_efficiency(efficiency)[source]
set_power_rating(power_rating)[source]
set_pump_curve(pump_curve)[source]

Set the pump curve to the given function

Parameters:

pump_curve (function) – function which takes in the current flow rate and returns the energy required to pump at that rate

class pype_schema.node.ROMembrane(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, area, permeability, selectivity, dosing_rate={}, settling_time=0.0, tags={})[source]

Bases: Filtration

A class for representing a reverse osmosis membrane process.

Parameters:
  • id (str) – ROMembrane ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the RO membrane

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the RO membrane

  • min_flow (pint.quantity or float) – Minimum flow rate of the RO membrane

  • max_flow (pint.quantity or float) – Maximum flow rate of the RO membrane

  • design_flow (pint.quantity or float) – Design flow rate of a single filter

  • num_units (int) – Number of RO membranes running in parallel

  • volume (pint.quantity or float) – Volume of the RO membrane in cubic meters

  • area (pint.quantity or float) – Area of the RO membrane in square meters

  • permeability (pint.quantity or float) – Permeability of the RO membrane

  • selectivity (pint.quantity or float) – Selectivity of the RO membrane

  • dosing_rate (dict of DosingType:float) – Dosing information for the RO membrane (key: DosingType, value: rate)

  • settling_time (pint.quantity or float) – time it takes for the filter to reach the desired operation mode

  • tags (dict of Tag) – Data tags associated with the RO membrane

Variables:
  • id (str) – ROMembrane ID

  • input_contents (list of ContentsType) – Contents entering the RO membrane

  • output_contents (list of ContentsType) – Contents leaving the RO membrane

  • num_units (int) – Number of RO membranes running in parallel

  • volume (pint.quantity or float) – Volume of a single filter in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single filter

  • max_flow (pint.quantity or float) – Maximum flow rate of a single filter

  • design_flow (pint.quantity or float) – Design flow rate of a single filter

  • area (float) – Area of the RO membrane in square meters

  • permeability (float) – Permeability of the RO membrane

  • selectivity (float) – Selectivity of the RO membrane

  • dosing_rate (dict of DosingType:float) – Dosing information for the RO membrane (key: DosingType, value: rate)

  • settling_time (pint.quantity or float) – time it takes for the filter to reach the desired operation mode

  • tags (dict of Tag) – Data tags associated with the RO membrane

class pype_schema.node.Reactor(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, residence_time, dosing_rate={}, pH=None, tags={})[source]

Bases: Node

A reactor modeled as a basic tank with chemical dosing point(s).

Parameters:
  • id (str) – Reactor ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the reactor

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the reactor

  • min_flow (pint.quantity or float) – Minimum flow rate through the reactor

  • max_flow (pint.quantity or float) – Maximum flow rate through the reactor

  • design_flow (pint.quantity or float) – Design flow rate through the reactor

  • num_units (int) – Number of reactor in parallel

  • volume (pint.quantity or float) – Volume of the reactor in cubic meters

  • residence_time (pint.Quantity or float) – Residence time of the reactor

  • dosing_rate (dict of DosingType:float) – Dosing information for the reactor (key: DosingType, value: rate)

  • pH (float) – pH value for the reactor

  • tags (dict of Tag) – Data tags associated with this reactor

Variables:
  • id (str) – Reactor ID

  • input_contents (list of ContentsType) – Contents entering the reactor

  • output_contents (list of ContentsType) – Contents leaving the reactor

  • min_flow (pint.quantity or float) – Minimum flow rate through the reactor

  • max_flow (pint.quantity or float) – Maximum flow rate through the reactor

  • design_flow (pint.quantity or float) – Design flow rate through the reactor

  • num_units (int) – Number of reactors

  • volume (pint.quantity or float) – Volume of the reactor in cubic meters

  • residence_time (pint.Quantity or float) – Residence time of the reactor

  • dosing_rate (dict of DosingType:float) – Dosing information for the reactor (key: DosingType, value: rate)

  • pH (float) – pH value for the reactor

  • num_units – Number of reactors in parallel

  • tags (dict of Tag) – Data tags associated with this reactor

del_dosing_rate()[source]
property dosing_rate
get_dosing_rate()[source]
set_dosing_rate(dosing_rate)[source]
class pype_schema.node.Reservoir(id, input_contents, output_contents, elevation, volume, tags={})[source]

Bases: Node

A generic reservoir used to represent lakes and oceans in addition to manmade bodies of water.

Parameters:
  • id (str) – Reservoir ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the reservoir.

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the reservoir.

  • elevation (pint.quantity or float) – Elevation of the reservoir in meters above sea level

  • volume (pint.quantity or float) – Volume of the reservoir in cubic meters

  • tags (dict of Tag) – Data tags associated with this reservoir

Variables:
  • id (str) – Reservoir ID

  • input_contents (list of ContentsType) – Contents entering the reservoir.

  • output_contents (list of ContentsType) – Contents leaving the reservoir.

  • elevation (pint.quantity or float) – Elevation of the reservoir in meters above sea level

  • volume (pint.quantity or float) – Volume of the reservoir in cubic meters

  • tags (dict of Tag) – Data tags associated with this reservoir

class pype_schema.node.Screening(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, tags={})[source]

Bases: Node

A class representing the screening process for removing large solids from the intake of a facility, such as a bar screen.

Parameters:
  • id (str) – Screen ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the screen

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the screen

  • min_flow (pint.quantity or float) – Minimum flow rate of a single screen

  • max_flow (pint.quantity or float) – Maximum flow rate of a single screen

  • design_flow (pint.quantity or float) – Design flow rate of a single screen

  • num_units (int) – Number of screens running in parallel

  • tags (dict of Tag) – Data tags associated with this screen

Variables:
  • id (str) – Screen ID

  • input_contents (list of ContentsType) – Contents entering the screen

  • output_contents (list of ContentsType) – Contents leaving the screen

  • num_units (int) – Number of screens running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate of a single screen

  • max_flow (pint.quantity or float) – Maximum flow rate of a single screen

  • design_flow (pint.quantity or float) – Design flow rate of a single screen

  • tags (dict of Tag) – Data tags associated with this screen

class pype_schema.node.Separation(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, power_rating=None, elevation=None, tags={})[source]

Bases: Node

A class representing a separator that divides a mixture into its components, such as air separation units that produce high purity oxygen and nitrogen.

Parameters:
  • id (str) – Separator ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the separator (e.g., Air)

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the separator (e.g., Oxygen, IdealGas for Nitrogen)

  • min_flow (pint.quantity or float) – Minimum flow rate of a single separator

  • max_flow (pint.quantity or float) – Maximum flow rate of a single separator

  • design_flow (pint.quantity or float) – Design flow rate of a single separator

  • num_units (int) – Number of separators running in parallel

  • volume (pint.quantity or float) – Volume of the separator in cubic meters

  • power_rating (pint.quantity or float) – Rated power of a single separator (in horsepower or kW)

  • elevation (pint.quantity or float) – Elevation of the separator in meters above sea level

  • tags (dict of Tag) – Data tags associated with this separator

Variables:
  • id (str) – Separator ID

  • input_contents (list of ContentsType) – Contents entering the separator

  • output_contents (list of ContentsType) – Contents leaving the separator

  • num_units (int) – Number of separators running in parallel

  • min_flow (pint.quantity or float) – Minimum flow rate of a single separator

  • max_flow (pint.quantity or float) – Maximum flow rate of a single separator

  • design_flow (pint.quantity or float) – Design flow rate of a single separator

  • volume (pint.quantity or float) – Volume of the separator in cubic meters

  • power_rating (pint.quantity or float) – Rated power of a single separator

  • elevation (pint.quantity or float) – Elevation of the separator in meters above sea level

  • tags (dict of Tag) – Data tags associated with this separator

class pype_schema.node.StaticMixing(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, residence_time, dosing_rate={}, pH=None, tags={})[source]

Bases: Reactor

A tank containing a static mixer, typically used for coagulation in water treatment.

Parameters:
  • id (str) – Static mixer ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the mixer

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the mixer

  • min_flow (pint.quantity or float) – Minimum flow rate through the mixer

  • max_flow (pint.quantity or float) – Maximum flow rate through the mixer

  • design_flow (pint.quantity or float) – Design flow rate through the mixer

  • num_units (int) – Number of mixers in parallel

  • volume (pint.quantity or float) – Volume of the mixer in cubic meters

  • residence_time (pint.Quantity or float) – Residence time of the mixer

  • dosing_rate (dict of DosingType:float) – Dosing information for the mixer (key: DosingType, value: rate)

  • pH (float) – pH value for the mixer

  • tags (dict of Tag) – Data tags associated with this mixer

Variables:
  • id (str) – Static mixer ID

  • input_contents (list of ContentsType) – Contents entering the mixer

  • output_contents (list of ContentsType) – Contents leaving the mixer

  • min_flow (pint.quantity or float) – Minimum flow rate through the mixer

  • max_flow (pint.quantity or float) – Maximum flow rate through the mixer

  • design_flow (pint.quantity or float) – Design flow rate through the mixer

  • num_units (int) – Number of mixers in parallel

  • volume (pint.quantity or float) – Volume of the mixer in cubic meters

  • residence_time (pint.Quantity or float) – Residence time of the mixer

  • dosing_rate (dict of DosingType:float) – Dosing information for the mixer (key: DosingType, value: rate)

  • pH (float) – pH value for the mixer

  • tags (dict of Tag) – Data tags associated with this mixer

class pype_schema.node.Tank(id, input_contents, output_contents, elevation, volume, num_units=1, tags={})[source]

Bases: Node

A generic class to represent a storage tank. Any input_contents and output_contents can be provided and metadata such as volume and elevation can be specified.

Parameters:
  • id (str) – Tank ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the tank

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the tank

  • elevation (pint.quantity or float) – Elevation of the tank in meters above sea level

  • volume (pint.quantity or float) – Volume of the tank in cubic meters

  • num_units (int) – Number of identical tanks in parallel

  • tags (dict of Tag) – Data tags associated with this tank

Variables:
  • id (str) – Tank ID

  • input_contents (list of ContentsType) – Contents entering the tank.

  • output_contents (list of ContentsType) – Contents leaving the tank.

  • elevation (pint.quantity or float) – Elevation of the tank in meters above sea level

  • volume (pint.quantity or float) – Volume of the tank in cubic meters

  • num_units (int) – Number of identical tanks in parallel

  • tags (dict of Tag) – Data tags associated with this tank

del_num_units()[source]
get_num_units()[source]
property num_units
set_num_units(num_units)[source]
class pype_schema.node.Thickening(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, tags={})[source]

Bases: Node

A class to represent a general thickener, such as gravity belt, dissolved air float (DAF), or centrifugal thickening.

Parameters:
  • id (str) – Thickener ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the thickener

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the thickener

  • min_flow (pint.quantity or float) – Minimum flow rate of a single thickener

  • max_flow (pint.quantity or float) – Maximum flow rate of a single thickener

  • design_flow (pint.quantity or float) – Design flow rate of a single thickener

  • num_units (int) – Number of thickeners running in parallel

  • volume (pint.quantity or float) – Volume of a single thickener in cubic meters

  • tags (dict of Tag) – Data tags associated with this thickener

Variables:
  • id (str) – Thickener ID

  • input_contents (list of ContentsType) – Contents entering the thickener

  • output_contents (list of ContentsType) – Contents leaving the thickener

  • num_units (int) – Number of thickeners running in parallel

  • volume (pint.quantity or float) – Volume of a single thickener in cubic meters

  • min_flow (pint.quantity or float) – Minimum flow rate of a single thickener

  • max_flow (pint.quantity or float) – Maximum flow rate of a single thickener

  • design_flow (pint.quantity or float) – Design flow rate of a single thickener

  • tags (dict of Tag) – Data tags associated with this thickener

class pype_schema.node.UVSystem(id, input_contents, output_contents, min_flow, max_flow, design_flow, num_units, volume, residence_time, intensity, area, tags={})[source]

Bases: Disinfection

An ultraviolet light disinfection system.

Parameters:
  • id (str) – UV System ID

  • input_contents (list of ContentsType) – Contents entering the UV system

  • output_contents (list of ContentsType) – Contents leaving the UV system

  • min_flow (pint.quantity or float) – Minimum flow rate of a single UV system

  • max_flow (pint.quantity or float) – Maximum flow rate of a single UV system

  • design_flow (pint.quantity or float) – Design flow rate of a single UV system

  • num_units (int) – Number of UV systems running in parallel

  • volume (pint.quantity or float) – Volume of a single UV system in cubic meters

  • residence_time (pint.Quantity or float) – Time in seconds that the water is exposed to UV light

  • intensity (pint.Quantity or float) – Intensity of the UV light in W/m^2

  • area (pint.Quantity or float) – Application area of the UV light in m^2

  • tags (dict of Tag) – Data tags associated with this UV system

Variables:
  • id (str) – UVSystem ID

  • min_flow (pint.quantity or float) – Minimum flow rate of a single UV system

  • max_flow (pint.quantity or float) – Maximum flow rate of a single UV system

  • design_flow (pint.quantity or float) – Design flow rate of a single UV system

  • num_units (int) – Number of chlorinators running in parallel

  • volume (pint.quantity or float) – Volume of a single UV system in cubic meters

  • residence_time (pint.Quantity or float) – Time in seconds that the water is exposed to UV light

  • dosing_rate (dict of DosingType:float) – UV intensity in the UV system

  • dosing_area (dict of DosingType:float) – Area of the UV system that is exposed to UV light

  • tags (dict of Tag) – Data tags associated with this UV system

del_dosing_area()[source]
property dosing_area
get_dosing_area()[source]
set_dosing_area(dosing_area)[source]
class pype_schema.node.Valve(id, input_contents, output_contents, diameter=None, tags={})[source]

Bases: Node

A generic valve.

Parameters:
  • id (str) – Valve ID

  • input_contents (ContentsType or list of ContentsType) – Contents entering the valve

  • output_contents (ContentsType or list of ContentsType) – Contents leaving the valve

  • diamater (pint.Quantity) – Diameter of the valve

  • tags (dict of Tag) – Data tags associated with this valve

pype_schema.operations module

class pype_schema.operations.Constant(value, parent_id=None)[source]

Bases: object

Representation for a constant value that is not in the SCADA system.

Only need for Algebraic mode since lambda expressions support constant values directly.

Parameters:

value (float) – The value of this constant at all timesteps

Variables:
  • id (str) –

  • value (float) – The value of this constant at all timesteps

pype_schema.operations.binary_helper(operation, unit, prev_unit, totalized_mix=False)[source]

Helper for parsing operations and checking units of binary operations

Parameters:
  • operation ([“+”, “-”, “”, “/”]*) – Function to apply when combining tags. Supported functions are “+”, “-”, “*”, and “/”.

  • unit (Unit) – Units for the right side of the operation, represented as a Pint unit.

  • prev_unit (Unit) – Units for the left side of the operation, represented as a Pint unit.

  • totalized_mix (bool) – Skip unit checking when there is a mix of totalized and detotalized variables. Default is False

Raises:
  • ValueError – When units are incompatible for addition or subtraction. When operation is unsupported.

  • UserWarning – When a mix of totalized and detotalized variables makes it impossible to verify unit compatibility

Returns:

Resulting Pint Unit from combining the unit and prev_unit according to operation

Return type:

Unit

pype_schema.operations.build_custom_operation(func_str)[source]

Validate a custom operation string and compile it to a callable.

The expression is validated and compiled from a single parsed AST (so the validated tree is exactly the one evaluated), then evaluated in a restricted namespace whose builtins are limited to SAFE_BUILTINS and whose only module globals are the libraries the expression actually uses (so e.g. scipy is only imported if the expression refers to it).

The restricted namespace is defense in depth, not a security boundary: the AST allow-lists enforced by validate_custom_operation are the primary control. Operations are expected to come from trusted authors (see the comment above ALLOWED_NODES).

Parameters:

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

Returns:

The compiled lambda function

Return type:

callable

Raises:
  • TypeError – When func_str is not a string

  • ValueError – When func_str fails validate_custom_operation, or is too deeply nested to compile

  • SyntaxError – When func_str is not valid Python syntax

  • ImportError – When a library the expression refers to is not installed

pype_schema.operations.count_args(func_str)[source]

Count the arguments for a lambda function string without executing the function.

Parameters:

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

Returns:

The lambda function’s number of arguments

Return type:

int

Raises:

ValueError – If custom_operations is not a single lambda string

pype_schema.operations.get_change(variable, delta_t=1, split=False)[source]

Converts cumulative value to rate-of-change value using finite differences Note: assumes rate of change at time t is equal to the difference between the value at time t+1 and t

Parameters:
  • variable (pandas.Series, numpy.ndarray) – variable to convert

  • delta_t (int) – Time difference between two consecutive values of the variable (default is 1)

  • split (bool) – Whether to split the variable into a negative change and a positive change

Returns:

Rate of change variable or tuple of netative, positive rate of change variable

Return type:

tuple, pandas.Series or numpy.ndarray

pype_schema.operations.unary_helper(data, un_op)[source]

Transform the given data according to the VirtualTag’s unary operator

Parameters:
  • data (list, array, or Series) – a list, numpy array, or pandas Series of data to apply a unary operation to

  • un_op ([“noop”, “delta”, “<<”, “>>”, “~”, “-“]) –

    Supported operations are:

    “noop” : null operator, useful when skipping tags in a list of unary operations.

    “delta” : calculate the difference between the current timestep and previous timestep

    “<<” : shift all data left one timestep, so that the last time step will be NaN

    “>>” : shift all data right one timestep, so that the first time step will be NaN

    “~” : Boolean not

    “-” : unary negation

    Note that “delta”, “<<”, and “>>” return a timeseries padded with NaN so that it is the same length as input data

Returns:

numpy array of dataset trannsformed by unary operation

Return type:

list, array, or Series

pype_schema.operations.validate_custom_operation(func_str)[source]

Validate that a custom operation string is a safe lambda expression.

Parses func_str and walks its abstract syntax tree with a scope-aware validator, enforcing allow-lists so the expression can use pandas/numpy/scipy/math (method calls, attribute access, subscripts, comprehensions, nested lambdas, and the functions listed in ALLOWED_MODULE_MEMBERS) while remaining unable to execute arbitrary code. It rejects:

  • input longer than MAX_EXPRESSION_LENGTH characters or containing more than MAX_EXPRESSION_NODES syntax nodes,

  • any syntax node outside ALLOWED_NODES (e.g. assignments, f-strings),

  • default argument values (they are evaluated when the lambda is built and would bypass the free-name check),

  • assignment targets that are not plain names (an Attribute/Subscript target such as np.sum could rebind a shared module),

  • any attribute whose name begins with _ (blocks dunder traversal such as __class__ / __globals__ / __subclasses__),

  • any member of np/pd/sp/math (or of one of their submodules) that is not in ALLOWED_MODULE_MEMBERS, and any attribute of any other object that is not in ALLOWED_ATTRIBUTES (default-deny, so code/IO entry points such as read_pickle, load, eval, query are never reachable, nor is any future addition to the libraries),

  • apply/agg/aggregate/transform unless called directly with a function that is visible in the expression, or the name of an allowed method (never a name that is built at runtime or passed in),

  • any free (unbound) name that is not in ALLOWED_NAMES or the safe builtin set (blocks __import__, open, getattr, eval …).

Names bound by lambda parameters and comprehension targets are scoped, so a name bound inside a comprehension is not treated as bound outside it, and a library name that has been shadowed by a parameter (lambda np: ...) is treated as an ordinary object.

The validator is iterative, so the nesting depth of an expression does not depend on the Python recursion limit.

This is validation only; use build_custom_operation to additionally compile the expression in a restricted namespace. See the comment above ALLOWED_NODES for what validation deliberately does not restrict (CPU/memory use, in-place modification of arguments).

Parameters:

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

Returns:

The original func_str, unchanged, when validation succeeds

Return type:

str

Raises:
  • TypeError – When func_str is not a string

  • ValueError – When func_str is not a single lambda expression, is too large or too deeply nested, or contains syntax, names, or attributes that are not allowed

  • SyntaxError – When func_str is not valid Python syntax

pype_schema.parse_json module

class pype_schema.parse_json.JSONParser(path)[source]

Bases: NetworkParser

A parser to convert a JSON file into a Network object

Parameters:
  • config_dict (dict) – dictionary that defines network

  • network_name (str) – name of the network being parsed

Variables:
  • path (str) – path to the JSON file to load

  • config (dict) – dictionary with the contents the JSON file

  • network_obj (Network) – Python representation of the JSON file

class pype_schema.parse_json.NetworkParser(config_dict, network_name)[source]

Bases: object

A parser to convert a dict file into a Network object

Parameters:
  • config_dict (dict) – dictionary that defines network

  • network_name (str) – name of the network being parsed

Variables:
  • path (str) – path to the JSON file to load

  • config (dict) – dictionary with the contents the JSON file

  • network_obj (Network) – Python representation of the JSON file

add_virtual_tags(verbose=False)[source]

Adds all virtual tags in an object NOTE: assumes the objects tags have already been added

Parameters:
  • obj (Node or Connection) – object to add virtual tags to

  • verbose (bool) – If True will print informative statements while adding virtual tags. Default is False

collect_virtual_tags(config, obj_id=None, virtual_tags=None)[source]

Recursively collects all virtual tags in a network’s dictionary representation (i.e. config)

Parameters:
  • config (dict) – Dictionary representation of the network

  • obj_id (str) – Optional “id” of config whose virtual tags are being collected (if None will use “ParentNetwork”)

  • virtual_tags (dict) – dictionary to store virtual tags in

Returns:

dictionary of all VirtualTag in network

Return type:

dict

static conn_to_dict(conn_obj)[source]

Converts a Connection object to a dictionary that can be parsed into JSON format

Parameters:

conn_obj (Connection) – object to be converted into a dictionary

Returns:

conn_obj in dictionary form

Return type:

dict

create_connection(connection_id, node_obj, verbose=False)[source]

Converts a dictionary into a Connection object

Parameters:
  • connection_id (str) – the string id for the Connection

  • node_id (str) – the string id for the Node which holds this connection. If None the default ID, ‘ParentNetwork’ is used

  • verbose (bool) – Whether to print informative messages for debugging. Default is False

Returns:

a Python object with all the values from key connection_id

Return type:

Connection

create_node(node_id, verbose=False)[source]

Converts a dictionary into a Node object

Parameters:
  • node_id (str) – the string id for the Node

  • verbose (bool) – Whether to print informative messages for debugging. Default is False

Returns:

a Python object with all the values from key node_id

Return type:

Node

static dosing_to_dict(dosing_dict)[source]

Converts the dosing rate or area dictionary from PyPES to JSON format.

Parameters:

dosing_dict (dict) –

dictionary of the form {

DosingTypeA : float or`pint.Quantity`

DosingTypeB : float or pint.Quantity

}

Returns:

Dictionary in JSON-readable format. I.e., {
DosingTypeA: {

value: float

units: str

}

DosingTypeB: {

value: float

units: str

}

}

Return type:

dict

extend_node(new_network, target_node_id, connections_path, inplace=False, verbose=False)[source]

Incoporates subnetwork (i.e. the new_network) into a node in a existing network (i.e. the old_network) modifying it in place and returning the modified network

Parameters:
  • new_network (str or pype_schema.Network) – JSON file path or Network objet to merge with self

  • target_node_id (str) – ID of the node to expend, must be in the old_network

  • connections_path (str) – JSON file path to the connections connecting new_network to old_network.

  • inplace (bool) – Whether to modify self in place or leave original object unmodified. False by default

  • verbose (bool) – Whether to print informative messages for debugging. Default is False

Raises:
  • TypeError – When user does not provide a valid path or Network object for old_network or new_network

  • KeyError – When target_node_id is not in the old_network or any node in connections_path is not in the new_network or old_network

Returns:

Modified network object

Return type:

pype_schema.node.Network

static get_tag_contents(tag_id, tag_info, obj)[source]

Parse tag ID and dictionary of information into Tag object

Parameters:
  • tag_id (str) – name of the tag

  • tag_info (dict) –

    dictionary of the form {

    type: TagType

    units: str

    contents: str

    source_unit_id: int or str

    dest_unit_id: int or str

    totalized: bool

    }

  • obj (Node or Connection) – object that this tag is associated with, which is used to gather relevant metadata

Returns:

the contents of this tag

Return type:

ContentsType

Raises:

ValueError – If contents are ambiguously defined in JSON. E.g., contents not defined in tag and parent object has a list of contents

initialize_network(verbose=False)[source]

Converts a dictionary into a Network object

Parameters:

verbose (bool) – If True will print informative statements while initializing the network

Returns:

a Python object with all the values from the JSON file stored hierarchically

Return type:

Network

merge_network(old_network, inplace=False)[source]

Incorporates nodes/connections (i.e. the new_network) into a network (i.e. old_newtwork) modifying it in place and returning the modified network

Parameters:

old_network (str or pype_schema.Network) – JSON file path or Network objet to merge with self

Raises:

TypeError: – When user does not provide a valid path or Network object for old_network

Returns:

Modified network object

Return type:

pype_schema.node.Network

static min_max_design_to_dict(obj, attribute)[source]

Converts the flow rate tuple of a Node or Connection into a dictionary object

Parameters:
  • obj (Node or Connection) – object to get attribute of and convert it to a dictionary

  • attribute (str) – Either “flow_rate”, “gen_capacity”, or “pressure”

Returns:

flow rate in the form {

min: float or int

max: float or int

design: float or int

units: str

}

Return type:

dict

static node_to_dict(node_obj)[source]

Converts a Node object to a dictionary that can be parsed into JSON format

Parameters:

node_obj (Node) – object to be converted into a dictionary

Raises:

TypeError – if node_obj is not a subclass of Node

Returns:

node_obj in dictionary form

Return type:

dict

parse_contents(id)[source]

Converts a dictionary into a tuple of input and output contents

Parameters:

id (str) – ID of the node to get the contents for

Returns:

(input_contents, output_contents)

Return type:

(str, str)

static parse_dosing_rate(dosing_dict)[source]

Converts a dictionary into a dictionary of a different format

Parameters:

heating_vals (dict) –

dictionary of the form {

DosingType: {

rate: float

units: str

}

}

Returns:

Keys are of DosingType or str and values of pint.Quantity or float Given as a float if no units are specified

Return type:

dict

static parse_heating_values(heating_vals)[source]

Converts a dictionary into a tuple of flow rates

Parameters:

heating_vals (dict) –

dictionary of the form {

lower: float

higher: float

units: str

}

Returns:

(lower, higher) heating values as a tuple, with units applied. Given as a float if no units are specified

Return type:

(pint.Quantity, pint.Quantity) or (float, float)

static parse_min_max_design(min_max_design)[source]

Converts a dictionary into a tuple of flow rates

Parameters:

min_max_design (dict) –

dictionary of the form {

min: float

max: float

design: float

units: str

}

Returns:

(min, max, and average) with the given Pint units as a tuple. If no units given, then returns a tuple of floats.

Return type:

(pint.Quantity, pint.Quantity, pint.Quantity) or (float, float, float)

static parse_tag(tag_id, tag_info, obj)[source]

Parse tag ID and dictionary of information into Tag object

Parameters:
  • tag_id (str) – name of the tag

  • tag_info (dict) –

    dictionary of the form {

    type: TagType

    units: str

    contents: str

    source_unit_id: int or str

    dest_unit_id: int or str

    totalized: bool

    }

  • obj (Node or Connection) – object that this tag is associated with, which is used to gather relevant metadata

Returns:

a Python object with the given ID and the values from tag_info

Return type:

Tag

static parse_unit_val_dict(unit_dict)[source]

Converts a dictionary into a Pint Quantity

Parameters:

unit_dict (dict) –

dictionary of the form {

value: float

units: str

}

Returns:

Dictionary as a Pint Quantity (or float if no units are specified)

Return type:

pint.Quantity or float

static parse_virtual_tag(tag_id, tag_info, obj, parent_network=None)[source]

Parse tag ID and dictionary information into VirtualTag object

Parameters:
  • tag_id (str) – name of the tag

  • tag_info (dict) –

    dictionary of the form {

    tags: dict of Tag

    unary_operations: list of str

    binary_operations: list of str

    custom_operations: str

    type: TagType

    contents: str

    }

  • obj (Node or Connection) – parent object that contains all constituent tags, which is used to gather the tag list for combining data correctly

  • parent_network (None, Network) – Optional network object the tag is a part of If None will assume obj is parent network and all tags are in obj.tags

  • parent_network (None, Network) – Optional network object the tag is a part of If None will assume obj is the parent network and all tags are in obj.tags

Returns:

a Python object with the given ID and the values from tag_info

Return type:

VirtualTag

static prefix_children(target_node, prefix)[source]

Renames the children nodes and connections of the target_node by prepending their ID with prefix.

Parameters:
  • target_node (node.Network) – Network object to rename the children of with a prefix

  • prefix (str) – String to prepend to the existing node and connection objects

Returns:

New network object with

Return type:

node.Network

static tag_to_dict(tag_obj)[source]

Converts a Tag or VirtualTag object to a dictionary that can be parsed into JSON format

Parameters:

tag_obj (Tag or VirtualTag) – object to be converted into a dictionary

Raises:

TypeError – If tag_obj is not of type Tag or VirtualTag

Returns:

tag_obj in dictionary form

Return type:

dict

static to_json(network, file_path=None, indent=4, verbose=False)[source]

Converts a Network object to a JSON file

Parameters:
  • network (node.Network) – Network object to export to JSON

  • file_path (str) – path to write the configuration in JSON format. Default is None, meaning that no file will be written

  • indent (int) – number of spaces to indent the JSON file. Default is 4

  • verbose (bool) – Whether to print informative messages for debugging. Default is False

Raises:

TypeError – If network is not of type Network

Returns:

json in dictionary format

Return type:

dict

static unit_val_to_dict(attribute)[source]
Converts the given attribute to dictionary of the form {

value: float

units: str

}

Parameters:

attribute (pint.Quantity or float) – Attribute to represent as a dictionary

Returns:

Dictionary with keys value and units

Return type:

dict

pype_schema.tag module

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

Bases: Enum

Enum to represent common methods of downsampling data.

Average = 1
Decimation = 2
Reservoir = 3
class pype_schema.tag.OperationMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum to represent methods of VirtualTag operations.

Algebraic = 1
Custom = 2
class pype_schema.tag.Tag(id, units, tag_type, source_unit_id, dest_unit_id, parent_id, totalized=False, contents=None, manufacturer=None, measure_freq=None, report_freq=None, downsample_method=None, calibration=<pype_schema.logbook.Logbook entries:{}>)[source]

Bases: object

Class to represent a SCADA or other data tag

Parameters:
  • id (str) – Tag ID

  • units (str or Unit) – Units represented as a string or Pint unit. E.g., ‘MGD’ or ‘cubic meters’ or <Unit(‘MGD’)>

  • tag_type (TagType) – Type of data saved under the tag. E.g., InfluentFlow or RunTime

  • source_unit_id (int or str) – integer representing unit number, or total if a combined data point across all units of the source node

  • dest_unit_id (int or str) – integer representing unit number, or total if a combined data point across all units of the destination node. None if the Tag is associated with a Node object instead of a Connection

  • parent_id (str) – ID for the parent object (either a Node or Connection)

  • totalized (bool) – True if data is totalized. False otherwise

  • contents (ContentsType) – Data stream contents. E.g., WasteActivatedSludge or NaturalGas

  • manufacturer (str) – Name of the manufacturer for the physical sensor hardware. Default is None

  • measure_freq (pint.Quantity) – Measurement frequency of the data with units. None by default

  • report_freq (pint.Quantity) – Reporting frequency of the data with units. None by default

  • downsample_method (DownsampleType) – None by default, meaning that data is reported on the same frequency as measured

  • calibration (Logbook) – A history of sensor calibration.

Variables:
  • id (str) – Tag ID

  • units (Unit) – Units represented as a Pint unit. E.g., <Unit(‘MGD’)>

  • tag_type (TagType) – Type of data saved under the tag. E.g., InfluentFlow or RunTime

  • source_unit_id (int or str) – integer representing unit number, or total if a combined data point across all units of the sources node

  • dest_unit_id (int or str) – integer representing unit number, or total if a combined data point across all units of the destination node

  • parent_id (str) – ID for the parent object (either a Node or Connection)

  • totalized (bool) – True if data is totalized. False by default

  • contents (ContentsType) – Contents moving through the node

  • manufacturer (str) – Name of the manufacturer for the physical sensor hardware. Default is None

  • measure_freq (pint.Quantity) – Measurement frequency of the data with units. None by default

  • report_freq (pint.Quantity) – Reporting frequency of the data with units. None by default

  • downsample_method (DownsampleType) – None by default, meaning that data is reported on the same frequency as measured

  • calibration (Logbook) – A history of sensor calibration.

property calibration
check_type_compatibility(other_type)[source]

Check if the given tag_type is compatible with another

Parameters:

other_type (TagType) – Type of tag to compare against

Returns:

True if compatible, False otherwise

Return type:

bool

del_calibration()[source]
del_downsample_method()[source]
del_manufacturer()[source]
del_measure_freq()[source]
del_report_freq()[source]
property downsample_method
get_calibration()[source]
get_downsample_method()[source]
get_manufacturer()[source]
get_measure_freq()[source]
get_report_freq()[source]
property manufacturer
property measure_freq
property report_freq
set_calibration(calibration)[source]
set_downsample_method(downsample_method)[source]
set_manufacturer(manufacturer)[source]
set_measure_freq(measure_freq)[source]
set_report_freq(report_freq)[source]
class pype_schema.tag.TagType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum to represent types of SCADA tags.

BOD = 12
COD = 11
Concentration = 26
Conductivity = 14
Current = 24
Efficiency = 17
Flow = 1
Frequency = 23
InFlow = 19
Level = 3
NetFlow = 21
OutFlow = 20
Pressure = 4
Rotation = 16
RunStatus = 7
RunTime = 6
SetPoint = 27
Speed = 22
StateOfCharge = 18
TDS = 10
TSS = 9
Temperature = 5
Turbidity = 15
VSS = 8
Voltage = 25
Volume = 2
pH = 13
class pype_schema.tag.VirtualTag(id, tags, unary_operations=None, binary_operations=None, custom_operations=None, units=None, tag_type=None, parent_id=None, contents=None)[source]

Bases: object

Representation for data that is not in the SCADA system, but is instead a combination of existing tags.

Tags are combined via either custom_operations lambda function string or the unary_operations and binary_operations lists depending on whether mode is Algebraic or Custom.

In Algebraic mode, all unary operations are applied before any binary operations.

Parameters:
  • id (str) – VirtualTag ID

  • tags (list of Tag) – List of Tag objects to combine

  • unary_operations (str or list) – Function to apply when combining tags. If a single string it will be applied to all Tags. Otherwise, the unary_operations must be same length as tags, and functions will be applied in order

  • binary_operations (str or list) – Function to apply when combining tags. If a single string it will be applied to all Tags. Otherwise, the binary_operations must be one shorter than tags, and functions will be applied in order

  • custom_operations (str) – String a lambda function to apply to all tags, must have number of args equal to number of tags

  • tag_type (TagType) – Type of data saved under the tag. E.g., InfluentFlow or RunTime. Default is None, and it will be automatically determined from constituent Tags if they all have the same type.

  • parent_id (str) – ID for the parent object (either a Node or Connection)

  • contents (ContentsType) – Contents moving through the node. Default is None, and it will be automatically determined from consituent Tag contents

Raises:
  • ValueError – When operations lambda function has the wrong number of elements When tag_type is not specified and constituent tags have different types. When contents of the constituent tags are different types.

  • UserWarning – When a mix of totalized and detotalized tags are combined When tags have different units

Variables:
  • id (str) – Tag ID

  • tags (list of Tag) – List of Tag objects to combine

  • unary_operations (["noop", "delta", "<<", ">>", "~", "-"]) –

    Unary operations to apply before combining tags.

    ”noop” : null operator, useful when skipping tags in a list of unary operations.

    ”delta” : calculate the difference between the current timestep and previous timestep

    ”<<” : shift all data left one timestep, so that the last time step will be NaN

    ”>>” : shift all data right one timestep, so that the first time step will be NaN

    ”~” : Boolean not

    ”-” : unary negation

    Note that “delta”, “<<”, and “>>” return a timeseries padded with NaN so that it is the same length as input data

  • binary_operations (["+", "-", "*", "/"]) – Binary operaitons to apply when combining tags. Supported functions are “+”, “-”, “*”, and “/”. If a single string is passed, it will be applied to all Tags. Otherwise, the binary_operations list must be one shorter than tags, and functions will be applied in order from left to right

  • custom_operations (str) – String giving a lambda function to apply to constituent tags

  • units (str or Unit) – Units represented as a string or Pint unit. E.g., ‘MGD’ or ‘cubic meters’ or <Unit(‘MGD’)>

  • tag_type (TagType) – Type of data saved under the tag. E.g., InfluentFlow or RunTime

  • totalized (bool) – True if data is totalized. False otherwise

  • parent_id (str) – ID for the parent object (either a Node or Connection)

  • contents (ContentsType) – Contents moving through the node

  • mode (OperationMode) – Mode of operation. Either Algebraic or Custom. Automatically determined based on values of unary_operations, binary_operations and custom_operations.

calculate_values(data, tag_to_var_map={})[source]

Combine the given data according to the VirtualTag’s operations

Parameters:
  • data (list, array, dict, or DataFrame) – a list, numpy array, or pandas DataFrame of data that has the correct dimensions. I.e., the number of columns is one more than binary operations and same length as unary operations

  • tag_to_var_map (dict) – dictionary of the form { tag.id : variable_name } for using data files that differ from the original SCADA tag naming system

Returns:

numpy array of combined dataset

Return type:

list, array, or Series

process_binary_ops(data, tag_to_var_map={})[source]

Combine the given data according to the VirtualTag’s binary operations

Parameters:
  • data (list, array, dict, or DataFrame) – a list, numpy array, or pandas DataFrame of data that has the correct dimensions. I.e., the number of columns is one more than binary operations and same length as unary operations

  • tag_to_var_map (dict) – dictionary of the form { tag.id : variable_name } for using data files that differ from the original SCADA tag naming system

Returns:

numpy array of combined dataset

Return type:

list, array, or Series

process_custom_ops(data, tag_to_var_map={})[source]

Transform the given data according to the VirtualTag’s lambda string

Parameters:
  • data (list, array, dict, or DataFrame) – a list, numpy array, or pandas DataFrame of data that has the correct dimensions. I.e., the number of columns is one more than binary operations and same length as unary operations

  • tag_to_var_map (dict) – dictionary of the form { tag.id : variable_name } for using data files that differ from the original SCADA tag naming system

Returns:

numpy array of combined dataset

Return type:

list, array, or Series

process_unary_ops(data, tag_to_var_map={})[source]

Transform the given data according to the VirtualTag’s unary operator

Parameters:
  • data (list, array, dict, or DataFrame) – a list, numpy array, or pandas DataFrame of data that has the correct dimensions. I.e., the number of columns is one more than binary operations and same length as unary operations

  • un_op ([“noop”, “delta”, “<<”, “>>”, “~”, “-“]) –

    Supported operations are:

    “noop” : null operator, useful when skipping tags in a list of unary operations.

    “delta” : calculate the difference between the current timestep and previous timestep

    “<<” : shift all data left one timestep, so that the last time step will be NaN

    “>>” : shift all data right one timestep, so that the first time step will be NaN

    “~” : Boolean not

    “-” : unary negation

    Note that “delta”, “<<”, and “>>” return a timeseries padded with NaN so that it is the same length as input data

  • tag_to_var_map (dict) – dictionary of the form { tag.id : variable_name } for using data files that differ from the original SCADA tag naming system

Returns:

numpy array of combined dataset

Return type:

list, array, or Series

pype_schema.tag.check_type_compatibility(tag_type, other_type)[source]

Check if the given tag_type is compatible with another

Parameters:
  • tag_type (TagType) – Type of the first tag

  • other_type (TagType) – Type of tag to compare against

Returns:

True if compatible, False otherwise

Return type:

bool

pype_schema.units module

Module containing global unit registry. The Pint package supports arithmetic of physical quantities, which are combinations of numerical values and units of measurement. The units of a quantity come from Pint’s unit registry. This module contains a unit registry, named u, based on Pint’s unit registry. It also defines a few additional units. Frequently Used Units and Constants in u

Prefixes for Metric Units

  • pico- = 1e-12 = p-

  • nano- = 1e-9 = n-

  • micro- = 1e-6 = u- = µ-

  • milli- = 1e-3 = m-

  • centi- = 1e-2 = c-

  • deci- = 1e-1 = d-

  • deca- = 1e+1 = da-

  • hecto- = 1e2 = h-

  • kilo- = 1e3 = k-

  • mega- = 1e6 = M-

  • giga- = 1e9 = G-

  • tera- = 1e12 = T-

Units of Length

  • u.meter = u.metre = u.m

  • u.inch

  • u.foot = u.ft

  • u.yard = u.yd

  • u.mile = u.mi

Units of Mass

  • u.gram = u.g

  • u.metric_ton = u.tonne = u.t

  • u.ounce = u.oz

  • u.pound = u.lb

  • u.ton

  • u.atomic_mass_unit = u.amu

Units of Time

  • u.second = u.sec = u.s

  • u.minute = u.min

  • u.hour = u.hr

  • u.day

  • u.week

  • u.year

Units of Temperature

  • u.kelvin = u.degK

  • u.celsius = u.degC

  • u.fahrenheit = u.degF

Units of Angle

  • u.revolution = u.rev

  • u.radian = u.rad

  • u.degree = u.deg

Units of Force

  • u.newton = u.N

  • u.gram_force = u.gf

  • u.kilogram_force = u.kgf

  • u.pound_force = u.lbf

  • u.ton_force

  • u.kip

Units of Frequency

  • u.hertz = u.Hz

  • u.revolutions_per_minute = u.rpm

Units of Money

  • u.dollar = u.USD

  • u.lempira = u.HNL

Units of Power

  • u.watt = u.W

  • u.horsepower = u.hp

Units of Pressure

  • u.pascal = u.Pa

  • u.bar

  • u.atmosphere = u.atm

  • u.torr

  • u.millimeter_Hg = u.mmHg

Units of Volume

  • u.liter = u.litre = u.L

  • u.cubic_centimeter = u.cc

  • u.gallon = u.gal

  • u.quart = u.qt

  • u.pint = u.pt

  • u.cup

  • u.fluid_ounce = u.floz

  • u.tablespoon = u.tbsp

  • u.teaspoon = tsp

Other Units

Constants

  • u.gravity

  • u.molar_gas_constant = u.R

  • u.avogadro_number

  • u.boltzmann_constant

pype_schema.units.set_sig_figs(n=4)[source]

Set the default number of significant figures used to print Pint, Pandas and NumPy value quantities.

Parameters:

n (int) – number of significant figures to display. Defaults to 4.

pype_schema.utils module

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

Bases: Enum

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

Air = 30
Antiscalant = 50
Biogas = 9
Brine = 22
Chemical = 33
ChlorinatedSeawater = 43
Coagulant = 34
CoagulatedWater = 44
ControlSignal = 48
DataTransfer = 49
Deodorant = 36
Disinfectant = 35
DisinfectedEffluent = 39
DrinkingWater = 6
Electricity = 21
FatOilGrease = 12
FilterBackwash = 45
Filtrate = 46
FoodWaste = 18
GasBlend = 11
Grease = 29
Groundwater = 25
Heat = 27
IdealGas = 32
IndustrialWastewater = 37
MunicipalWastewater = 38
NaturalGas = 10
NonpotableReuse = 8
Oil = 28
Oxygen = 31
PotableReuse = 7
PretreatedWater = 41
PrimaryEffluent = 2
PrimarySludge = 13
ProductWater = 42
Scum = 17
Seawater = 23
SecondaryEffluent = 3
SludgeBlend = 19
SolidWaste = 40
Stormwater = 26
SurfaceWater = 24
TPS = 14
TWAS = 16
TertiaryEffluent = 4
ThickenedSludgeBlend = 20
TreatedSewage = 5
UntreatedSewage = 1
WFBS = 47
WasteActivatedSludge = 15
class pype_schema.utils.DigesterType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum to represent types of digesters

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

Bases: Enum

Enum to represent types of dosing

Antiscalant = 3
CO2 = 4
CaOH2 = 5
FeCl3 = 2
NaOCl = 1
OrthoPolyphosphate = 6
Polymer = 8
SBS = 7
UVLight = 9
class pype_schema.utils.PumpType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enum to represent constant vs. variable drive pumps

AirBlower = 4
Constant = 1
ERD = 3
VFD = 2
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

pype_schema.visualize module

pype_schema.visualize.draw_graph(network, pyvis=False, output_file=None)[source]

Draw all of the nodes and connections in the given network

Parameters:
  • network (Network) – Network object to draw

  • pyvis (bool) – Whether to draw the graph with PyVis or Networkx. False (networkx) by default

  • output_file (str) – Path to the desired output. Default is None, meaning the file will be saved as networkd.id + extension

Module contents

Main package for PyPES.

pype_schema.get_module_version()[source]