Skip to main content

Represent acoustic stimuli and responses

Project description

PyPI

ndx-sound Extension for NWB

NWB extension for sounds.

Installation

pip install ndx-sound

Usage

Python

Add to an NWB file

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)

Visualization

Static widgets

Use plot_sound to visualize the waveform series and the spectrogram. For longer recordings, specify the time_window argument for the start and end time of the recording to be shown.

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

Use acoustic_waveform_widget to include an Audio element that plays the sound.

from ndx_sound.widgets import acoustic_waveform_widget

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

Interactive widgets

Use AcousticWaveformWidget to use a slider for interactively scrolling through the recording and a button for changing the duration of the sound that is being shown.

from ndx_sound.widgets import AcousticWaveformWidget

AcousticWaveformWidget(nwbfile.stimulus["acoustic_stimulus"])

nwbwidgets

Use load_widgets to load the interactive sound widget into nwb2widget.

from ndx_sound.widgets import load_widgets
from nwbwidgets import nwb2widget

load_widgets()

nwb2widget(nwbfile)

nwbwidgets and HDF5IO

When using nwb2widget with an NWB file that is read from disk, make sure to have load_widgets imported within the same Jupyter cell where your data is being loaded.

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)

This extension was created using ndx-template.

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

ndx-sound-0.2.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

ndx_sound-0.2.0-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ndx-sound-0.2.0.tar.gz.

File metadata

  • Download URL: ndx-sound-0.2.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for ndx-sound-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5f4a3503eff849c329cda5be1968674f386e0baa6a74f9d05f30e462542f387e
MD5 658c7f00b6cf42184570f25b64031b54
BLAKE2b-256 312f72b5bf8d5e87bbb7f87d39364e52b657202e474d951c71d2d7d99cc97490

See more details on using hashes here.

File details

Details for the file ndx_sound-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: ndx_sound-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for ndx_sound-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1371ccdc0690d89a89495612172336cd473f6c86736991c54f1873d8380b2ecc
MD5 841e5e2b22a3c408c3241af11a924c8a
BLAKE2b-256 519ab5d24dbf05878fa505a178e1ab5fb2ea42508a057ada7cffaa7d8dfa797e

See more details on using hashes here.

Supported by

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