### Documenting function usage with examples Source: https://mirdata.readthedocs.io/en/stable/source/contributing.html Demonstrates how to include a usage example within a function docstring. ```python foo = add_to_list([1, 2, 3], 2) ``` -------------------------------- ### Install mirdata Source: https://mirdata.readthedocs.io/en/stable/_sources/index.rst.txt Use pip to install the mirdata library. ```bash pip install mirdata ``` -------------------------------- ### Example documentation table entry Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Example of how to format a dataset entry in the documentation table. ```rst * - Beatport EDM key - - audio: ✅ - annotations: ✅ - - global :ref:`key` - 1486 - .. image:: https://licensebuttons.net/l/by-sa/3.0/88x31.png :target: https://creativecommons.org/licenses/by-sa/4.0 ``` -------------------------------- ### Install Mirdata development dependencies Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Install core, testing, documentation, or dataset-specific dependencies for local development. ```bash # Install Core dependencies pip install . #Install Testing dependencies pip install ."[tests]" #Install Docs dependencies pip install ."[docs]" #Install dataset-specific dependencies pip install ."[dataset]" # where dataset can be dali | haydn_op20 | cipi ... ``` -------------------------------- ### Initialize DataLoader for Training Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt Example of initializing a DataLoader with a mirdata dataset and iterating through batches. ```python md = DataLoader(MIRDataset("orchset"), batch_size=2, shuffle=True, drop_last=False) for audio, times, freqs in md: pass # train your model on this data ``` -------------------------------- ### Create dataset index script Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Example script used to generate dataset indexes. ```python from mirdata import utils import os import json # This is a placeholder for the actual script content # Refer to the mirdata/scripts folder for full implementations def make_index(data_path, save_path): index = {} # Logic to traverse data_path and build index with open(save_path, 'w') as f: json.dump(index, f, indent=4) ``` -------------------------------- ### Define dataset structure Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Example directory structure for a dataset version. ```javascript > Example_Dataset/ > audio/ track1.wav track2.wav track3.wav > annotations/ track1.csv Track2.csv track3.csv > metadata/ metadata_file.csv ``` -------------------------------- ### Implement Google-style docstrings Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Follow specific indentation and formatting rules for function documentation, including parameter descriptions and usage examples. ```python def add_to_list(list_of_numbers, scalar): """Add a scalar to every element of a list. You can write a continuation of the function description here on the next line. You can optionally write more about the function here. If you want to add an example of how this function can be used, you can do it like below. Example: .. code-block:: python foo = add_to_list([1, 2, 3], 2) Args: list_of_numbers (list): A short description that fits on one line. scalar (float): Description of the second parameter. If there is a lot to say you can overflow to a second line. ``` -------------------------------- ### Define a multitrack dataset structure Source: https://mirdata.readthedocs.io/en/stable/source/contributing.html Example directory structure for a multitrack dataset. ```text > Example_Dataset/ > audio/ multitrack1-voice1.wav multitrack1-voice2.wav multitrack1-accompaniment.wav multitrack1-mix.wav multitrack2-voice1.wav multitrack2-voice2.wav multitrack2-accompaniment.wav multitrack2-mix.wav > annotations/ multitrack1-voice-f0.csv multitrack2-voice-f0.csv multitrack1-f0.csv multitrack2-f0.csv > metadata/ metadata_file.csv ``` -------------------------------- ### Example Dataset Directory Structure Source: https://mirdata.readthedocs.io/en/stable/source/contributing.html Represents the expected file organization for a dataset version 1.0 to be indexed. ```text Example_Dataset/ audio/ track1.wav track2.wav track3.wav annotations/ track1.csv Track2.csv track3.csv metadata/ metadata_file.csv ``` -------------------------------- ### Handle optional dependencies in dataset modules Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Use a try/except block to import optional dependencies and provide clear installation instructions if the module is missing. ```python try: import asdf except ImportError: logging.error( "In order to use example_dataset you must have asdf installed. " "Please reinstall mirdata using `pip install 'mirdata[example_dataset]'" ) raise ImportError ``` -------------------------------- ### Initialize and use a dataset Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt A complete workflow demonstrating listing datasets, initializing a loader, downloading, validating, and accessing track data. ```python # Basic Usage Example import mirdata # 1. List all available datasets print(mirdata.list_datasets()) # 2. Initialize a dataset loader dataset = mirdata.initialize("orchset", data_home='/choose/where/data/live') # 3. Download the dataset dataset.download() # 4. validate the dataset dataset.validate() # 5. Load tracks random_track = dataset.choice_track() # 6. Access metadata and annotations print(random_track) ``` -------------------------------- ### Initialize the dataset Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/compmusic_carnatic_rhythm.html Use this command to initialize the dataset after downloading and uncompressing the files to a local directory. ```python compmusic_carnatic_rhythm = mirdata.initialize("compmusic_carnatic_rhythm", data_home="/path/to/home/folder/of/dataset"). ``` -------------------------------- ### Initialize CompMusic Hindustani Rhythm Dataset Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/compmusic_hindustani_rhythm.html Use this command to initialize the dataset after downloading and uncompressing the files from Zenodo. ```python compmusic_hindustani_rhythm = mirdata.initialize("compmusic_hindustani_rhythm", data_home="/path/to/home/folder/of/dataset") ``` -------------------------------- ### Dataset Index Structure Example Source: https://mirdata.readthedocs.io/en/stable/_sources/source/overview.rst.txt Example of a JSON-based dataset index structure defining metadata and track-level annotations. ```json { "version": "1.0.0", "metadata": { "metadata_file_1": [ // the relative path for metadata_file_1 "path_to_metadata/metadata_file_1.csv", // metadata_file_1 md5 checksum "bb8b0ca866fc2423edde01325d6e34f7" ], "metadata_file_2": [ // the relative path for metadata_file_2 "path_to_metadata/metadata_file_2.csv", // metadata_file_2 md5 checksum "6cce186ce77a06541cdb9f0a671afb46" ] } "tracks": { "track1": { 'audio': ["audio_files/track1.wav", "6c77777ce77a06541cdb9f0a671afb46"], 'beats': ["annotations/track1.beats.csv", "ab8b0ca866fc2423edde01325d6e34f7"], 'sections': ["annotations/track1.sections.txt", "05abeca866fc2423edde01325d6e34f7"], } "track2": { 'audio': ["audio_files/track2.wav", "6c77777ce77a06542cdb9f0a672afb46"], 'beats': ["annotations/track2.beats.csv", "ab8b0ca866fc2423edde02325d6e34f7"], 'sections': ["annotations/track2.sections.txt", "05abeca866fc2423edde02325d6e34f7"], } ... } } ``` -------------------------------- ### Get notes for a section Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/phenicx_anechoic.html Retrieves NoteData for a specific section. ```python def get_notes_for_section(self, section, notes_property="notes"): """Get the notes for a particular section Args: section (str): the section to get the notes for notes_property (str): the attribute associated with NoteData, notes or notes_original Returns: NoteData: Note data for the section """ return self.get_notes_target( self.sections[section], notes_property=notes_property ) ``` -------------------------------- ### Get notes for an instrument Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/phenicx_anechoic.html Retrieves NoteData for a specific instrument. ```python def get_notes_for_instrument(self, instrument, notes_property="notes"): """Get the notes for a particular instrument Args: instrument (str): the instrument to get the notes for notes_property (str): the attribute associated with NoteData, notes or notes_original Returns: NoteData: Note data for the instrument """ return getattr(self.tracks[self.instruments[instrument]], notes_property) ``` -------------------------------- ### Build documentation locally Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Generate HTML documentation from the docs folder using Sphinx. ```bash make html ``` -------------------------------- ### initialize(dataset_name, data_home=None, version='default') Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata.html Loads a mirdata dataset by name, returning a Dataset object. ```APIDOC ## initialize(dataset_name, data_home=None, version='default') ### Description Initializes and returns a mirdata.core.Dataset object for the specified dataset. ### Parameters - **dataset_name** (str) - The name of the dataset to load. - **data_home** (str or None) - Optional path where the data is stored. If None, uses the default location. - **version** (str or None) - The version of the dataset to load. If None, the default version is loaded. ### Returns - **Dataset** - A mirdata.core.Dataset object. ``` -------------------------------- ### Get notes for a target Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/phenicx_anechoic.html Aggregates NoteData from a list of track keys. ```python def get_notes_target(self, track_keys, notes_property="notes"): """Get the notes for all the tracks Args: track_keys (list): list of track keys to get the NoteData for notes_property (str): the attribute associated with NoteData, notes or notes_original Returns: NoteData: Note data for the tracks """ notes_target = None for k in track_keys: score = getattr(self.tracks[k], notes_property) if notes_target is None: notes_target = score else: notes_target += score return notes_target ``` -------------------------------- ### Initialize SALAMI Dataset class Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/salami.html Defines the Dataset class for SALAMI, inheriting from core.Dataset and setting up configuration. ```python @core.docstring_inherit(core.Dataset) class Dataset(core.Dataset): """ The salami dataset """ def __init__(self, data_home=None, version="default"): super().__init__( data_home, version, name="salami", track_class=Track, bibtex=BIBTEX, indexes=INDEXES, remotes=REMOTES, download_info=DOWNLOAD_INFO, license_info=LICENSE_INFO, ) ``` -------------------------------- ### Access track metadata Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Example of the resulting metadata accessible for a specific track ID. ```python { 'artist': 'B', 'genre': 'Y' } ``` -------------------------------- ### mirdata.initialize Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/compmusic_carnatic_rhythm.html Initializes the CompMusic Carnatic Music Rhythm dataset loader. ```APIDOC ## mirdata.initialize("compmusic_carnatic_rhythm", data_home="/path/to/home/folder/of/dataset") ### Description Initializes the dataset loader for the CompMusic Carnatic Music Rhythm dataset. Users must provide the local path where the dataset files are stored. ### Parameters - **dataset_name** (str) - Required - The name of the dataset, "compmusic_carnatic_rhythm". - **data_home** (str) - Required - The local path where the dataset is stored. ``` -------------------------------- ### MultiTrack.get_random_target Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Gets a random target by combining a random selection of tracks with random weights. ```APIDOC ## get_random_target(n_tracks=None, min_weight=0.3, max_weight=1.0) ### Description Get a random target by combining a random selection of tracks with random weights. ### Parameters - **n_tracks** (int or None) - Optional - Number of tracks to randomly mix. - **min_weight** (float) - Optional - Minimum possible weight when mixing. - **max_weight** (float) - Optional - Maximum possible weight when mixing. ### Returns - **np.ndarray** - Mixture audio with shape (n_samples, n_channels). - **list** - List of keys of included tracks. - **list** - List of weights used to mix tracks. ``` -------------------------------- ### NoteData.__init__ Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/annotations.html Initializes a new NoteData object with intervals, pitches, and optional confidence data. ```APIDOC ## NoteData.__init__(intervals, interval_unit, pitches, pitch_unit, confidence=None, confidence_unit=None) ### Description Initializes a NoteData object. Validates input arrays and units, and removes duplicate entries. ### Parameters - **intervals** (np.ndarray) - Required - (n x 2) array of [start_time, end_time]. - **interval_unit** (str) - Required - Unit of time values. - **pitches** (np.ndarray) - Required - Array of pitches. - **pitch_unit** (str) - Required - Unit of pitch values. - **confidence** (np.ndarray) - Optional - Array of confidence values. - **confidence_unit** (str) - Optional - Unit of confidence values. ``` -------------------------------- ### maestro.validate(verbose=True) Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Validates the local dataset installation by checking for missing files and invalid checksums. ```APIDOC ## maestro.validate(verbose=True) ### Description Validates if the stored dataset is a valid version. ### Parameters - **verbose** (bool) - Optional - If False, don't print output. Defaults to True. ### Returns - **list** - Files in the index but missing locally. - **list** - Files which have an invalid checksum. ``` -------------------------------- ### Initialize a mirdata dataset Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata.html Demonstrates how to load, download, validate, and interact with a dataset using the initialize function. ```python orchset = mirdata.initialize('orchset') # get the orchset dataset orchset.download() # download orchset orchset.validate() # validate orchset track = orchset.choice_track() # load a random track print(track) # see what data a track contains orchset.track_ids() # load all track ids ``` -------------------------------- ### MultiTrack Class Initialization and Audio Access Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/jtd.html Initialization logic for the MultiTrack class and properties for accessing audio channels. ```python def __init__( self, mtrack_id, data_home, dataset_name, index, track_class, metadata ): super().__init__( mtrack_id=mtrack_id, data_home=data_home, dataset_name=dataset_name, index=index, track_class=track_class, metadata=lambda: json.load(open(self.get_path("metadata"), "r")), ) self.audio_path = self.get_path("audio") self.audio_lchan_path = self.get_path("audio-lchan") self.audio_rchan_path = self.get_path("audio-rchan") self.beats_path = self.get_path("beats") ``` ```python @property def album(self) -> str: """The name of the album that this performance was taken from Returns: * str - name of the album """ return self._multitrack_metadata["album_name"] ``` ```python @property def audio(self) -> Optional[Tuple[np.ndarray, float]]: """The track's audio, center channel Returns: * np.ndarray - audio signal * float - sample rate """ return load_audio(self.audio_path) ``` ```python @property def audio_lchan(self) -> Optional[Tuple[np.ndarray, float]]: """The track's audio, left channel (not present for all tracks) Returns: * np.ndarray - audio signal * float - sample rate """ return load_audio(self.audio_lchan_path) ``` -------------------------------- ### DALI Dataset Dependency Check Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/dali.html Ensures the dali-dataset package is installed before proceeding with data loading. ```python try: import DALI except ImportError as E: logging.error( "In order to use dali you must have dali-dataset installed. " "Please reinstall mirdata using `pip install 'mirdata[dali]'" ) raise ``` -------------------------------- ### mirdata.core.Dataset.__init__ Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Initializes a new Dataset instance with configuration for data paths, versions, and class mappings. ```APIDOC ## Dataset(data_home=None, version='default', name=None, track_class=None, multitrack_class=None, bibtex=None, indexes=None, remotes=None, download_info=None, license_info=None) ### Description Initializes the dataset object. This sets up the environment for interacting with a specific dataset, including defining where data is stored and how tracks or multitracks are handled. ### Parameters - **data_home** (str or None) - Optional - Path where mirdata will look for the dataset. - **version** (str) - Optional - Dataset version. - **name** (str or None) - Optional - The identifier of the dataset. - **track_class** (mirdata.core.Track or None) - Optional - A Track class. - **multitrack_class** (mirdata.core.Multitrack or None) - Optional - A Multitrack class. - **bibtex** (str or None) - Optional - Dataset citation/s in bibtex format. - **indexes** (dict or None) - Optional - Indexes to be downloaded. - **remotes** (dict or None) - Optional - Data to be downloaded. - **download_info** (str or None) - Optional - Download instructions or caveats. - **license_info** (str or None) - Optional - License of the dataset. ``` -------------------------------- ### load_midi(fhandle: BinaryIO) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/groove_midi.html Loads a Groove MIDI file into a pretty_midi object. ```APIDOC ## load_midi(fhandle: BinaryIO) ### Description Load a Groove MIDI midi file. ### Parameters - **fhandle** (str or file-like) - Required - File-like object or path to midi file ### Returns - **pretty_midi.PrettyMIDI** - pretty_midi object ``` -------------------------------- ### Define metadata dictionary structure Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Example of a metadata dictionary structure returned by a _metadata cached property. ```python { 'track1': { 'artist': 'A', 'genre': 'Z' }, 'track2': { 'artist': 'B', 'genre': 'Y' } } ``` -------------------------------- ### Manage dataset versions Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt List available versions for a dataset and initialize a specific version. ```python # To see all available versions of a specific dataset: mirdata.list_dataset_versions('orchset') #Use 'version' parameter if you wish to use a version other than the default one. dataset = mirdata.initialize('orchset', data_home='/choose/where/data/live', version="1.0") ``` -------------------------------- ### Define dataset remote files Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt Example structure for defining remote file metadata in a dataset loader. ```python REMOTES = { "spectrogram": download_utils.RemoteFileMetadata( filename="cante100_spectrum.zip", url="https://zenodo.org/record/1322542/files/cante100_spectrum.zip?download=1", checksum="0b81fe0fd7ab2c1adc1ad789edb12981", # the md5 checksum destination_dir="cante100_spectrum", # relative path for where to unzip the data, or None ), "melody": download_utils.RemoteFileMetadata( filename="cante100midi_f0.zip", url="https://zenodo.org/record/1322542/files/cante100midi_f0.zip?download=1", checksum="cce543b5125eda5a984347b55fdcd5e8", # the md5 checksum destination_dir="cante100midi_f0", # relative path for where to unzip the data, or None ), "notes": download_utils.RemoteFileMetadata( filename="cante100_automaticTranscription.zip", url="https://zenodo.org/record/1322542/files/cante100_automaticTranscription.zip?download=1", checksum="47fea64c744f9fe678ae5642a8f0ee8e", # the md5 checksum destination_dir="cante100_automaticTranscription", # relative path for where to unzip the data, or None ), "metadata": download_utils.RemoteFileMetadata( filename="cante100Meta.xml", url="https://zenodo.org/record/1322542/files/cante100Meta.xml?download=1", checksum="6cce186ce77a06541cdb9f0a671afb46", # the md5 checksum ), "README": download_utils.RemoteFileMetadata( filename="cante100_README.txt", url="https://zenodo.org/record/1322542/files/cante100_README.txt?download=1", checksum="184209b7e7d816fa603f0c7f481c0aae", # the md5 checksum ), } ``` -------------------------------- ### Initialize Track object structure Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt Example of the Track data class structure used for representing dataset entries. ```python >>> Track( alternating_melody=True, audio_path_mono="user/mir_datasets/orchset/audio/mono/Beethoven-S3-I-ex1.wav", audio_path_stereo="user/mir_datasets/orchset/audio/stereo/Beethoven-S3-I-ex1.wav", composer="Beethoven", contains_brass=False, contains_strings=True, contains_winds=True, excerpt="1", melody_path="user/mir_datasets/orchset/GT/Beethoven-S3-I-ex1.mel", only_brass=False, only_strings=False, only_winds=False, predominant_melodic_instruments=['strings', 'winds'], track_id="Beethoven-S3-I-ex1", work="S3-I", audio_mono: (np.ndarray, float), audio_stereo: (np.ndarray, float), melody: F0Data, ) ``` -------------------------------- ### Initialize Dataset Class Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/idmt_smt_audio_effects.html Constructor for the IDMT-SMT-Audio-Effects dataset class, setting up paths and configuration. ```python def __init__(self, data_home=None, version="default"): super().__init__( data_home, version, name="idmt_smt_audio_effects", track_class=Track, bibtex=BIBTEX, indexes=INDEXES, remotes=REMOTES, download_info=DOWNLOAD_INFO, license_info=LICENSE_INFO, ) ``` -------------------------------- ### Example Dataset Index Structure Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt A JSON-like structure representing the index file for a dataset, mapping tracks and multitracks to their respective files and checksums. ```javascript { "version": 1, "tracks": { "multitrack1-voice": { "audio_voice1": ('audio/multitrack1-voice1.wav', checksum), "audio_voice2": ('audio/multitrack1-voice1.wav', checksum), "voice-f0": ('annotations/multitrack1-voice-f0.csv', checksum) } "multitrack1-accompaniment": { "audio_accompaniment": ('audio/multitrack1-accompaniment.wav', checksum) } "multitrack2-voice" : {...} ... }, "multitracks": { "multitrack1": { "tracks": ['multitrack1-voice', 'multitrack1-accompaniment'], "audio": ('audio/multitrack1-mix.wav', checksum) "f0": ('annotations/multitrack1-f0.csv', checksum) } "multitrack2": ... }, "metadata": { "metadata_file": [ "metadata/metadata_file.csv", "7a41b280c7b74e2ddac5184708f9525b" ] } } ``` -------------------------------- ### Define Download and License Information Source: https://mirdata.readthedocs.io/en/stable/source/contributing.html Strings containing instructions for users and license details for the dataset. ```python DOWNLOAD_INFO = """ Include any information you want to be printed when dataset.download() is called. These can be instructions for how to download the dataset (e.g. request access on zenodo), caveats about the download, etc """ # -- Include the dataset's license information LICENSE_INFO = """ The dataset's license information goes here. """ ``` -------------------------------- ### Initialize MDB-stem-synth Dataset Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/mdb_stem_synth.html The Dataset class provides the main interface for interacting with the MDB-stem-synth collection. ```python @core.docstring_inherit(core.Dataset) class Dataset(core.Dataset): """ The MDB-stem-synth dataset """ def __init__(self, data_home=None, version="default"): super().__init__( data_home, version, name="mdb_stem_synth", track_class=Track, bibtex=BIBTEX, indexes=INDEXES, remotes=REMOTES, license_info=LICENSE_INFO, ) ``` -------------------------------- ### load_audio(fhandle) Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Loads a MTG Jamendo Autotagging Moodtheme audio file. ```APIDOC ### Method `load_audio(fhandle)` ### Description Load a MTG jamendo autotagging moodtheme audio file. ### Parameters - **fhandle** (str or file-like) - Required - Path or file-like object pointing to an audio file. ### Returns - **tuple** - (np.ndarray, float) - The mono audio signal and the sample rate. ``` -------------------------------- ### Test dataset integration with pytest Source: https://mirdata.readthedocs.io/en/stable/source/contributing.html Example of a test file for a dataset loader, verifying track attributes and property types using the run_track_tests utility. ```python """Tests for example dataset """ import numpy as np import pytest from mirdata import annotations from mirdata.datasets import example from tests.test_utils import run_track_tests def test_track(): default_trackid = "some_id" data_home = "tests/resources/mir_datasets/dataset" dataset = example.Dataset(data_home, version="test") track = dataset.track(default_trackid) expected_attributes = { "track_id": "some_id", "audio_path": "tests/resources/mir_datasets/example/" + "Wavfile/some_id.wav", "song_id": "some_id", "annotation_path": "tests/resources/mir_datasets/example/annotation/some_id.pv", } expected_property_types = {"annotation": annotations.XData} assert track._track_paths == { "audio": ["Wavfile/some_id.wav", "278ae003cb0d323e99b9a643c0f2eeda"], "annotation": ["Annotation/some_id.pv", "0d93a011a9e668fd80673049089bbb14"], } run_track_tests(track, expected_attributes, expected_property_types) ``` -------------------------------- ### Initialize MultiTrack class Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/slakh.html Constructor for the MultiTrack class, setting up paths for mix, MIDI, and metadata. ```python def __init__( self, mtrack_id, data_home, dataset_name, index, track_class, metadata ): super().__init__( mtrack_id=mtrack_id, data_home=data_home, dataset_name=dataset_name, index=index, track_class=track_class, metadata=metadata, ) self.mix_path = self.get_path("mix") self.midi_path = self.get_path("midi") self.metadata_path = self.get_path("metadata") # split (train/validation/test) is determined by the relative filepath in the index self.split = None # for baby_slakh, there are no data splits - set to None if "2100-redux" in index["version"]: # Adding also option for test self.split = os.path.normpath(self._multitrack_paths["mix"][0]).split( os.sep )[1] assert self.split in SPLITS, "{} not in SPLITS".format(self.split) self.data_split = self.split # deprecated in 0.3.6 ``` -------------------------------- ### Run full test suite Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Execute all tests locally with coverage reporting and black formatting checks. ```bash pytest -vv --cov-report term-missing --cov-report=xml --cov=mirdata --black tests/ --local ``` -------------------------------- ### Initialize IndexFile class Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/core.html Constructor for the index file handler, managing remote metadata and local directory paths. ```python def __init__( self, filename: str, url: Optional[str] = None, checksum: Optional[str] = None, partial_download: Optional[List[str]] = None, ): self.filename = filename self.remote: Optional[download_utils.RemoteFileMetadata] self.indexes_dir = os.path.join( os.path.dirname(os.path.realpath(__file__)), "datasets", "indexes", ) if url and checksum: self.remote = download_utils.RemoteFileMetadata( filename=filename, url=url, checksum=checksum, destination_dir=self.indexes_dir, ) elif url or checksum: raise ValueError( "Remote indexes must have both a url and a checksum specified." ) else: self.indexes_dir = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), "tests", "indexes", ) self.remote = None self.partial_download = partial_download ``` -------------------------------- ### load_audio(path: str) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/groove_midi.html Loads a Groove MIDI audio file and returns the audio signal and sample rate. ```APIDOC ## load_audio(path: str) ### Description Loads a Groove MIDI audio file. ### Parameters - **path** (str) - Required - Path to an audio file ### Returns - **np.ndarray** - The mono audio signal - **float** - The sample rate of the audio file ``` -------------------------------- ### Initialize AcousticBrainz Dataset Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/acousticbrainz_genre.html Initializes the Dataset class for the AcousticBrainz genre collection. ```python @core.docstring_inherit(core.Dataset) class Dataset(core.Dataset): """ The acousticbrainz genre dataset """ def __init__(self, data_home=None, version="default"): super().__init__( data_home, version, name=NAME, track_class=Track, bibtex=BIBTEX, indexes=INDEXES, remotes=REMOTES, license_info=LICENSE_INFO, ) ``` -------------------------------- ### Initialize dataset with custom data_home Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt Sets a specific directory for dataset storage using the data_home parameter. ```python dataset = mirdata.initialize('orchset', data_home='/Users/leslieknope/Desktop/orchset123') dataset.download() # Dataset is downloaded to the folder "orchset123" on Leslie Knope's desktop ``` -------------------------------- ### Global Initialization Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Functions for initializing the mirdata environment and listing available datasets. ```APIDOC ## initialize() ### Description Initializes the mirdata environment. ## list_datasets() ### Description Returns a list of all datasets currently supported by the library. ``` -------------------------------- ### mirdata.datasets.good_sounds.Dataset Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Initializes the Good-Sounds dataset loader. ```APIDOC ## mirdata.datasets.good_sounds.Dataset(data_home=None, version='default') ### Description Initializes the Good-Sounds dataset loader instance. ### Parameters - **data_home** (str) - Optional - Path where mirdata will look for the dataset. - **version** (str) - Optional - The version of the dataset to use. ``` -------------------------------- ### Initialize dataset track and multitrack accessors Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/core.html Sets up lambda functions for track and multitrack retrieval and assigns their docstrings dynamically. ```python # this is a hack to be able to have dataset-specific docstrings self.track = lambda track_id: self._track(track_id) self.track.__doc__ = self._track_class.__doc__ # set the docstring self.multitrack = lambda mtrack_id: self._multitrack(mtrack_id) self.multitrack.__doc__ = self._multitrack_class.__doc__ # set the docstring ``` -------------------------------- ### Convert audio files to WAV Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/giantsteps_tempo.html Execute this command to convert the downloaded audio files to the .wav format. ```bash ./convert_audio.sh ``` -------------------------------- ### Initialize Billboard Track Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/billboard.html Constructor for the Billboard track class, setting up paths for various data files. ```python def __init__(self, track_id, data_home, dataset_name, index, metadata): super().__init__(track_id, data_home, dataset_name, index, metadata) self.audio_path = self.get_path("audio") self.salami_path = self.get_path("salami") self.lab_full_path = self.get_path("lab_full") self.lab_majmin7_path = self.get_path("lab_majmin7") self.lab_majmin7inv_path = self.get_path("lab_majmin7inv") self.lab_majmin_path = self.get_path("lab_majmin") self.lab_majmininv_path = self.get_path("lab_majmininv") self.bothchroma_path = self.get_path("bothchroma") self.tuning_path = self.get_path("tuning") ``` -------------------------------- ### Initialize Ballroom Track Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/ballroom.html Constructor for the Ballroom track class, setting up paths for audio, beats, and tempo annotations. ```python def __init__( self, track_id, data_home, dataset_name, index, metadata, ): super().__init__( track_id, data_home, dataset_name, index, metadata, ) # Audio path self.audio_path = self.get_path("audio") # Annotations paths self.beats_path = self.get_path("beats") self.tempo_path = self.get_path("tempo") self.genre = os.path.basename(os.path.dirname(self.audio_path)).lower() ``` -------------------------------- ### Basic Mirdata Usage Source: https://mirdata.readthedocs.io/en/stable/source/tutorial.html A complete workflow demonstrating how to list, initialize, download, validate, and access a dataset. ```python 1# Basic Usage Example 2import mirdata 3 4# 1. List all available datasets 5print(mirdata.list_datasets()) 6 7# 2. Initialize a dataset loader 8dataset = mirdata.initialize("orchset", data_home='/choose/where/data/live') 9 10# 3. Download the dataset 11dataset.download() 12 13# 4. validate the dataset 14dataset.validate() 15 16# 5. Load tracks 17random_track = dataset.choice_track() 18 19# 6. Access metadata and annotations 20print(random_track) ``` -------------------------------- ### Run full dataset integration test Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Verify that a specific dataset downloads, validates, and loads correctly using the local flag. ```bash pytest -s tests/test_full_dataset.py --local --dataset dataset ``` -------------------------------- ### Download MTG Jamendo Audio Files Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/mtg_jamendo_autotagging_moodtheme.html Use the provided script to download, unpack, and validate the dataset audio files. ```console mkdir /path/to/download python3 scripts/download/download.py --dataset autotagging_moodtheme --type audio /path/to/download --unpack --remove ``` -------------------------------- ### load_audio(fhandle) Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Loads a Jingju A Cappella audio file. ```APIDOC ## load_audio(fhandle) ### Description Load Jingju A Cappella Singing audio file. ### Parameters - **fhandle** (str or file-like) - Required - File-like object or path to audio file. ### Returns - **tuple** - (np.ndarray, float) containing the mono audio signal and the sample rate. ``` -------------------------------- ### load_activations(fhandle) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/scms.html Loads a Saraga-Carnatic-Melody-Synth activation annotation file. ```APIDOC ## load_activations(fhandle) ### Description Loads a Saraga-Carnatic-Melody-Synth activation annotation file containing vocal activations. ### Parameters - **fhandle** (str or file-like) - Required - The path or file-like object to the activation annotation file. ### Returns - **EventData** - The vocal activation events, or None if the file is empty. ``` -------------------------------- ### load_audio(fhandle) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/gtzan_genre.html Loads a GTZAN audio file from a file-like object or path. ```APIDOC ## load_audio(fhandle) ### Description Loads a GTZAN audio file and returns the mono audio signal and sample rate. ### Parameters - **fhandle** (str or BinaryIO) - Required - File-like object or path to the audio file. ### Returns - **np.ndarray** - The mono audio signal. - **float** - The sample rate of the audio file. ``` -------------------------------- ### mirdata.datasets.vocadito.Dataset Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Initializes the vocadito dataset loader. ```APIDOC ## mirdata.datasets.vocadito.Dataset(data_home=None, version='default') ### Description Initializes the vocadito dataset loader instance. ### Parameters - **data_home** (str) - Optional - Path where mirdata will look for the dataset. - **version** (str) - Optional - The version of the dataset to load. ``` -------------------------------- ### mirdata.initialize Source: https://mirdata.readthedocs.io/en/stable/_sources/source/mirdata.rst.txt Initializes the mirdata environment, typically used to set up data paths or configurations. ```APIDOC ## mirdata.initialize ### Description Initializes the mirdata library environment. ### Signature `mirdata.initialize(data_home=None)` ``` -------------------------------- ### Initialize LyricData annotation Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/annotations.html Constructor for the LyricData class, including validation for lyrics and intervals. ```python def __init__(self, intervals, interval_unit, lyrics, lyric_unit): validate_array_like(intervals, np.ndarray, float) validate_array_like(lyrics, list, str) validate_lengths_equal([intervals, lyrics]) validate_intervals(intervals, interval_unit) validate_unit(lyric_unit, LYRIC_UNITS) self.intervals = intervals self.interval_unit = interval_unit self.lyrics = lyrics self.lyric_unit = lyric_unit @property def pronunciations(self): logging.warning( "LyricData.pronunciations is deprecated as of 0.3.4 and will be removed in a future" " version. Use LyricData.lyrics." ) return self.lyrics ``` -------------------------------- ### load_audio(audio_path) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/compmusic_indian_tonic.html Loads an Indian Art Music Tonic audio file and returns the audio signal and sample rate. ```APIDOC ## load_audio(audio_path) ### Description Loads an Indian Art Music Tonic audio file from the specified path. ### Parameters - **audio_path** (str or file-like) - Required - Path to the audio file or a file-like object. ### Returns - **np.ndarray** - The mono audio signal. - **float** - The sample rate of the audio file. ``` -------------------------------- ### Initialize a dataset loader Source: https://mirdata.readthedocs.io/en/stable/_sources/source/tutorial.rst.txt Create a loader object for a specific dataset by specifying the data home directory. ```python dataset = mirdata.initialize('orchset', data_home='/choose/where/data/live') ``` -------------------------------- ### load_audio(fhandle) Source: https://mirdata.readthedocs.io/en/stable/source/mirdata.html Loads a TinySOL audio file from a path or file-like object. ```APIDOC ## load_audio(fhandle) ### Description Load a TinySOL audio file. ### Parameters - **fhandle** (str or file-like) - Required - File-like object or path to audio file ### Returns - **np.ndarray** - the mono audio signal - **float** - The sample rate of the audio file ``` -------------------------------- ### Saraga Carnatic Track Class Initialization Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/saraga_carnatic.html Initializes paths for audio and annotation files within the Saraga Carnatic track structure. ```python def __init__(self, track_id, data_home, dataset_name, index, metadata): super().__init__(track_id, data_home, dataset_name, index, metadata) # Audio path self.audio_path = self.get_path("audio-mix") # Multitrack audio paths self.audio_ghatam_path = self.get_path("audio-ghatam") self.audio_mridangam_left_path = self.get_path("audio-mridangam-left") self.audio_mridangam_right_path = self.get_path("audio-mridangam-right") self.audio_violin_path = self.get_path("audio-violin") self.audio_vocal_s_path = self.get_path("audio-vocal-s") self.audio_vocal_path = self.get_path("audio-vocal") # Annotation paths self.ctonic_path = self.get_path("ctonic") self.pitch_path = self.get_path("pitch") self.pitch_vocal_path = self.get_path("pitch-vocal") self.tempo_path = self.get_path("tempo") self.sama_path = self.get_path("sama") self.sections_path = self.get_path("sections") self.phrases_path = self.get_path("phrases") self.metadata_path = self.get_path("metadata") ``` -------------------------------- ### download(partial_download=None, force_overwrite=False, cleanup=False, allow_invalid_checksum=False) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/idmt_smt_audio_effects.html Downloads the IDMT-SMT-AUDIO-EFFECTS dataset. This method handles the downloading of the main archive, extraction of nested zip files, and organization of the dataset directory. ```APIDOC ## download ### Description Downloads and extracts the IDMT-SMT-AUDIO-EFFECTS dataset. It handles the main archive download and subsequent extraction of nested instrument-specific zip files. ### Parameters - **partial_download** (list or None) - Optional - A list of keys of remotes to partially download. If None, all data is downloaded. - **force_overwrite** (bool) - Optional - If True, existing files are overwritten by the downloaded files. - **cleanup** (bool) - Optional - Whether to delete any zip/tar files after extracting. - **allow_invalid_checksum** (bool) - Optional - Whether to allow downloads even if the checksum is invalid. ### Raises - **ValueError**: If invalid keys are passed to partial_download. - **IOError**: If a downloaded file's checksum is different from expected. ``` -------------------------------- ### Run project tests Source: https://mirdata.readthedocs.io/en/stable/_sources/source/contributing.rst.txt Execute the test suite with coverage reporting enabled. ```bash pytest -vv --cov-report term-missing --cov-report=xml --cov=mirdata tests/ --local ``` -------------------------------- ### load_audio(fhandle) Source: https://mirdata.readthedocs.io/en/stable/_modules/mirdata/datasets/slakh.html Loads a Slakh audio file from a given path or file-like object. ```APIDOC ## load_audio(fhandle) ### Description Loads a Slakh audio file and returns the audio signal and its sample rate. ### Parameters - **fhandle** (str or file-like) - Required - Path or file-like object pointing to an audio file. ### Returns - **np.ndarray** - The audio signal. - **float** - The sample rate of the audio file. ```