Skip to content

Commit

Permalink
added kwarg to update_val for verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
samueldmcdermott committed Oct 5, 2023
1 parent 3dce34c commit 35fc94e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion deepcmbsim/camb_power_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ def __init__(self, in_config_obj):
and an update_val method
"""
self.camb_params_to_dict = lambda user_params: in_config_obj.camb_params_to_dict(user_params=user_params)
self.update_val = lambda k, v: in_config_obj.update_val(k, v)

self.CAMBparams = in_config_obj.CAMBparams
self.UserParams = in_config_obj.UserParams

self.update_val = lambda k, v: in_config_obj.update_val(k, v, verbose = self.UserParams["verbose"])

# according to the CAMB documentation, errors affect the last "100 or so" multipoles
self.max_l_use = min(self.UserParams['max_l_use'], noise.max_multipole(self.UserParams['beamfwhm_arcmin']))
self.max_l_calc = int(self.max_l_use + self.UserParams['extra_l'])
Expand Down
11 changes: 7 additions & 4 deletions deepcmbsim/params_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(
self.dict_iterables = self._all_params_dict['USERPARAMS']['ITERABLES'] # make this more easily accessible


def update_val(self, attr, new_val):
def update_val(self, attr, new_val, verbose=True):
"""
updates values in the config_obj
Parameters
Expand All @@ -124,14 +124,17 @@ def update_val(self, attr, new_val):
attr_split = re.split("\.", attr)
if (len(attr_split) == 1) and (hasattr(self.CAMBparams, attr)):
setattr(self.CAMBparams, attr, new_val)
print(f"updated {attr} in CAMBparams")
if verbose:
print(f"updated {attr} in CAMBparams to {new_val}")
elif (len(attr_split) == 2) and (hasattr(getattr(self.CAMBparams, attr_split[0]), attr_split[1])):
setattr(getattr(self.CAMBparams, attr_split[0]), attr_split[1], new_val)
print(f"updated {attr} in CAMBparams")
if verbose:
print(f"updated {attr} in CAMBparams to {new_val}")
elif attr in self._all_params_dict['USERPARAMS']:
self._all_params_dict['USERPARAMS'][attr] = new_val
self.UserParams[attr] = new_val
print(f"updated {attr} in UserParams")
if verbose:
print(f"updated {attr} in UserParams to {new_val}")
else:
print("not a valid attribute")

Expand Down

0 comments on commit 35fc94e

Please sign in to comment.