表示声学刺激和响应
项目描述
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 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5f4a3503eff849c329cda5be1968674f386e0baa6a74f9d05f30e462542f387e |
|
MD5 | 658c7f00b6cf42184570f25b64031b54 |
|
BLAKE2b-256 | 312f72b5bf8d5e87bbb7f87d39364e52b657202e474d951c71d2d7d99cc97490 |
关闭
ndx_sound-0.2.0-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 1371ccdc0690d89a89495612172336cd473f6c86736991c54f1873d8380b2ecc |
|
MD5 | 841e5e2b22a3c408c3241af11a924c8a |
|
BLAKE2b-256 | 519ab5d24dbf05878fa505a178e1ab5fb2ea42508a057ada7cffaa7d8dfa797e |