Skip to main content

NWB extensions for storing hierarchical behavioral data

Project description

ndx-hierarchical-behavioral-data Extension for NWB

PyPI version

schema schema

Installation

pip install ndx-hierarchical-behavioral-data

Usage

Use pre-made hierarchical transcription tables:

from ndx_hierarchical_behavioral_data.definitions.transcription import TIPhonemes, HBTSyllables, HBTWords, HBTSentences

# Phonemes level
phonemes = TIPhonemes()
phonemes.add_column('max_pitch', 'maximum pitch for this phoneme. NaN for unvoiced')
for i, p in enumerate('abcdefghijkl'):
    phonemes.add_interval(label=p, start_time=float(i), stop_time=float(i+1), max_pitch=i**2)

# Syllables level
syllables = HBTSyllables(lower_tier_table=phonemes)
syllables.add_interval(label='abc', next_tier=[0, 1, 2])
syllables.add_interval(label='def', next_tier=[3, 4, 5])
syllables.add_interval(label='ghi', next_tier=[6, 7, 8])
syllables.add_interval(label='jkl', next_tier=[9, 10, 11])

# Words level
words = HBTWords(lower_tier_table=syllables)
words.add_column('emphasis', 'boolean indicating whether this word was emphasized')
words.add_interval(label='A-F', next_tier=[0, 1], emphasis=False)
words.add_interval(label='G-L', next_tier=[2, 3], emphasis=True)

# Sentences level
sentences = HBTSentences(lower_tier_table=words)
sentences.add_interval(label='A-L', next_tier=[0, 1])

View individual tiers:

sentences.to_dataframe()
labelstart_timestop_timenext_tier
id
0A-L0.012.0label start_time stop_time \\id ...
words.to_dataframe()
label start_time stop_time next_tier emphasis
id
0 A-F 0.0 6.0 label start_time stop_time \\ id 0 abc 0.0 3.0 1 def 3.0 6.0 next_tier id 0 start_time stop_time label max_pitch id 0 0.0 1.0 a 0 1 1.0 2.0 b 1 2 2.0 3.0 c 4 1 start_time stop_time label max_pitch id 3 3.0 4.0 d 9 4 4.0 5.0 e 16 5 5.0 6.0 f 25 False
1 G-L 6.0 12.0 label start_time stop_time \\ id 2 ghi 6.0 9.0 3 jkl 9.0 12.0 next_tier id 2 start_time stop_time label max_pitch id 6 6.0 7.0 g 36 7 7.0 8.0 h 49 8 8.0 9.0 i 64 3 start_time stop_time label max_pitch id 9 9.0 10.0 j 81 10 10.0 11.0 k 100 11 11.0 12.0 l 121 True
syllables.to_dataframe()
labelstart_timestop_timenext_tier
id
0 abc 0.0 3.0 start_time stop_time label id 0 0.0 1.0 a 1 1.0 2.0 b 2 2.0 3.0 c
1 def 3.0 6.0 start_time stop_time label id 3 3.0 4.0 d 4 4.0 5.0 e 5 5.0 6.0 f
2 ghi 6.0 9.0 start_time stop_time label id 6 6.0 7.0 g 7 7.0 8.0 h 8 8.0 9.0 i
3 jkl 9.0 12.0 start_time stop_time label id 9 9.0 10.0 j 10 10.0 11.0 k 11 11.0 12.0 l
phonemes.to_dataframe()
start_time stop_time label max_pitch
id
0 0.0 1.0 a 0
1 1.0 2.0 b 1
2 2.0 3.0 c 4
3 3.0 4.0 d 9
4 4.0 5.0 e 16
5 5.0 6.0 f 25
6 6.0 7.0 g 36
7 7.0 8.0 h 49
8 8.0 9.0 i 64
9 9.0 10.0 j 81
10 10.0 11.0 k 100
11 11.0 12.0 l 121

Hierarchical dataframe:

sentences.to_hierarchical_dataframe()
source_table phonemes
label id start_time stop_time label max_pitch
sentences_id sentences_label sentences_start_time sentences_stop_time words_id words_label words_start_time words_stop_time words_emphasis syllables_id syllables_label syllables_start_time syllables_stop_time
0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 0 0.0 1.0 a 0
3.0 1 1.0 2.0 b 1
3.0 2 2.0 3.0 c 4
1 def 3.0 6.0 3 3.0 4.0 d 9
6.0 4 4.0 5.0 e 16
6.0 5 5.0 6.0 f 25
1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 6 6.0 7.0 g 36
9.0 7 7.0 8.0 h 49
9.0 8 8.0 9.0 i 64
3 jkl 9.0 12.0 9 9.0 10.0 j 81
12.0 10 10.0 11.0 k 100
12.0 11 11.0 12.0 l 121

