Managing network files#

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 import Scaffold

network = Scaffold()
network.compile()

Network from config#

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

from bsb import Configuration, Scaffold

cfg = Configuration()
# Let's set a file name for the network
cfg.storage.root = "my_network.hdf5"
# And add a cell type
cfg.cell_types.add(
    "hero_cells",
    spatial=dict(
        radius=2,
        density=1e-3,
    ),
)

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

Loading a network from file#

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

from bsb import from_storage

network = from_storage("my_network.hdf5")

Accessing network data#

Configuration#

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

import numpy as np

from bsb import from_storage

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), cell_type.name, "placed")
    # The positions are an (Nx3) numpy array
    print("The median cell is located at", np.median(pos, axis=0))

Todo

Document best practices for the morphology data

Todo

Document best practices for the connectivity data