Commit d6654942 authored by BorjaEst's avatar BorjaEst
Browse files

convert Source.models to property and add construction tests

parent 741e70ab
......@@ -39,7 +39,6 @@ class Source:
def __init__(self, name, collections): = name
self.models = [x for x in collections.keys()]
self._models = {}"Load source '%s'",
for name, specifications in collections.items():
......@@ -51,13 +50,17 @@ class Source:
def __getitem__(self, model_name):
return self._models[model_name]
def models(self):
return self._models.keys()
def skim(self, groupby=None):
"""Request to skim all source data into the current folder
:param groupby: How to group output (None, year, decade).
:type groupby: str, optional
for model in self.models:
for model in self._models:
dirname = "{source}_{model}".format(, model=model)
os.makedirs(dirname, exist_ok=True)"Skim data from '%s'", dirname)
......@@ -87,12 +90,31 @@ def __load_model(tco3_zm=None, vmro3_zm=None):
return dataset
class TestsSource(unittest.TestCase):
name = "SourceTest"
collections = {} # Empty, only to test constructor stability
def setUp(self):
self.source = Source(, TestsSource.collections)
def test_property_name(self):
expected =
result =
self.assertEqual(expected, result)
def test_property_models(self):
expected = TestsSource.collections.keys()
result = self.source.models
self.assertEqual(expected, result)
class TestsModel(unittest.TestCase):
tco3 = np.random.rand(3, 3, 25)
vmro3 = np.random.rand(3, 3, 4, 25)
@ staticmethod
def model():
return xr.Dataset(
Supports Markdown
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