Skip to main content

SONATA files reader

Project description

banner

license coverage documentation status

libsonata

C++ / Python reader for SONATA circuit files: SONATA guide

Installation

Installing from PyPI

pip install libsonata

Installing as a Python package, directly from GitHub

pip install git+https://github.com/BlueBrain/libsonata

Building the C++ library

git clone git@github.com:BlueBrain/libsonata.git --recursive
cd libsonata
mkdir build && cd build
cmake  -DCMAKE_BUILD_TYPE=Release  -DEXTLIB_FROM_SUBMODULES=ON ..
make -j

Usage (Python)

Nodes

NodeStorage
>>> import libsonata

>>> nodes = libsonata.NodeStorage('path/to/H5/file')

# list populations
>>> nodes.population_names

# open population
>>> population = nodes.open_population(<name>)
NodePopulation
# total number of nodes in the population
>>> population.size

# attribute names
>>> population.attribute_names

# get attribute value for single node, say 42
>>> population.get_attribute('mtype', 42)

# ...or Selection of nodes (see below) => returns NumPy array with corresponding values
>>> selection = libsonata.Selection(values=[1, 5, 9, 42])  # nodes 1, 5, 9, 42
>>> mtypes = population.get_attribute('mtype', selection)
>>> list(zip(selection.flatten(), mtypes))
[(1, u'mtype_of_1'), (5, u'mtype_of_5'), (9, u'mtype_of_9'), (42, u'mtype_of_42')]
Selection

List of element IDs (either node_id, or edge_id) where adjacent IDs are grouped for the sake of efficient HDF5 file access. For instance, {1, 2, 3, 5} sequence becomes {[1, 4), [5, 6)}.

Selection can be instantiated from:
  • a sequence of scalar values (works for NumPy arrays as well)

  • a sequence of pairs (interpreted as ranges above, works for N x 2 NumPy arrays as well)

EdgePopulation connectivity queries (see below) return Selections as well.

>>> selection = libsonata.Selection([1, 2, 3, 5])
>>> selection.ranges
[(1, 4), (5, 6)]
>>> selection = libsonata.Selection([(1, 4), (5, 6)])
>>> selection.flatten()
[1, 2, 3, 5]
>>> selection.flat_size
4
>>> bool(selection)
True

Edges

EdgeStorage

Population handling for EdgeStorage is analogous to NodeStorage:

>>> edges = libsonata.EdgeStorage('path/to/H5/file')

# list populations
>>> edges.population_names

# open population
>>> population = edges.open_population(<name>)
EdgePopulation
# total number of edges in the population
>>> population.size

# attribute names
>>> population.attribute_names

# get attribute value for single edge, say 123
>>> population.get_attribute('delay', 123)

# ...or Selection of edges => returns NumPy array with corresponding values
>>> selection = libsonata.Selection([1, 5, 9])
>>> population.get_attribute('delay', selection) # returns delays for edges 1, 5, 9

…with additional methods for querying connectivity, where the results are selections that can be applied like above

# get source / target node ID for the 42nd edge:
>>> population.source_node(42)
>>> population.target_node(42)

# query connectivity (result is Selection object)
>>> selection_to_1 = population.afferent_edges(1)  # all edges with target node_id 1
>>> population.target_nodes(selection_to_1)  # since selection only contains edges
                                             # targeting node_id 1 the result will be a
                                             # numpy array of all 1's
>>> selection_from_2 = population.efferent_edges(2)  # all edges sourced from node_id 2
>>> selection = population.connecting_edges(2, 1)  # this selection is all edges from
                                                   # node_id 2 to node_id 1

# ...or their vectorized analogues
>>> selection = population.afferent_edges([1, 2, 3])
>>> selection = population.efferent_edges([1, 2, 3])
>>> selection = population.connecting_edges([1, 2, 3], [4, 5, 6])

Reports

SpikeReader
>>> import libsonata

>>> spikes = libsonata.SpikeReader('path/to/H5/file')

# list populations
>>> spikes.get_populations_names()

