From ea5ad4dd34a79f6d41548eda4a559a7b61123ef2 Mon Sep 17 00:00:00 2001 From: rowanc1 Date: Fri, 16 May 2014 12:27:58 -0700 Subject: [PATCH] more rules to directive changes. --- SimPEG/Directives.py | 30 +++++++++++++++--------------- SimPEG/Inversion.py | 24 ++++++++++++------------ SimPEG/Survey.py | 4 ++++ 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/SimPEG/Directives.py b/SimPEG/Directives.py index 5f26c022..cff073ac 100644 --- a/SimPEG/Directives.py +++ b/SimPEG/Directives.py @@ -42,13 +42,13 @@ class InversionDirective(object): class DirectiveList(object): - rList = None #: The list of Directives + dList = None #: The list of Directives - def __init__(self, *rules, **kwargs): - self.rList = [] - for r in rules: - assert isinstance(r, InversionDirective), 'All rules must be InversionDirectives not %s' % r.__name__ - self.rList.append(r) + def __init__(self, *directives, **kwargs): + self.dList = [] + for d in directives: + assert isinstance(d, InversionDirective), 'All directives must be InversionDirectives not %s' % d.__name__ + self.dList.append(d) Utils.setKwargs(self, **kwargs) @property @@ -56,8 +56,8 @@ class DirectiveList(object): return getattr(self, '_debug', False) @debug.setter def debug(self, value): - for r in self.rList: - r.debug = value + for d in self.dList: + d.debug = value self._debug = value @property @@ -69,18 +69,18 @@ class DirectiveList(object): if self.inversion is i: return if getattr(self,'_inversion',None) is not None: print 'Warning: %s has switched to a new inversion.' % self.__name__ - for r in self.rList: - r.inversion = i + for d in self.dList: + d.inversion = i self._inversion = i def call(self, ruleType): - if self.rList is None: - if self.debug: 'DirectiveList is None, no rules to call!' + if self.dList is None: + if self.debug: 'DirectiveList is None, no directives to call!' return - rules = ['initialize', 'endIter', 'finish'] - assert ruleType in rules, 'Directive type must be in ["%s"]' % '", "'.join(rules) - for r in self.rList: + directives = ['initialize', 'endIter', 'finish'] + assert ruleType in directives, 'Directive type must be in ["%s"]' % '", "'.join(directives) + for r in self.dList: getattr(r, ruleType)() diff --git a/SimPEG/Inversion.py b/SimPEG/Inversion.py index 3d96b4b4..bae18bb6 100644 --- a/SimPEG/Inversion.py +++ b/SimPEG/Inversion.py @@ -17,16 +17,16 @@ class BaseInversion(object): counter = None #: Set this to a SimPEG.Utils.Counter() if you want to count things @property - def ruleList(self): - if getattr(self,'_ruleList', None) is None: - self._ruleList = Directives.DirectiveList(inversion=self) - return self._ruleList + def directiveList(self): + if getattr(self,'_directiveList', None) is None: + self._directiveList = Directives.DirectiveList(inversion=self) + return self._directiveList - @ruleList.setter - def ruleList(self, value): - assert isinstance(value, Directives.DirectiveList), 'Must be a RuleList' - self._ruleList = value - self._ruleList.inversion = self + @directiveList.setter + def directiveList(self, value): + assert isinstance(value, Directives.DirectiveList), 'Must be a DirectiveList' + self._directiveList = value + self._directiveList.inversion = self def __init__(self, objFunc, opt, **kwargs): Utils.setKwargs(self, **kwargs) @@ -54,11 +54,11 @@ class BaseInversion(object): """ self.objFunc.startup(m0) - self.ruleList.call('initialize') + self.directiveList.call('initialize') self.m = self.opt.minimize(self.objFunc.evalFunction, m0) - self.ruleList.call('finish') + self.directiveList.call('finish') return self.m def _optCallback(self, xt): - self.ruleList.call('endIter') + self.directiveList.call('endIter') diff --git a/SimPEG/Survey.py b/SimPEG/Survey.py index 0d56145f..bc297fcb 100644 --- a/SimPEG/Survey.py +++ b/SimPEG/Survey.py @@ -236,6 +236,10 @@ class Fields(object): allFields = [k for k in self.knownFields] + [a for a in self.aliasFields] assert len(allFields) == len(set(allFields)), 'Aliased fields and Known Fields have overlapping definitions.' + self.startup() + + def startup(self): + pass @property def approxSize(self):