Contacts#

class Contacts(data=None, layer_keys=None, **kwargs)[source]#

Bases: FlexDict

A simple (for now) class for storing different contact layers.

Parameters:
  • data (dict) – a dictionary that looks like a Contacts object

  • layer_keys (list) – if provided, create an empty Contacts object with these layers

  • kwargs (dict) – additional layer(s), merged with data

Methods

add_layer(**kwargs)[source]#

Small method to add one or more layers to the contacts. Layers should be provided as keyword arguments.

Example:

hospitals_layer = hpv.Layer(label='hosp')
sim.people.contacts.add_layer(hospitals=hospitals_layer)
pop_layer(*args)[source]#

Remove the layer(s) from the contacts.

Example:

sim.people.contacts.pop_layer('hospitals')

Note: while included here for convenience, this operation is equivalent to simply popping the key from the contacts dictionary.

to_graph()[source]#

Convert all layers to a networkx MultiDiGraph

Example:

import networkx as nx
sim = hpv.Sim(n_agents=50, pop_type='hybrid').run()
G = sim.people.contacts.to_graph()
nx.draw(G)