# open population
>>> population = spikes['<name>']
SpikePopulation
# get all spikes [(node_id, timestep)]
>>> population.get()
[(5, 0.1), (2, 0.2), (3, 0.3), (2, 0.7), (3, 1.3)]

# get all spikes betwen tstart and tstop
>>> population.get(tstart=0.2, tstop=1.0)
[(2, 0.2), (3, 0.3), (2, 0.7)]

# get spikes attribute sorting (by_time, by_id, none)
>>> population.sorting
'by_time'

Pandas can be used to create a dataframe and get a better representation of the data
>>> import pandas

data = population.get()
df = pandas.DataFrame(data=data, columns=['ids', 'times']).set_index('times')
print(df)
       ids
times
0.1      5
0.2      2
0.3      3
0.7      2
1.3      3
SomaReportReader
>>> somas = libsonata.SomaReportReader('path/to/H5/file')

# list populations
>>> somas.get_populations_names()

# open population
>>> population_somas = somas['<name>']
SomaReportPopulation
# get times (tstart, tstop, dt)
>>> population_somas.times
(0.0, 1.0, 0.1)

# get unit attributes
>>> population_somas.time_units
'ms'
>>> population_somas.data_units
'mV'

# node_ids sorted?
>>> population_somas.sorted
True

# get a list of all node ids in the selected population
>>> population_somas.get_node_ids()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

# get the DataFrame of the node_id values for the timesteps between tstart and tstop
>>> data_frame = population_somas.get(node_ids=[13, 14], tstart=0.8, tstop=1.0)

# get the data values
>>> data_frame.data
[[13.8, 14.8], [13.9, 14.9]]

# get the list of timesteps
>>> data_frame.times
[0.8, 0.9]

# get the list of node ids
>>> data_frame.ids
[13, 14]

Once again, pandas can be used to create a dataframe using the data, ids and times lists

>>> import pandas

df = pandas.DataFrame(data_frame.data, columns=data_frame.ids, index=data_frame.times)
print(df)
       13    14
0.8  13.8  14.8
0.9  13.9  14.9
ElementReportReader
>>> elements = libsonata.ElementReportReader('path/to/H5/file')

# list populations
>>> elements.get_populations_names()

# open population
>>> population_elements = elements['<name>']
ElementReportPopulation
# get times (tstart, tstop, dt)
>>> population_elements.times
(0.0, 4.0, 0.2)

>>> population_elements.get_node_ids()
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

# get the DataFrame of the node_id values for the timesteps between tstart and tstop
>>> data_frame = population_elements.get(node_ids=[13, 14], tstart=0.8, tstop=1.0)

# get the data values (list of list of floats with data[time_index][element_index])
>>> data_frame.data
[[46.0, 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7, 46.8, 46.9], [56.0, 56.1, 56.2, 56.3, 56.4, 56.5, 56.6, 56.7, 56.8, 56.9]]

# get the list of timesteps
>>> data_frame.times
[0.8, 1.0]

# get the list of (node id, element_id)
>>> data_frame.ids
[(13, 30), (13, 30), (13, 31), (13, 31), (13, 32), (14, 32), (14, 33), (14, 33), (14, 34), (14, 34)]

The same way than with spikes and soma reports, pandas can be used to get a better representation of the data

>>> import pandas

df = pandas.DataFrame(data_frame.data, columns=pandas.MultiIndex.from_tuples(data_frame.ids), index=data_frame.times)
print(df)
       13                            14
       30    30    31    31    32    32    33    33    34    34
0.8  46.0  46.1  46.2  46.3  46.4  46.5  46.6  46.7  46.8  46.9
1.0  56.0  56.1  56.2  56.3  56.4  56.5  56.6  56.7  56.8  56.9

For big datasets, using numpy arrays could greatly improve the performance

>>> import numpy

np_data = numpy.asarray(data_frame.data)
np_ids = numpy.asarray(data_frame.ids).T
np_times = numpy.asarray(data_frame.times)

df = pandas.DataFrame(np_data, columns=pandas.MultiIndex.from_arrays(np_ids), index=np_times)

Acknowledgements

This project/research has received funding from the European Union’s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement No. 785907 (Human Brain Project SGA2).

License