Hierachical columns, flattened rows:

sentences.to_hierarchical_dataframe(flat_column_index=True)
id start_time stop_time label max_pitch
sentences_id sentences_label sentences_start_time sentences_stop_time words_id words_label words_start_time words_stop_time words_emphasis syllables_id syllables_label syllables_start_time syllables_stop_time
0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 0 0.0 1.0 a 0
3.0 1 1.0 2.0 b 1
3.0 2 2.0 3.0 c 4
1 def 3.0 6.0 3 3.0 4.0 d 9
6.0 4 4.0 5.0 e 16
6.0 5 5.0 6.0 f 25
1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 6 6.0 7.0 g 36
9.0 7 7.0 8.0 h 49
9.0 8 8.0 9.0 i 64
3 jkl 9.0 12.0 9 9.0 10.0 j 81
12.0 10 10.0 11.0 k 100
12.0 11 11.0 12.0 l 121

Denormalized dataframe:

sentences.to_denormalized_dataframe()
source_table sentences words syllables phonemes
label id label start_time stop_time id label start_time stop_time emphasis id label start_time stop_time id start_time stop_time label max_pitch
0 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 0 0.0 1.0 a 0
1 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 1 1.0 2.0 b 1
2 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 2 2.0 3.0 c 4
3 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 1 def 3.0 6.0 3 3.0 4.0 d 9
4 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 1 def 3.0 6.0 4 4.0 5.0 e 16
5 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 1 def 3.0 6.0 5 5.0 6.0 f 25
6 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 6 6.0 7.0 g 36
7 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 7 7.0 8.0 h 49
8 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 8 8.0 9.0 i 64
9 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 3 jkl 9.0 12.0 9 9.0 10.0 j 81
10 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 3 jkl 9.0 12.0 10 10.0 11.0 k 100
11 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 3 jkl 9.0 12.0 11 11.0 12.0 l 121

Denormalized dataframe with flattened columns:

sentences.to_denormalized_dataframe(flat_column_index=True)
sentences_id sentences_label sentences_start_time sentences_stop_time words_id words_label words_start_time words_stop_time words_emphasis syllables_id syllables_label syllables_start_time syllables_stop_time id start_time stop_time label max_pitch
0 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 0 0.0 1.0 a 0
1 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 1 1.0 2.0 b 1
2 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 0 abc 0.0 3.0 2 2.0 3.0 c 4
3 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 1 def 3.0 6.0 3 3.0 4.0 d 9
4 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 1 def 3.0 6.0 4 4.0 5.0 e 16
5 0 A-L 0.0 12.0 0 A-F 0.0 6.0 False 1 def 3.0 6.0 5 5.0 6.0 f 25
6 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 6 6.0 7.0 g 36
7 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 7 7.0 8.0 h 49
8 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 2 ghi 6.0 9.0 8 8.0 9.0 i 64
9 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 3 jkl 9.0 12.0 9 9.0 10.0 j 81
10 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 3 jkl 9.0 12.0 10 10.0 11.0 k 100
11 0 A-L 0.0 12.0 1 G-L 6.0 12.0 True 3 jkl 9.0 12.0 11 11.0 12.0 l 121

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-hierarchical-behavioral-data-0.1.1.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

ndx_hierarchical_behavioral_data-0.1.1-py2.py3-none-any.whl (14.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ndx-hierarchical-behavioral-data-0.1.1.tar.gz.

File metadata

  • Download URL: ndx-hierarchical-behavioral-data-0.1.1.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for ndx-hierarchical-behavioral-data-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2b234195d0cbb2f60b2fb8d413860e27c997104e000fe5ca4fc66f42bb7af321
MD5 3977f83dad00b0d039064e1cedc6a2f8
BLAKE2b-256 6c5b3fc869f0c5a99700770b96afa6ae2b84736ce7e8f330fe26bfff5e7995ca

See more details on using hashes here.

File details

Details for the file ndx_hierarchical_behavioral_data-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: ndx_hierarchical_behavioral_data-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for ndx_hierarchical_behavioral_data-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4edb86978d6b129f091685e775be3d4d8282af1a095582aa88c3c3a8e8725d2e
MD5 225ad0e396d34df7dd27f18e7f66695f
BLAKE2b-256 7624647ad3c664c2b9940719c2210d327398f25bb2eb56e5b01ab95153e84337

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