diff --git a/tupak/core/likelihood.py b/tupak/core/likelihood.py index b4bfaace99e47ed9a01868e9f2dae2bd7ebc3ce8..eefa05754f0321068bbb939f2e6db546ffed5016 100644 --- a/tupak/core/likelihood.py +++ b/tupak/core/likelihood.py @@ -1,8 +1,8 @@ from __future__ import division, print_function -import inspect import numpy as np from scipy.special import gammaln +from tupak.core.utils import infer_parameters_from_function class Likelihood(object): @@ -61,7 +61,7 @@ class Analytical1DLikelihood(Likelihood): """ def __init__(self, x, y, func): - parameters = self._infer_parameters_from_function(func) + parameters = infer_parameters_from_function(func) Likelihood.__init__(self, dict.fromkeys(parameters)) self.x = x self.y = y @@ -83,15 +83,6 @@ class Analytical1DLikelihood(Likelihood): """ Makes function_keys read_only """ return self.__function_keys - @staticmethod - def _infer_parameters_from_function(func): - """ Infers the arguments of function (except the first arg which is - assumed to be the dep. variable) - """ - parameters = inspect.getargspec(func).args - parameters.pop(0) - return parameters - @property def n(self): """ The number of data points """ diff --git a/tupak/core/utils.py b/tupak/core/utils.py index f03495fc18be7414e88b223c4210c5e223a1a6f8..82d3af182c1853c515230e9d825863aa676a89da 100644 --- a/tupak/core/utils.py +++ b/tupak/core/utils.py @@ -5,6 +5,7 @@ import numpy as np from math import fmod import argparse import traceback +import inspect logger = logging.getLogger('tupak') @@ -16,6 +17,15 @@ solar_mass = 1.98855 * 1e30 radius_of_earth = 6371 * 1e3 # metres +def infer_parameters_from_function(func): + """ Infers the arguments of function (except the first arg which is + assumed to be the dep. variable) + """ + parameters = inspect.getargspec(func).args + parameters.pop(0) + return parameters + + def get_sampling_frequency(time_series): """ Calculate sampling frequency from a time series diff --git a/tupak/gw/waveform_generator.py b/tupak/gw/waveform_generator.py index fe87dc8acd2cf8a54916b0296050a623b0848cea..88c892abae44137e04bac4941fbd544523f5e521 100644 --- a/tupak/gw/waveform_generator.py +++ b/tupak/gw/waveform_generator.py @@ -1,5 +1,3 @@ -import inspect - from tupak.core import utils import numpy as np @@ -51,6 +49,7 @@ class WaveformGenerator(object): self.start_time = start_time self.frequency_domain_source_model = frequency_domain_source_model self.time_domain_source_model = time_domain_source_model + self.__parameters_from_source_model() self.duration = duration self.sampling_frequency = sampling_frequency self.parameter_conversion = parameter_conversion @@ -205,22 +204,15 @@ class WaveformGenerator(object): @parameters.setter def parameters(self, parameters): - """ Does some introspection into the source_model to figure out the parameters if none are given. - """ - self.__parameters_from_source_model() if isinstance(parameters, dict): for key in parameters.keys(): self.__parameters[key] = parameters[key] def __parameters_from_source_model(self): if self.frequency_domain_source_model is not None: - parameters = inspect.getargspec(self.frequency_domain_source_model).args - parameters.pop(0) - self.__parameters = dict.fromkeys(parameters) + self.__parameters = dict.fromkeys(utils.infer_parameters_from_function(self.frequency_domain_source_model)) elif self.time_domain_source_model is not None: - parameters = inspect.getargspec(self.time_domain_source_model).args - parameters.pop(0) - self.__parameters = dict.fromkeys(parameters) + self.__parameters = dict.fromkeys(utils.infer_parameters_from_function(self.time_domain_source_model)) @property def duration(self):