aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/configs
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-07 16:48:48 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-07 19:35:36 +0800
commit2e4b50fe7ac0b405e0e5e3219392d9b06f82b76d (patch)
tree883801d2e73bb03539752db2115238e11a84959c /fg21sim/configs
parent7169442444ee76c4f46dbe5c83cbf31058d74eb4 (diff)
downloadfg21sim-2e4b50fe7ac0b405e0e5e3219392d9b06f82b76d.tar.bz2
configs/checkers.py: Add "check_common()"
Diffstat (limited to 'fg21sim/configs')
-rw-r--r--fg21sim/configs/checkers.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/fg21sim/configs/checkers.py b/fg21sim/configs/checkers.py
index e225234..0788443 100644
--- a/fg21sim/configs/checkers.py
+++ b/fg21sim/configs/checkers.py
@@ -44,6 +44,30 @@ def _check_existence(configs, keys):
return results
+def _is_power2(n):
+ """Check a number whether a power of 2"""
+ # Credit: https://stackoverflow.com/a/29489026/4856091
+ return (n and not (n & (n-1)))
+
+
+def check_common(configs):
+ """Check the "[common]" section of the configurations."""
+ results = {}
+ # "common/nside" must be a power of 2
+ key = "common/nside"
+ if not _is_power2(configs.getn(key)):
+ results[key] = "not a power of 2"
+ # "common/lmax" must be greater than "common/lmin"
+ key = "common/lmax"
+ if configs.getn(key) <= configs.getn("common/lmin"):
+ results[key] = "not greater than 'common/lmin'"
+ # Check enabled components
+ key = "common/components"
+ if len(configs.getn(key)) == 0:
+ results[key] = "no components enabled/selected"
+ return results
+
+
def check_frequency(configs):
"""Check the "[frequency]" section of the configurations."""
results = {}
@@ -121,6 +145,7 @@ def check_galactic_snr(configs):
# Available checkers to validate the configurations
_CHECKERS = [
+ check_common,
check_frequency,
check_output,
check_galactic_synchrotron,