How to use the mirdata.utils.SectionData function in mirdata

To help you get started, we’ve selected a few mirdata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mir-dataset-loaders / mirdata / tests / test_rwc_jazz.py View on Github external
+ 'annotations/AIST.RWC-MDB-J-2001.CHORUS/RM-J004.CHORUS.TXT',
        'beats_path': 'tests/resources/mir_datasets/RWC-Jazz/'
            + 'annotations/AIST.RWC-MDB-J-2001.BEAT/RM-J004.BEAT.TXT',
        'piece_number': 'No. 4',
        'suffix': 'M01',
        'track_number': 'Tr. 04',
        'title': 'Crescent Serenade (Piano Solo)',
        'artist': 'Makoto Nakamura',
        'duration': 167,
        'variation': 'Instrumentation 1',
        'instruments': 'Pf',
    }

    expected_property_types = {
        'beats': utils.BeatData,
        'sections': utils.SectionData
    }

    run_track_tests(track, expected_attributes, expected_property_types)

    # test audio loading functions
    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2,)
github mir-dataset-loaders / mirdata / tests / test_jams_utils.py View on Github external
],
            None,
        ]
    ]
    multi_section_data_6 = [
        (
            (
                (
                    utils.SectionData(
                        np.array([[0.0, 10.0, 20.0], [10.0, 20.0, 25.0]]).T,
                        np.array(['verse A', 'verse B', 'verse A']),
                    ),
                    None,
                ),
                (
                    utils.SectionData(
                        np.array([[0.0, 15.0, 20.0], [15.0, 20.0, 25.0]]).T,
                        np.array(['verse a', 'verse b', 'verse a']),
                    ),
                    None,
                ),
            ),
            None,
        )
    ]
    multi_section_data_7 = [([(None, None), (None, None)], None)]
    multi_section_data_8 = [
        (
            [
                (
                    utils.EventData(
                        np.array([0.2, 0.3]),
github mir-dataset-loaders / mirdata / tests / test_rwc_genre.py View on Github external
assert (
        track.audio_path
        == 'tests/resources/mir_datasets/RWC-Genre/' + 'audio/rwc-g-m01/2.wav'
    )
    assert track.piece_number == 'No. 2'
    assert track.suffix == 'M01'
    assert track.track_number == 'Tr. 02'
    assert track.category == 'Pop'
    assert track.sub_category == 'Pop'
    assert track.title == 'Forget about It'
    assert track.composer == 'Shinya Iguchi'
    assert track.artist == 'Shinya Iguchi (Male)'
    assert track.duration == 262

    # test that cached properties don't fail and have the expected type
    assert type(track.sections) is utils.SectionData
    assert type(track.beats) is utils.BeatData

    # test audio loading functions
    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2,)

    repr_string = (
        "RWC-Genre Track(track_id=RM-G002, "
        + "audio_path=tests/resources/mir_datasets/RWC-Genre/audio/rwc-g-m01/2.wav, "
        + "piece_number=No. 2, suffix=M01, track_number=Tr. 02, category=Pop, "
        + "sub_category=Pop, title=Forget about It, composer=Shinya Iguchi, "
        + "artist=Shinya Iguchi (Male), duration=262.0, "
        + "sections=SectionData('intervals', 'labels'), "
        + "beats=BeatData('beat_times', 'beat_positions'))"
    )
github mir-dataset-loaders / mirdata / tests / test_rwc_classical.py View on Github external
def test_load_sections():
    # load a file which exists
    section_path = (
        'tests/resources/mir_datasets/RWC-Classical/'
        + 'annotations/AIST.RWC-MDB-C-2001.CHORUS/RM-C003.CHORUS.TXT'
    )
    section_data = rwc_classical.load_sections(section_path)

    # check types
    assert type(section_data) == utils.SectionData
    assert type(section_data.intervals) is np.ndarray
    assert type(section_data.labels) is list

    # check values
    assert np.array_equal(section_data.intervals[:, 0], np.array([0.29, 419.96]))
    assert np.array_equal(section_data.intervals[:, 1], np.array([46.14, 433.71]))
    assert np.array_equal(section_data.labels, np.array(['chorus A', 'ending']))

    # load a file which doesn't exist
    section_data_none = rwc_classical.load_sections('fake/file/path')
    assert section_data_none is None
github mir-dataset-loaders / mirdata / tests / test_rwc_popular.py View on Github external
+ 'annotations/AIST.RWC-MDB-P-2001.VOCA_INST/RM-P001.VOCA_INST.TXT',
        'piece_number': 'No. 1',
        'suffix': 'M01',
        'track_number': 'Tr. 01',
        'title': 'Eien no replica',
        'artist': 'Kazuo Nishi',
        'singer_information': 'Male',
        'duration': 209,
        'tempo': '135',
        'instruments': 'Gt',
        'drum_information': 'Drum sequences',
    }

    expected_property_types = {
        'beats': utils.BeatData,
        'sections': utils.SectionData,
        'chords': utils.ChordData,
        'vocal_instrument_activity': utils.EventData,
    }

    run_track_tests(track, expected_attributes, expected_property_types)

    # test audio loading functions
    y, sr = track.audio
    assert sr == 44100
    assert y.shape == (44100 * 2,)
github mir-dataset-loaders / mirdata / mirdata / beatles.py View on Github external
Returns:
        (utils.SectionData): loaded section data

    """
    if sections_path is None or not os.path.exists(sections_path):
        return None

    start_times, end_times, sections = [], [], []
    with open(sections_path, 'r') as fhandle:
        reader = csv.reader(fhandle, delimiter='\t')
        for line in reader:
            start_times.append(float(line[0]))
            end_times.append(float(line[1]))
            sections.append(line[3])

    section_data = utils.SectionData(np.array([start_times, end_times]).T, sections)

    return section_data
github mir-dataset-loaders / mirdata / mirdata / salami.py View on Github external
raise IOError("sections_path {} does not exist".format(sections_path))

    times = []
    secs = []
    with open(sections_path, 'r') as fhandle:
        reader = csv.reader(fhandle, delimiter='\t')
        for line in reader:
            times.append(float(line[0]))
            secs.append(line[1])
    times = np.array(times)
    secs = np.array(secs)

    # remove sections with length == 0
    times_revised = np.delete(times, np.where(np.diff(times) == 0))
    secs_revised = np.delete(secs, np.where(np.diff(times) == 0))
    return utils.SectionData(
        np.array([times_revised[:-1], times_revised[1:]]).T, list(secs_revised[:-1])
    )
github mir-dataset-loaders / mirdata / mirdata / jams_utils.py View on Github external
Convert sections annotations into jams format.

    Parameters
    ----------
    sections: tuple
        A tuple in the format (SectionData, str), where str describes the annotation
        and SectionData is the sections mirdata annotation format.

    Returns
    -------
    jannot_seg: JAM segment_open annotation object.
    '''
    jannot_seg = jams.Annotation(namespace='segment_open')
    jannot_seg.annotation_metadata = jams.AnnotationMetadata(data_source='mirdata')
    if sections[0] is not None:
        if type(sections[0]) != utils.SectionData:
            raise TypeError('Type should be SectionData.')
        for inter, seg in zip(sections[0].intervals, sections[0].labels):
            jannot_seg.append(time=inter[0], duration=inter[1] - inter[0], value=seg)
    if sections[1] is not None:
        jannot_seg.sandbox = jams.Sandbox(name=sections[1])
    return jannot_seg