Skip to content

Commit

Permalink
CNMFParams.change_params() - Don't use set(), and track unused params…
Browse files Browse the repository at this point in the history
… everywhere
  • Loading branch information
pgunn committed Dec 4, 2023
1 parent e3018c9 commit 92505b1
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions caiman/source_extraction/cnmf/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,21 +1123,24 @@ def change_params(self, params_dict, allow_legacy=True, warn_unused=True, verbos
"""
consumed = {} # Keep track of what parameters in params_dict were used to set something in params
for paramkey in params_dict:
if paramkey in list(self.__dict__.keys()):
self.set(paramkey, params_dict[paramkey], verbose=verbose)
consumed[paramkey] = True
# BEGIN code that we will remove in some future version of caiman
if allow_legacy:
legacy_used = False
for remaining_k in params_dict: # This used to be handled by self.set()
if paramkey in list(self.__dict__.keys()): # Proper pathed part
cat_handle = getattr(self, paramkey)
for k, v in params_dict[paramkey].items():
if k not in cat_handle and warn_unused:
logging.warning(f"In setting CNMFParams, provided key {paramkey}/{k} was not consumed. This is a bug!")
else:
cat_handle[k] = v
# BEGIN code that we will remove in some future version of caiman
elif allow_legacy:
for category in list(self.__dict__.keys()):
cat_handle = getattr(self, category) # Thankfully a read-write handle
if remaining_k in cat_handle: # Is it known?
if paramkey in cat_handle: # Is it known?
legacy_used = True
consumed[remaining_k] = True
cat_handle[remaining_k] = params_dict[remaining_k] # Do the update
if legacy_used:
logging.warning(f"In setting CNMFParams, non-pathed parameters were used; this is deprecated. allow_legacy will default to False, and then will be removed in future versions of Caiman")
consumed[paramkey] = True
cat_handle[paramkey] = params_dict[paramkey] # Do the update
if legacy_used:
logging.warning(f"In setting CNMFParams, non-pathed parameters were used; this is deprecated. allow_legacy will default to False, and then will be removed in future versions of Caiman")

# END
if warn_unused:
for toplevel_k in params_dict:
Expand Down

0 comments on commit 92505b1

Please sign in to comment.