Skip to content

Commit

Permalink
add drop_base_params helper func
Browse files Browse the repository at this point in the history
  • Loading branch information
TomDonoghue committed Aug 19, 2024
1 parent cd45e0f commit 260188f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions neurodsp/sim/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
###################################################################################################
###################################################################################################

BASE_PARAMS = ['n_seconds', 'fs']

class SimParams():
"""Object for managing simulation parameters.
Expand Down Expand Up @@ -613,3 +615,22 @@ def clear(self, clear_samplers=True, clear_params=False, clear_base=False):

if clear_params:
super().clear(clear_base=clear_base)

Check warning on line 617 in neurodsp/sim/params.py

View check run for this annotation

Codecov / codecov/patch

neurodsp/sim/params.py#L617

Added line #L617 was not covered by tests


## Utilities for helping with parameter management

def drop_base_params(params):
"""Drop base parameters from a parameter definition.
Parameters
----------
params : dict
Parameter definition.
Returns
-------
params : dict
Parameter definition, exluding base parameters.
"""

return {key : value for key, value in params.items() if key not in BASE_PARAMS}
8 changes: 8 additions & 0 deletions neurodsp/tests/sim/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ def test_sim_samplers_upd(tsim_samplers):

tsim_samplers.update_sampler('samp_exp', 'n_samples', 100)
assert tsim_samplers['samp_exp'].n_samples == 100

def test_drop_base_params():

params = {'n_seconds' : 2, 'fs' : 250, 'exponent' : -1}
out1 = drop_base_params(params)
for bparam in BASE_PARAMS:
assert bparam not in out1
assert 'exponent' in params

0 comments on commit 260188f

Please sign in to comment.