Commit f21d947a authored by Carl Schaffer's avatar Carl Schaffer
Browse files

adding initial version of data accessor

parent e792ab3b
from os import walk
from os.path import join, dirname, abspath, basename
_datadir = abspath(join(dirname(__file__), "data"))
class AttrDict(dict):
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict__ = self
class TestDataAccessor():
"""Class to facilitate easy access to test data. Data is stored in a separate folder and accessed as attributes e.g.
TestDataAccessor().chrotel.l1_data will give you a list of filenames for chrotel level 1 data.
"""
def __init__(self):
print(_datadir)
_container = AttrDict()
for root, dirs, files in walk(_datadir):
if files:
instr = basename(dirname(root))
data_type = basename(root)
files = [join(root, f) for f in files]
if instr not in _container:
_container[instr] = AttrDict()
_container[instr][data_type] = files
print(instr, data_type, files)
self._container = _container
def __getattr__(self, item):
return self._container[item]
def __str__(self):
from pprint import pformat
return pformat(self._container)
from data_accessor import TestDataAccessor
test_data = TestDataAccessor()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment