diff --git a/pyroomacoustics/datasets/sofa.py b/pyroomacoustics/datasets/sofa.py index b636e749..4dd38152 100644 --- a/pyroomacoustics/datasets/sofa.py +++ b/pyroomacoustics/datasets/sofa.py @@ -1,7 +1,7 @@ import json from pathlib import Path -from .utils import download_multiple +from .utils import download_multiple, AttrDict _pra_data_folder = Path(__file__).parents[1] / "data" DEFAULT_SOFA_PATH = _pra_data_folder / "sofa" @@ -49,3 +49,9 @@ def download_sofa_files(path=None, overwrite=False, verbose=False): download_multiple(files, overwrite=overwrite, verbose=verbose) return list(files.keys()) + + +def SOFADatabase(AttrDict): + def __init__(self): + self._db = get_sofa_db_info() + super().__init__(self._db) diff --git a/pyroomacoustics/datasets/utils.py b/pyroomacoustics/datasets/utils.py index a78bbfff..8d1817b7 100644 --- a/pyroomacoustics/datasets/utils.py +++ b/pyroomacoustics/datasets/utils.py @@ -34,6 +34,27 @@ from urllib import urlopen, urlretrieve +class AttrDict(object): + """Convert a dictionary into an object""" + + def __init__(self, dictionary): + for key, val in dictionary.items(): + if isinstance(val, dict): + setattr(self, key, Dict2Obj(val)) + elif isinstance(val, list): + setattr( + self, key, [Dict2Obj(v) if isinstance(v, dict) else v for v in val] + ) + else: + setattr(self, key, val) + + def __getitem__(self, key): + return getattr(self, key) + + def __setitem__(self, key, val): + return setattr(self, key, val) + + def download_uncompress(url, path=".", compression=None, context=None): """ This functions download and uncompress on the fly a file