Package: ndx-hierarchical-behavioral-data
ndx-hierarchical-behavioral-data Extension for NWBInstallationpip install ndx-hierarchical-behavioral-dataUsageUse pre-made hierarchical transcription tables:fromndx_hierarchical_behavioral_data.definitions.transcriptionimportTIPhonemes,HBTSyllables,HBTWords,HBTSentences# Phonemes levelphonemes=TIPhonemes()phonemes.add_column('max_pitch','maximum pitch for this phoneme. NaN for unvoiced')fori,pinenumerate('abcdefghijkl'):phonemes.add_interval(label=p,start_time=float(i),stop_time=float(i+1),max_pitch=i**2)# Syllables levelsyllables=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 levelwords=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 levelsentences=HBTSentences(lower_tier_table=words)sentences.add_interval(label='A-L',next_tier=[0,1])View individual tiers:sentences.to_dataframe()labelstart_timestop_timenext_tierid0A-L0.012.0label  start_time  stop_time  \\id     ...words.to_dataframe()labelstart_timestop_timenext_tieremphasisid0A-F0.06.0label  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         25False1G-L6.012.0label  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        121Truesyllables.to_dataframe()labelstart_timestop_timenext_tierid0abc0.03.0start_time  stop_time label id                              0          0.0        1.0     a 1          1.0        2.0     b 2          2.0        3.0     c1def3.06.0start_time  stop_time label id                              3          3.0        4.0     d 4          4.0        5.0     e 5          5.0        6.0     f2ghi6.09.0start_time  stop_time label id                              6          6.0        7.0     g 7          7.0        8.0     h 8          8.0        9.0     i3jkl9.012.0start_time  stop_time label id                              9          9.0       10.0     j 10        10.0       11.0     k 11        11.0       12.0     lphonemes.to_dataframe()start_timestop_timelabelmax_pitchid00.01.0a011.02.0b122.03.0c433.04.0d944.05.0e1655.06.0f2566.07.0g3677.08.0h4988.09.0i6499.010.0j811010.011.0k1001111.012.0l121Hierarchical dataframe:sentences.to_hierarchical_dataframe()source_tablephonemeslabelidstart_timestop_timelabelmax_pitchsentences_idsentences_labelsentences_start_timesentences_stop_timewords_idwords_labelwords_start_timewords_stop_timewords_emphasissyllables_idsyllables_labelsyllables_start_timesyllables_stop_time0A-L0.012.00A-F0.06.0False0abc0.03.000.01.0a03.011.02.0b13.022.03.0c41def3.06.033.04.0d96.044.05.0e166.055.06.0f251G-L6.012.0True2ghi6.09.066.07.0g369.077.08.0h499.088.09.0i643jkl9.012.099.010.0j8112.01010.011.0k10012.01111.012.0l121Hierachical columns, flattened rows:fromhdmf.common.hierarchicaltableimportflatten_column_indexflatten_column_index(sentences.to_hierarchical_dataframe(),1)idstart_timestop_timelabelmax_pitchsentences_idsentences_labelsentences_start_timesentences_stop_timewords_idwords_labelwords_start_timewords_stop_timewords_emphasissyllables_idsyllables_labelsyllables_start_timesyllables_stop_time0A-L0.012.00A-F0.06.0False0abc0.03.000.01.0a03.011.02.0b13.022.03.0c41def3.06.033.04.0d96.044.05.0e166.055.06.0f251G-L6.012.0True2ghi6.09.066.07.0g369.077.08.0h499.088.09.0i643jkl9.012.099.010.0j8112.01010.011.0k10012.01111.012.0l121Denormalized dataframe:fromhdmf.common.hierarchicaltableimportto_hierarchical_dataframeto_hierarchical_dataframe(sentences).reset_index()source_tablesentenceswordssyllablesphonemeslabelidlabelstart_timestop_timeidlabelstart_timestop_timeemphasisidlabelstart_timestop_timeidstart_timestop_timelabelmax_pitch00A-L0.012.00A-F0.06.0False0abc0.03.000.01.0a010A-L0.012.00A-F0.06.0False0abc0.03.011.02.0b120A-L0.012.00A-F0.06.0False0abc0.03.022.03.0c430A-L0.012.00A-F0.06.0False1def3.06.033.04.0d940A-L0.012.00A-F0.06.0False1def3.06.044.05.0e1650A-L0.012.00A-F0.06.0False1def3.06.055.06.0f2560A-L0.012.01G-L6.012.0True2ghi6.09.066.07.0g3670A-L0.012.01G-L6.012.0True2ghi6.09.077.08.0h4980A-L0.012.01G-L6.012.0True2ghi6.09.088.09.0i6490A-L0.012.01G-L6.012.0True3jkl9.012.099.010.0j81100A-L0.012.01G-L6.012.0True3jkl9.012.01010.011.0k100110A-L0.012.01G-L6.012.0True3jkl9.012.01111.012.0l121Denormalized dataframe with flattened columns:fromhdmf.common.hierarchicaltableimportflatten_column_indexflatten_column_index(sentences.to_hierarchical_dataframe(),1).reset_index()sentences_idsentences_labelsentences_start_timesentences_stop_timewords_idwords_labelwords_start_timewords_stop_timewords_emphasissyllables_idsyllables_labelsyllables_start_timesyllables_stop_timeidstart_timestop_timelabelmax_pitch00A-L0.012.00A-F0.06.0False0abc0.03.000.01.0a010A-L0.012.00A-F0.06.0False0abc0.03.011.02.0b120A-L0.012.00A-F0.06.0False0abc0.03.022.03.0c430A-L0.012.00A-F0.06.0False1def3.06.033.04.0d940A-L0.012.00A-F0.06.0False1def3.06.044.05.0e1650A-L0.012.00A-F0.06.0False1def3.06.055.06.0f2560A-L0.012.01G-L6.012.0True2ghi6.09.066.07.0g3670A-L0.012.01G-L6.012.0True2ghi6.09.077.08.0h4980A-L0.012.01G-L6.012.0True2ghi6.09.088.09.0i6490A-L0.012.01G-L6.012.0True3jkl9.012.099.010.0j81100A-L0.012.01G-L6.012.0True3jkl9.012.01010.011.0k100110A-L0.012.01G-L6.012.0True3jkl9.012.01111.012.0l121This extension was created usingndx-template.