跳转到主要内容

表示声学刺激和响应

项目描述

PyPI

ndx-sound NWB扩展

NWB的音频扩展。

安装

pip install ndx-sound

用法

Python

添加到NWB文件

from pynwb import NWBFile
from scipy.io import wavfile

from ndx_sound import AcousticWaveformSeries

# The file path to the audio file
file_path = "audio_data.wav"

# Read the audio file to get the rate of the recording and the waveform
sampling_rate, samples = wavfile.read(file_path)

# Create an AcousticWaveformSeries object with a given name and description
acoustic_waveform_series = AcousticWaveformSeries(
    name="acoustic_stimulus",
    data=samples,
    rate=sampling_rate,
    description="acoustic stimulus",
)

# Create an NWBFile object where this AcousticWaveformSeries can be added to
nwbfile = NWBFile(
    session_description=...,
    identifier=...,
    session_start_time=...,
)

# If a recording of behavior, add to acquisition
nwbfile.add_acquisition(acoustic_waveform_series)

# If a stimulus, add to stimulus
nwbfile.add_stimulus(acoustic_waveform_series)

可视化

静态小部件

使用plot_sound来可视化波形系列和频谱图。对于较长的录音,指定time_window参数来指定要显示的录音的开始和结束时间。

from ndx_sound.widgets import plot_sound

plot_sound(nwbfile.stimulus["acoustic_stimulus"])

# Show only from 5 to 15 seconds
plot_sound(nwbfile.stimulus["acoustic_stimulus"], time_window=(5, 15))

使用acoustic_waveform_widget来包含一个播放声音的音频元素。

from ndx_sound.widgets import acoustic_waveform_widget

acoustic_waveform_widget(nwbfile.stimulus["acoustic_stimulus"], time_window=(5, 15))

交互式小部件

使用AcousticWaveformWidget来使用滑动条来交互式地滚动录音,并使用按钮来更改显示的音长。

from ndx_sound.widgets import AcousticWaveformWidget

AcousticWaveformWidget(nwbfile.stimulus["acoustic_stimulus"])

nwbwidgets

使用load_widgets将交互式声音小部件加载到nwb2widget

from ndx_sound.widgets import load_widgets
from nwbwidgets import nwb2widget

load_widgets()

nwb2widget(nwbfile)

nwbwidgets和HDF5IO

当使用nwb2widget与从磁盘读取的NWB文件时,请确保在同一Jupyter单元中导入load_widgets,其中您正在加载数据。

from pynwb import NWBHDF5IO
from ndx_sound.widgets import load_widgets
from nwbwidgets import nwb2widget

load_widgets()


io = NWBHDF5IO("audio.nwb", mode="r", load_namespaces=True)
nwbfile = io.read()
nwb2widget(nwbfile)

此扩展使用 ndx-template 创建。

项目详情


下载文件

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

源代码分发

ndx-sound-0.2.0.tar.gz (15.8 kB 查看哈希值)

上传时间 源代码

构建分发

ndx_sound-0.2.0-py2.py3-none-any.whl (6.7 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持