From 5fd287919671026fff9e5bb3cd17b36603c3924f Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins <jrollins@finestructure.net> Date: Thu, 30 Jan 2020 15:30:45 -0800 Subject: [PATCH] nb: simplify BudgetItem freq attirbute access Allows for specifying as a class attribute. --- gwinc/nb.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/gwinc/nb.py b/gwinc/nb.py index 18c09a4d..310db63f 100644 --- a/gwinc/nb.py +++ b/gwinc/nb.py @@ -52,15 +52,21 @@ class BudgetItem: ########## - def __init__(self, freq, **kwargs): + def __init__(self, freq=None, **kwargs): """Initialize budget item. - Primary argument is the evaluation frequency array. Any - keyword arguments provided are simple written as attribute - variables in the initialized object. + The primary argument should be the evaluation frequency array. + If it is not provided, then it is assumed to be a pre-defined + attribute of the BudgetItem class. Any keyword arguments + provided are simple written as attribute variables in the + initialized object. """ - self.__freq = freq + if freq is not None: + assert isinstance(freq, np.ndarray) + self.freq = freq + elif not hasattr(self, 'freq'): + raise AttributeError("Frequency array not provided or defined.") for key, val in kwargs.items(): setattr(self, key, val) @@ -76,11 +82,6 @@ class BudgetItem: self.name, ) - @property - def freq(self): - """Evaluation frequency array supplied at initialization.""" - return self.__freq - def interpolate(self, freq, data): """Interpolate data to the evaluation frequencies. -- GitLab