跳转到主要内容

SONATA文件阅读器

项目描述

banner

license coverage documentation status

libsonata

C++ / Python阅读器,用于SONATA电路文件:SONATA指南

安装

从PyPI安装

pip install libsonata

直接从GitHub安装Python包

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

构建C++库

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

由于libsonata使用backports for std::optional和std::variant,这些在可用时会转换为其实际STL实现,因此建议使用与链接到libsonata的项目相同的C++标准编译libsonata。这可以通过向上面的cmake命令传递-DCMAKE_CXX_STANDARD={14,17}来实现。

使用(Python)

节点

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')]
选择

元素ID列表(可以是node_id或edge_id),相邻ID被分组以提高HDF5文件访问效率。例如,{1, 2, 3, 5}序列变为{[1, 4), [5, 6)}

选择可以从以下实例化
  • 标量值序列(也适用于NumPy数组)

  • 对序列(解释为上述范围,也适用于N x 2 NumPy数组)

EdgePopulation 连接查询(见下文)也返回 选择

>>> 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
节点集合

libsonata 可以与节点集合概念协同工作,如以下所述: SONATA指南:节点集合文件 这允许为细胞组定义名称,并提供查询它们的方法。libsonata 还允许使用扩展表达式,例如正则表达式和浮点数测试,如以下所述: SONATA扩展:节点集合

# 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'}

边存储

EdgeStorage 的节点处理与 NodeStorage 类似

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

# list populations
>>> edges.population_names

# open population
>>> population = edges.open_population(<name>)
边人口
# 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

…提供额外的查询连接的方法,结果为可以像上面一样应用的选择

# 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])

报告

尖峰读取器
>>> import libsonata

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

# list populations
>>> spikes.get_population_names()

# open population
>>> population = spikes['<name>']
尖峰人口
# 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
细胞体报告读取器
>>> somas = libsonata.SomaReportReader('path/to/H5/file')

# list populations
>>> somas.get_population_names()

# open population
>>> population_somas = somas['<name>']
细胞体报告人口
# 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]

再次使用pandas,可以创建一个使用数据、id和时间的列表的dataframe

>>> 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
元素报告读取器
>>> elements = libsonata.ElementReportReader('path/to/H5/file')

# list populations
>>> elements.get_population_names()

# open population
>>> population_elements = elements['<name>']
元素报告人口
# 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)]

与尖峰和细胞体报告一样,可以使用pandas更好地表示数据

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

对于大数据集,使用numpy数组可以大大提高性能

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

致谢

本软件的开发得到了瑞士联邦理工学院洛桑联邦理工学院(EPFL)的Blue Brain Project研究中心的资金支持,该中心得到了瑞士政府ETH委员会的资助。

本研究得到了EBRAINS研究基础设施的支持,该基础设施由欧盟的Horizon 2020研究与创新框架计划资助,具体资助协议编号为945539(人类大脑项目SGA3)。该项目/研究还得到了欧盟的Horizon 2020研究与创新框架计划的资助,具体资助协议编号为785907(人类大脑项目SGA2)。

许可协议

libsonata在以下条件下分发:GNU Lesser General Public License版本3,除非另有说明,例如外部依赖项。有关详细信息,请参阅COPYING.LESSERCOPYING文件。

版权(c)2018-2022 Blue Brain Project/EPFL

libsonata是自由软件:您可以按照自由软件基金会发布的GNU Lesser General Public License版本3的条款重新分发和/或修改它。

libsonata以希望它将是有用的方式分发,但没有任何保证;甚至没有关于其商售性或适用于特定目的的隐含保证。有关详细信息,请参阅GNU Lesser General Public License。

您应该已经收到了GNU Lesser General Public License的副本,与libsonata一起。如果没有,请参阅 <https://gnu.ac.cn/licenses/>。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

libsonata-0.1.28.tar.gz (1.1 MB 查看哈希值)

上传时间 源代码

构建分发

libsonata-0.1.28-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.13 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

libsonata-0.1.28-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.13 manylinux: glibc 2.17+ x86-64

libsonata-0.1.28-cp313-cp313-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间 CPython 3.13 macOS 11.0+ ARM64

libsonata-0.1.28-cp313-cp313-macosx_10_13_x86_64.whl (2.1 MB 查看哈希值)

上传时间 CPython 3.13 macOS 10.13+ x86-64

libsonata-0.1.28-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

libsonata-0.1.28-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

libsonata-0.1.28-cp312-cp312-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间: CPython 3.12 macOS 11.0+ ARM64

libsonata-0.1.28-cp312-cp312-macosx_10_9_x86_64.whl (2.1 MB 查看哈希值)

上传时间: CPython 3.12 macOS 10.9+ x86-64

libsonata-0.1.28-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.3 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

libsonata-0.1.28-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看哈希值)

上传时间: CPython 3.11 manylinux: glibc 2.17+ x86-64

libsonata-0.1.28-cp311-cp311-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间: CPython 3.11 macOS 11.0+ ARM64

libsonata-0.1.28-cp311-cp311-macosx_10_9_x86_64.whl (2.0 MB 查看哈希值)

上传时间: CPython 3.11 macOS 10.9+ x86-64

libsonata-0.1.28-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.3 MB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

libsonata-0.1.28-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看哈希值)

上传时间: CPython 3.10 manylinux: glibc 2.17+ x86-64

libsonata-0.1.28-cp310-cp310-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间: CPython 3.10 macOS 11.0+ ARM64

libsonata-0.1.28-cp310-cp310-macosx_10_9_x86_64.whl (2.0 MB 查看哈希值)

上传时间: CPython 3.10 macOS 10.9+ x86-64

libsonata-0.1.28-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

libsonata-0.1.28-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.9 manylinux: glibc 2.17+ x86-64

libsonata-0.1.28-cp39-cp39-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间 CPython 3.9 macOS 11.0+ ARM64

libsonata-0.1.28-cp39-cp39-macosx_10_9_x86_64.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.9 macOS 10.9+ x86-64

libsonata-0.1.28-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

libsonata-0.1.28-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.8 manylinux: glibc 2.17+ x86-64

libsonata-0.1.28-cp38-cp38-macosx_11_0_arm64.whl (1.7 MB 查看哈希值)

上传时间 CPython 3.8 macOS 11.0+ ARM64

libsonata-0.1.28-cp38-cp38-macosx_10_9_x86_64.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.8 macOS 10.9+ x86-64

支持者