From 1e0d443c4c77a8a2cc0ae6e503e8811aca6b3e39 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 4 Oct 2016 14:56:52 +0800 Subject: Fix wrong config syntax and minor changes to ConfigManager --- fg21sim/configs/00-general.conf.spec | 8 ++++---- fg21sim/configs/manager.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/fg21sim/configs/00-general.conf.spec b/fg21sim/configs/00-general.conf.spec index ab36f52..6827a12 100644 --- a/fg21sim/configs/00-general.conf.spec +++ b/fg21sim/configs/00-general.conf.spec @@ -11,15 +11,15 @@ [common] # HEALPix N_side value, i.e., pixel resolution # NOTE: also update "lmax" below. -nside = int(min=1, default=512) +nside = integer(min=1, default=512) # HEALPix ordering scheme ordering = option("RING", "NESTED", default="RING") # Range of multipole monents (l) of the angular power spectrum. # The power spectrum will be cut off to a constant for multipole l < lmin. # Generally, lmax = 3 * nside - 1 -lmin = int(min=0, default=10) -lmax = int(min=1, default=1535) +lmin = integer(min=0, default=10) +lmax = integer(min=1, default=1535) # Directory contains the input data, e.g., component templates # NOTE: This config is mandatory and should be provided by the user. @@ -44,7 +44,7 @@ unit = option("MHz", default="MHz") type = option("custom", "calc", default="custom") # The frequency values to be simulated if above "type" is "custom". -frequencies = force_list(default=float_list(120.0)) +frequencies = float_list(default=list()) # Parameters to calculate the frequencies # start and stop frequency value (both inclusive) diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py index 5987394..fe3c18f 100644 --- a/fg21sim/configs/manager.py +++ b/fg21sim/configs/manager.py @@ -128,13 +128,13 @@ class ConfigManager: """Get config value by key.""" return self._config.get(key, fallback) - def getn(self, keys, sep="/"): + def getn(self, key, sep="/"): """Get the config value from the nested dictionary configs using a list of keys or a "sep"-separated keys strings. Parameters ---------- - keys : str / list[str] + key : str / list[str] List of keys or a string separated by a specific character (e.g., "/") to specify the item in the `self._config`, which is a nested dictionary. @@ -148,21 +148,27 @@ class ConfigManager: - Stackoverflow: Checking a Dictionary using a dot notation string https://stackoverflow.com/q/12414821/4856091 """ - if isinstance(keys, str): - keys = keys.split(sep) - return reduce(dict.get, keys, self._config) + if isinstance(key, str): + key = key.split(sep) + return reduce(dict.get, key, self._config) - def get_path(self, keys): + def get_path(self, key): """Return the absolute path of the file/directory specified by the config keys. + Parameters + ---------- + key : str + "/"-separated string specifying the config name of the + file/directory + NOTE ---- - The "~" (tilde) inside path is expanded to the user home directory. - The relative path (with respect to the user configuration file) is converted to absolute path if `self.userconfig` presents. """ - path = os.path.expanduser(self.getn(keys)) + path = os.path.expanduser(self.getn(key)) if not os.path.isabs(path): # relative path if hasattr(self, "userconfig"): @@ -170,7 +176,7 @@ class ConfigManager: else: # cannot convert to the absolute path logger.warning("Cannot convert to absolute path: %s" % path) - return path + return os.path.normpath(path) @property def frequencies(self): -- cgit v1.2.2