SONATA files reader
Project description
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
Since libsonata uses backports for std::optional and std::variant which turn into their actual STL implementation once available, it’s recommended to compile libsonata with the same C++ standard as the project linking to libsonata. This is done by passing -DCMAKE_CXX_STANDARD={14,17} to the cmake command above.
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
Node Sets
libsonata can work with the Node Set concept, as described here: SONATA guide: Node Sets File This allows the definition of names for groups of cells, and a way to query them. libsonata also allows for extended expressions, such as Regular expressions,and floating point tests, as described here: SONATA extension: Node Sets
# load a node set JSON file
>>> node_sets = libsonata.NodeSets.from_file('node_sets.json')
# list node sets
>>> node_sets.names
{'L6_UPC', 'Layer1', 'Layer2', 'Layer3', ....}
# get the selection of nodes that match in population
>>> selection = node_sets.materialize('Layer1', population)
# node sets can also be loaded from a JSON string
>>> node_sets_manual = libsonata.NodeSets(json.dumps({"SLM_PPA_and_SP_PC": {"mtype": ["SLM_PPA", "SP_PC"]}}))
>>> node_sets_manual.names
{'SLM_PPA_and_SP_PC'}
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_population_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_population_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_population_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
The development of this software was supported by funding to the Blue Brain Project, a research center of the École polytechnique fédérale de Lausanne (EPFL), from the Swiss government’s ETH Board of the Swiss Federal Institutes of Technology.
This research was supported by the EBRAINS research infrastructure, funded from the European Union’s Horizon 2020 Framework Programme for Research and Innovation under the Specific Grant Agreement No. 945539 (Human Brain Project SGA3). 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-2022 Blue Brain Project/EPFL
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for libsonata-0.1.29-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 304482074ba397afbfdbe8dda5ebda838ff65ce02e29a29b4fc52720a0822da6 |
|
MD5 | dcaa2aca060cb796a0e08fc8f59fbc7e |
|
BLAKE2b-256 | 5a05cdb772d6285c94a5eb1d191b01c66ce2080ba7b6bc060225db8eec6f2ffe |
Hashes for libsonata-0.1.29-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f15232d528fd2229912f18be2dcedf7f198cc132a7c4c4c20963d32f1f527f6 |
|
MD5 | 155b2f52ef87149d21d536e22c53c360 |
|
BLAKE2b-256 | 9a61fd97df35ec8cae692ad71e9f7ad06ef8b472b648f96b7d3bc89e97eed4c1 |
Hashes for libsonata-0.1.29-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d38d2397b54cd080907862e6da9f51090c377574f21a5cd3da22b81ed5e53bb |
|
MD5 | 11d6a2df41e74a8c444cd5afe8fd8baf |
|
BLAKE2b-256 | 0a769dc932902e047362dad37a585d576900cac12cae1aecd14137bc944ad1a5 |
Hashes for libsonata-0.1.29-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b6e8eb122a5d935e69bbc902cabfcf1baf42f05e1ec329f5c27bb8d08f34060 |
|
MD5 | 1f289d8f69822f5b26602b47149a9912 |
|
BLAKE2b-256 | fd8c8fb0ce158fab06b9087518635cf1118e733700b57e506f4428b79c08c511 |
Hashes for libsonata-0.1.29-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9087ab174761847eb138c9ba16a0e52a8c74e0eafe3109017300ec82872a1ec1 |
|
MD5 | 38fcf39c48c6ccce2b95b40e0724077b |
|
BLAKE2b-256 | 572bf25203b940acfddeaa5a7d54585db98938305d2350a5616435fde1f9c03c |
Hashes for libsonata-0.1.29-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f06e74b6dc810d97a5e4e12d67e13adbde7a326a83a8bd60f82d282f12f6a65 |
|
MD5 | 419519901314b1ee0fbfa08e605d2743 |
|
BLAKE2b-256 | 71305498b6838cfac205f836bcb4dd906a9495f7ea46bd844ca8bd56ea46bf63 |
Hashes for libsonata-0.1.29-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b762b29777efc6308217ba8bf4c1bb1dc73ca075829523a03a25fdee6b3ca05 |
|
MD5 | 59e87e4d112e209285ea9bb3827120d7 |
|
BLAKE2b-256 | f33015f0f3412dce37003aa53919f15caac8438c50d933813ab8c61b67f2ea1f |
Hashes for libsonata-0.1.29-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15cc8371016c2e01a100bdceb1596ae1975fefd4249b5def937c5fc4b15b93a |
|
MD5 | c7ac543938947af91cac932fe4a60c21 |
|
BLAKE2b-256 | 0e815c82f79b0e0aaaa14f8e14a6691b4dded1b403ba55a621bd03ff0b9f74dc |
Hashes for libsonata-0.1.29-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 958356914f8fb2f6804a56630497223f0a34a8903f8f01464e4869a0820ce4d1 |
|
MD5 | adaae42c821761d58c06afe6789ee7f3 |
|
BLAKE2b-256 | d07df6135908552a8949e3cd7d64956cdbd9e09d0dc7a9f685ffd86a98880dee |
Hashes for libsonata-0.1.29-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5b2792d4015b52d9cc771ba8c784545927e0987743991b12a898bc698103161 |
|
MD5 | 9d92f773be2c40564bcc1fbc9dbfd16f |
|
BLAKE2b-256 | daf3a92ea162b81064463431107cd8585634fc2f45dba5e559cff5e979e6b138 |
Hashes for libsonata-0.1.29-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acce07d35de3416aca79f9c5864f6bc5931f4b1219bc1a061e845556b7e888d4 |
|
MD5 | 2c66861d5d81d4d88887d8e3de344736 |
|
BLAKE2b-256 | 6faa75374e964fc15df2beb62147cfe3c049d5c357e5ecff9cb005fee377041d |
Hashes for libsonata-0.1.29-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6b710add37cac4fbf83f9a22856bca17541d59e07a85f1131686799a6e04242 |
|
MD5 | a647e39675cc2f503465088893507f37 |
|
BLAKE2b-256 | 4441f8c169cb2051d848e9d3d02dd09a95d7ac15cdb69125d463c4dd40f3f9d6 |
Hashes for libsonata-0.1.29-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b163bc2472273e5e086af2edda0f647e02cc1eddfedbde3460648dbb15fdd05f |
|
MD5 | d435b496b1b02fde749677b2c526e3b7 |
|
BLAKE2b-256 | c1a64b78d4eb104e09e01270f7732256cce0278a0736f0b508bf6800694b79ee |
Hashes for libsonata-0.1.29-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a049eaa26de2678abda84cd5dde0fb7ba48d8e9fd2dd3cbe45999d116d15cb6 |
|
MD5 | ebec369fb25eea9f6168aadda75a1a84 |
|
BLAKE2b-256 | 8fea7ade4f51b6c8786f8799f7faf18b2f6d512550f6f7f5d5f651deab24c780 |
Hashes for libsonata-0.1.29-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2397453bc10681dc2fb47487e22a8c896a491b26dc7873b573e6f1e5d806c06b |
|
MD5 | abcad6d0c54ef424f949a27cae2d50e1 |
|
BLAKE2b-256 | e80ff34ec5fc867ec180d39a6db5c209b09ac7a64e8453522c2ebf6be5c55294 |
Hashes for libsonata-0.1.29-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49eec66c0c7a16b561a89055c78b27b1b2907926570911e14dbc1c2b0f0e2626 |
|
MD5 | c528425741fdfc6b9a01c2a1de72dc5c |
|
BLAKE2b-256 | bfb89be5e82a8e3fc231a5fcc7696c3d2340e739bfb662b3cf038b74508304cc |
Hashes for libsonata-0.1.29-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 514e5e0d543b9f00b515b8292c16a35f0f173e9fc2ff47b53565b5602b1e5aa2 |
|
MD5 | 937c78629a5ec15823917b71da78d411 |
|
BLAKE2b-256 | 68a9cd76630533a1a74e998a9216a5690588d9dc3c765f9420db79fd9fbdfa39 |
Hashes for libsonata-0.1.29-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51d829bf403c5aa636c9d93f94a7781ebd564a89d827300edff6d47e0703960a |
|
MD5 | 10002a715957f392a7894f88ab8bd758 |
|
BLAKE2b-256 | 2ca55b0371b1e09cad267b7a2d36f8b7b010e877a51d3400a21fd567e44a1cdc |
Hashes for libsonata-0.1.29-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62f232c9af3c132f5d8470f05432d6ba48fe44bc4e3c349f347034d1d6f1dbb8 |
|
MD5 | f13663ccf26dae49ecc398b542304cff |
|
BLAKE2b-256 | 3bdeea04941919a612ec83752abacad80108bbfad7a6ec20b35e6946e933ec35 |
Hashes for libsonata-0.1.29-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d115067e8c3376f46fcc7600633f3c08ffeb24a653fb270194b5c4fcb2fb9965 |
|
MD5 | 3ea27de47ec84738bbf069a058e794c6 |
|
BLAKE2b-256 | 8e97e279bc1caeaa8d4838622be9c0d8da55bbb0a71fcd62ce8c85c0e45263bd |