Skip to content

Commit 67abaa1

Browse files
authored
Merge pull request #55 from mikofski/model_metaclass
Model metaclass * fixes #56 * model layers can be declared in model class as dictionaries or classes * consolidate BasicModel into Model class * adds BaseModel meta class
2 parents e0e283d + e3d8845 commit 67abaa1

12 files changed

Lines changed: 322 additions & 153 deletions

File tree

carousel/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
__author__ = u'Mark Mikofski'
88
__email__ = u'mark.mikofski@sunpowercorp.com'
99
__url__ = u'https://github.com/SunPower/Carousel'
10-
__version__ = u'0.2.4'
11-
__release__ = u'Blue Balloons'
10+
__version__ = u'0.2.6'
11+
__release__ = u'Bicycle Bears'

carousel/core/calculations.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ def index_registry(args, arg_key, reg, ts, idx=None):
140140

141141

142142
class CalcBase(CommonBase):
143+
"""
144+
Base calculation meta class.
145+
"""
143146
_path_attr = 'calcs_path'
144147
_file_attr = 'calcs_file'
145148

carousel/core/data_sources.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,22 @@ def register(self, newdata, *args, **kwargs):
130130

131131
class DataSourceBase(CommonBase):
132132
"""
133-
Most general data source.
133+
Base data source meta class.
134134
"""
135135
_path_attr = 'data_path'
136136
_file_attr = 'data_file'
137137
_reader_attr = 'data_reader'
138138
_enable_cache_attr = 'data_cache_enabled'
139139

140140
def __new__(mcs, name, bases, attr):
141-
# use only with Calc subclasses
141+
# use only with DataSource subclasses
142142
if not CommonBase.get_parents(bases, DataSourceBase):
143143
return super(DataSourceBase, mcs).__new__(mcs, name, bases, attr)
144144
# pop the data reader so it can be overwritten
145145
reader = attr.pop(mcs._reader_attr, None)
146146
cache_enabled = attr.pop(mcs._enable_cache_attr, None)
147147
meta = attr.pop('Meta', None)
148-
# set param file full path if calculation path and file specified or
148+
# set param file full path if data source path and file specified or
149149
# try to set parameters from class attributes except private/magic
150150
attr = mcs.set_param_file_or_parameters(attr)
151151
# set data-reader attribute if in subclass, otherwise read it from base

carousel/core/layers.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,22 @@
2727

2828
import importlib
2929
import os
30-
from carousel.core.simulations import SimRegistry
31-
from carousel.core.data_sources import DataRegistry
32-
from carousel.core.formulas import FormulaRegistry
33-
from carousel.core.calculations import CalcRegistry
34-
from carousel.core.outputs import OutputRegistry
30+
from carousel.core.simulations import SimRegistry, Simulation
31+
from carousel.core.data_sources import DataRegistry, DataSource
32+
from carousel.core.formulas import FormulaRegistry, Formula
33+
from carousel.core.calculations import CalcRegistry, Calc
34+
from carousel.core.outputs import OutputRegistry, Output
3535

3636

3737
class Layer(object):
3838
"""
3939
A layer in the model.
4040
41-
:param layer_data: Dictionary of model data specific to this layer.
42-
:type layer_data: dict
41+
:param sources: Dictionary of model parameters specific to this layer.
42+
:type sources: dict
4343
"""
4444
reg_cls = NotImplemented #: registry class
45+
src_cls = NotImplemented #: source class
4546

4647
def __init__(self, sources=None):
4748
#: dictionary of layer sources
@@ -104,9 +105,6 @@ class Data(Layer):
104105
"""
105106
The Data layer of the model.
106107
107-
:param data: Dictionary of model data specific to the data layer.
108-
:type data: :class:`~carousel.core.data_sources.DataRegistry`
109-
110108
The :attr:`~Layer.layer` attribute is a dictionary of data sources names
111109
as keys of dictionaries for each data source with the module and optionally
112110
the package containing the module, the filename, which can be ``None``,
@@ -115,6 +113,7 @@ class Data(Layer):
115113
to Carousel is used. External data files should specify the path.
116114
"""
117115
reg_cls = DataRegistry #: data layer registry
116+
src_cls = DataSource #: data layer source
118117

119118
def add(self, data_source, module, package=None):
120119
"""
@@ -219,6 +218,7 @@ class Formulas(Layer):
219218
Layer containing formulas.
220219
"""
221220
reg_cls = FormulaRegistry #: formula layer registry
221+
src_cls = Formula #: formula layer source
222222

223223
def add(self, formula, module, package=None):
224224
"""
@@ -259,6 +259,7 @@ class Calculations(Layer):
259259
Layer containing formulas.
260260
"""
261261
reg_cls = CalcRegistry #: calculations layer registry
262+
src_cls = Calc #: calculation layer source
262263

263264
def add(self, calc, module, package=None):
264265
"""
@@ -289,6 +290,7 @@ class Outputs(Layer):
289290
Layer containing output sources.
290291
"""
291292
reg_cls = OutputRegistry #: output layer registry
293+
src_cls = Output #: output layer source
292294

293295
def add(self, output, module, package=None):
294296
"""
@@ -318,6 +320,7 @@ class Simulations(Layer):
318320
Layer containing simulation sources.
319321
"""
320322
reg_cls = SimRegistry #: simulation layer registry
323+
src_cls = Simulation #: simulation layer source
321324

322325
def add(self, sim, module, package=None):
323326
"""

0 commit comments

Comments
 (0)