From 7613d39f5c593957cdb81bc6a9114764ccf066a8 Mon Sep 17 00:00:00 2001 From: Tom Donoghue Date: Sun, 8 Sep 2024 12:35:32 -0400 Subject: [PATCH] consitency updates --- neurodsp/sim/__init__.py | 2 +- neurodsp/sim/params.py | 60 ++++++++++++++++++++++++---------------- neurodsp/sim/update.py | 12 ++++---- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/neurodsp/sim/__init__.py b/neurodsp/sim/__init__.py index c60b84d1..47f3bab3 100644 --- a/neurodsp/sim/__init__.py +++ b/neurodsp/sim/__init__.py @@ -9,4 +9,4 @@ from .cycles import sim_cycle from .transients import sim_synaptic_kernel, sim_action_potential from .combined import sim_combined, sim_peak_oscillation, sim_modulated_signal, sim_combined_peak -from .multi import sim_multiple, sim_across_values, sim_from_sampler +from .multi import sim_multiple, sim_across_values, sim_multi_across_values, sim_from_sampler diff --git a/neurodsp/sim/params.py b/neurodsp/sim/params.py index 6b920aae..b25c1cd3 100644 --- a/neurodsp/sim/params.py +++ b/neurodsp/sim/params.py @@ -200,12 +200,12 @@ def params(self): return {label : {**self.base, **params} for label, params in self._params.items()} - def make_params(self, parameters=None, **kwargs): + def make_params(self, params=None, **kwargs): """Make a simulation parameter definition from given parameters. Parameters ---------- - parameters : dict or list of dict + params : dict or list of dict Parameter definition(s) to create simulation parameter definition. **kwargs Additional keyword arguments to create the simulation definition. @@ -216,23 +216,23 @@ def make_params(self, parameters=None, **kwargs): Parameter definition. """ - return {**self.base, **self._make_params(parameters, **kwargs)} + return {**self.base, **self._make_params(params, **kwargs)} - def register(self, label, parameters=None, **kwargs): + def register(self, label, params=None, **kwargs): """Register a new simulation parameter definition. Parameters ---------- label : str Label to set simulation parameters under in `params`. - parameters : dict or list of dict + params : dict or list of dict Parameter definition(s) to create simulation parameter definition. **kwargs Additional keyword arguments to create the simulation definition. """ - self._params[label] = self._make_params(parameters, **kwargs) + self._params[label] = self._make_params(params, **kwargs) def register_group(self, group, clear=False): @@ -250,8 +250,8 @@ def register_group(self, group, clear=False): if clear: self.clear() - for label, parameters in group.items(): - self.register(label, parameters) + for label, params in group.items(): + self.register(label, params) def update_base(self, n_seconds=False, fs=False): @@ -349,27 +349,39 @@ def copy(self): return deepcopy(self) - def _make_params(self, parameters=None, **kwargs): - """Sub-function for `make_params`.""" + def _make_params(self, params=None, **kwargs): + """Sub-function to make parameter definition. - parameters = {} if not parameters else deepcopy(parameters) + Parameters + ---------- + params : dict or list of dict + Parameter definition(s) to create simulation parameter definition. + **kwargs + Additional keyword arguments to create the simulation definition. + + Returns + ------- + params : dict + Parameter definition. + """ + + params = {} if not params else deepcopy(params) - if isinstance(parameters, list): - comps = [parameters.pop(0)] - kwargs = {**kwargs, **parameters[0]} if parameters else kwargs - params = self._make_combined_params(comps, **kwargs) + if isinstance(params, list): + comps = [params.pop(0)] + kwargs = {**kwargs, **params[0]} if params else kwargs + out_params = self._make_combined_params(comps, **kwargs) else: - params = {**parameters, **kwargs} + out_params = {**params, **kwargs} # If any base parameters were passed in, clear them - for bparam in self.base: - params.pop(bparam, None) + out_params = drop_base_params(out_params) - return params + return out_params def _make_combined_params(self, components, component_variances=None): - """Make parameters for combined simulations, specifying multiple components. + """Sub-function to make parameters for combined simulations, specifying multiple components. Parameters ---------- @@ -384,17 +396,17 @@ def _make_combined_params(self, components, component_variances=None): Parameter definition. """ - parameters = {} + out_params = {} comps = {} for comp in components: comps.update(**deepcopy(comp)) - parameters['components'] = comps + out_params['components'] = comps if component_variances: - parameters['component_variances'] = component_variances + out_params['component_variances'] = component_variances - return parameters + return out_params class SimIters(SimParams): diff --git a/neurodsp/sim/update.py b/neurodsp/sim/update.py index 5b033e0d..0187e0c5 100644 --- a/neurodsp/sim/update.py +++ b/neurodsp/sim/update.py @@ -37,12 +37,12 @@ def base(self): ## PARAM UPDATERS -def param_updater(parameter): +def param_updater(param): """Create a lambda updater function to update a specified parameter. Parameters ---------- - parameter : str + param : str Name of the parameter to update. Returns @@ -51,15 +51,15 @@ def param_updater(parameter): Updater function which can update specified parameter in simulation parameters. """ - return lambda params, value : params.update({parameter : value}) + return lambda params, value : params.update({param : value}) -def component_updater(parameter, component): +def component_updater(param, component): """Create a lambda updater function to update a parameter within a simulation component. Parameters ---------- - parameter : str + param : str Name of the parameter to update. component : str Name of the component to update the parameter within. @@ -70,7 +70,7 @@ def component_updater(parameter, component): Updater function which can update specified parameter in simulation parameters. """ - return lambda params, value : params['components'][component].update({parameter : value}) + return lambda params, value : params['components'][component].update({param : value}) def create_updater(update, component=None):