Skip to content

Commit

Permalink
adds sofa database as attrdict
Browse files Browse the repository at this point in the history
  • Loading branch information
fakufaku committed Apr 23, 2024
1 parent b0d2b1d commit b4abb9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pyroomacoustics/datasets/sofa.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
21 changes: 21 additions & 0 deletions pyroomacoustics/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4abb9b

Please sign in to comment.