Using networks#

Greetings traveller, it seems you’ve created a network. Network files contain:

  • The configuration used to create them, so also all component definitions like cell types, topology, placement and connectivity blocks, and simulation config.

  • The morphologies that may be assigned to cells, their labels and properties.

  • The placement data such as positions, rotations, assigned morphologies and user-defined additional data.

  • The connectivity data that specifies which cells are connected, and the properties of those connections.

Here are some examples to help you on your way.

Creating networks#

Default network#

The default configuration contains a skeleton configuration, for an HDF5 storage, without any components in it. The file will be called something like scaffold_network_2022_06_29_10_10_10.hdf5, and will be created once you construct the Scaffold object:

from bsb.core import Scaffold

network = Scaffold()

Network from config#

You can also first load or create a config.Configuration object, and create a network from it, by passing it to the Scaffold:

from bsb.core import Scaffold
from bsb.config import Configuration

cfg = Configuration()
# Let's set a file name for the network = "my_network.hdf5"
# And add a cell type

# After customizing your configuration, create a network from it.
network = Scaffold(cfg)

Loading a network from file#

You can load a stored network from file using bsb.core.from_storage():

from bsb.core import from_storage

network = from_storage("my_network.hdf5")

Accessing network data#


The configuration of a network is available as network.configuration, the root nodes such as cell_types, placement and others are available on network as well.

from bsb.core import from_storage

network = from_storage("network.hdf5")
print("My network was configured with", network.configuration)
print("My network has", len(network.configuration.cell_types), "cell types")
    # But to avoid some needless typing and repetition,
    network.cell_types is network.configuration.cell_types
    and network.placement is network.configuration.placement
    and "so on"

Placement data#

The placement data is available through the storage.interfaces.PlacementSet interface. This example shows how to access the cell positions of each population:

from bsb.core import from_storage
import numpy as np

network = from_storage("network.hdf5")
for cell_type in network.cell_types:
    ps = cell_type.get_placement_set()
    pos = ps.load_positions()
    print(len(pos),, "placed")
    # The positions are an (Nx3) numpy array
    print("The median cell is located at", np.median(pos, axis=0))


Document best ways to interact with the morphology data