libsonata is distributed under the terms of the GNU Lesser General Public License version 3, unless noted otherwise, for example, for external dependencies. Refer to COPYING.LESSER and COPYING files for details.

Copyright (C) 2018-2020, Blue Brain Project/EPFL and contributors.

libsonata is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation.

libsonata is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with libsonata. If not, see <https://www.gnu.org/licenses/>.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libsonata-0.1.6.tar.gz (397.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libsonata-0.1.6-cp38-cp38-manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8

libsonata-0.1.6-cp38-cp38-macosx_10_13_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.8macOS 10.13+ x86-64

libsonata-0.1.6-cp37-cp37m-manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.7m

libsonata-0.1.6-cp37-cp37m-macosx_10_13_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.7mmacOS 10.13+ x86-64

libsonata-0.1.6-cp36-cp36m-manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.6m

libsonata-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.6mmacOS 10.13+ x86-64

File details

Details for the file libsonata-0.1.6.tar.gz.

File metadata

  • Download URL: libsonata-0.1.6.tar.gz
  • Upload date:
  • Size: 397.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6.tar.gz
Algorithm Hash digest
SHA256 fe79f33071228a727b382fc78be3347056f54a9f33b34e797682465096c8ee50
MD5 ed16dfc7f9a447f7863adfb8152d1eb6
BLAKE2b-256 5251f86c1bde91f58d5fefc34e79882619f7bbfe41b12224f61fb505be4ca794

See more details on using hashes here.

File details

Details for the file libsonata-0.1.6-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: libsonata-0.1.6-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b03634fb105584576abba84260824ccaec3e4055c1ad34a1bb01e2a07a7598a5
MD5 7cfe85cbb8192e98f97fbe50be9d0fe3
BLAKE2b-256 92a1b60664a00e0cd899c2473e0eececaeae86af528d52178a91dcbccd289ebd

See more details on using hashes here.

File details

Details for the file libsonata-0.1.6-cp38-cp38-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: libsonata-0.1.6-cp38-cp38-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.8, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 e68d35b6096c7cd7dc609349ea693d17656c12ae55abffa77b2d222fa6ea80f8
MD5 ad1a6cb797749fe93bfe9f898d92727c
BLAKE2b-256 cc839597230236747f8bf84555068f851e6ca90fab36def212032c855a041c90

See more details on using hashes here.

File details

Details for the file libsonata-0.1.6-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: libsonata-0.1.6-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d1b84235ee5a3ccba40d301aaf94a584bbe3ccae630812e7ff36d507b16a092b
MD5 c3ef5f10ce346dd226b3b0c9814b1438
BLAKE2b-256 313a106d207f72d81de8a092a58f8a61b16be5322e1973435f083e3ad5c44a4e

See more details on using hashes here.

File details

Details for the file libsonata-0.1.6-cp37-cp37m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: libsonata-0.1.6-cp37-cp37m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.7m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6-cp37-cp37m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 185039fc4fb7ffc7cd347ee78b07d1bbf6efea31b2353e72756565edea81666c
MD5 26f96c2e0764509714146db017573161
BLAKE2b-256 24d2bb2434fb6991ee6c506f6bee6dd51b3df42211c74899656ab36e3e587725

See more details on using hashes here.

File details

Details for the file libsonata-0.1.6-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: libsonata-0.1.6-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3e244f27087d31c407bd3f1a5d148b52f9b908d60ad0adf797d856eafc56a0d0
MD5 1a0e6d7f3500db0c49e8e91ea36a00b9
BLAKE2b-256 9b7b422da6dbbeff4b1346c213eec9fdb7aad6181a9859da6185dc679ce57569

See more details on using hashes here.

File details

Details for the file libsonata-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: libsonata-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 2.0 MB
  • Tags: CPython 3.6m, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for libsonata-0.1.6-cp36-cp36m-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 47787b9057e352dd54bd616ecf842a9bcc54284e564ff0b7b6b1533b72eb18aa
MD5 cdf5a0eeca8694d909747fd86ce6cf14
BLAKE2b-256 fa1125f2cb6afffbb6158870f84767a3e310d22cd102546d8bd5c2f22db3a863

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page