From 02d9b9bc2263d4eabee8a07bbf8c7606255fa761 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 16 May 2017 14:21:58 +0800 Subject: configs: Use separate section "foregrounds" to config components Also update copyright information. --- fg21sim/configs/00-general.conf.spec | 31 +++++++++++++++------------ fg21sim/configs/checkers.py | 41 +++++++++++++++++++++++------------- fg21sim/configs/manager.py | 18 +++++++++++++++- 3 files changed, 61 insertions(+), 29 deletions(-) (limited to 'fg21sim/configs') diff --git a/fg21sim/configs/00-general.conf.spec b/fg21sim/configs/00-general.conf.spec index 4779f6c..aa2a29a 100644 --- a/fg21sim/configs/00-general.conf.spec +++ b/fg21sim/configs/00-general.conf.spec @@ -19,19 +19,24 @@ nside = integer(min=1, default=1024) lmin = integer(min=0, default=10) lmax = integer(min=1, default=3071) -# List of foreground components to be simulated: -# + galactic/synchrotron: -# Diffuse Galactic synchrotron emission (unpolarized) -# + galactic/freefree: -# Diffuse Galactic free-free emission -# + galactic/snr: -# Galactic supernova remnants emission -# + extragalactic/clusters: -# Extragalactic clusters of galaxies emission -# + extragalactic/pointsources: -# Emission from multiple types of extragalactic point sources -# NOTE: This component is not well integrated and tested at the moment -components = force_list(default=list("galactic/synchrotron", "galactic/freefree", "galactic/snr", "extragalactic/clusters")) + +# Foreground components to be simulated +[foregrounds] +# Diffuse Galactic synchrotron emission (unpolarized) +galactic/synchrotron = boolean(default=True) + +# Diffuse Galactic free-free emission +galactic/freefree = boolean(default=True) + +# Galactic supernova remnants emission +galactic/snr = boolean(default=True) + +# Extragalactic clusters of galaxies emission +extragalactic/clusters = boolean(default=True) + +# Emission from multiple types of extragalactic point sources +# NOTE: This component is not well integrated and tested at the moment +extragalactic/pointsources = boolean(default=False) # Frequencies specification of the simulation products diff --git a/fg21sim/configs/checkers.py b/fg21sim/configs/checkers.py index 7bbcdd7..74d61e3 100644 --- a/fg21sim/configs/checkers.py +++ b/fg21sim/configs/checkers.py @@ -101,26 +101,37 @@ def check_output(configs): def check_galactic_synchrotron(configs): """Check the "[galactic][synchrotron]" section of the configurations.""" comp = "galactic/synchrotron" - comp_enabled = configs.getn("common/components") + comp_enabled = configs.foregrounds[0] + if comp not in comp_enabled: + return {} + results = {} - if comp in comp_enabled: - # Only validate the configs if this component is enabled - results.update( - _check_missing(configs, [comp+"/template_freq", - comp+"/template_unit"]) - ) - results.update( - _check_existence(configs, [comp+"/template", comp+"/indexmap"]) - ) - if configs.getn(comp+"/save"): - results.update(_check_missing(configs, comp+"/output_dir")) + # Only validate the configs if this component is enabled + results.update( + _check_missing(configs, [comp+"/template_freq", + comp+"/template_unit"]) + ) + results.update( + _check_existence(configs, [comp+"/template", comp+"/indexmap"]) + ) + if configs.getn(comp+"/add_smallscales"): + # "lmax" must be greater than "lmin" + key = comp + "/lmax" + res = _check_missing(configs, [key, comp+"/lmin"]) + if res == {}: + if configs.getn(key) <= configs.getn(comp+"/lmin"): + results[key] = "not greater than 'lmin'" + else: + results.update(res) + if configs.getn(comp+"/save"): + results.update(_check_missing(configs, comp+"/output_dir")) return results def check_galactic_freefree(configs): """Check the "[galactic][freefree]" section of the configurations.""" comp = "galactic/freefree" - comp_enabled = configs.getn("common/components") + comp_enabled = configs.foregrounds[0] results = {} if comp in comp_enabled: # Only validate the configs if this component is enabled @@ -139,7 +150,7 @@ def check_galactic_freefree(configs): def check_galactic_snr(configs): """Check the "[galactic][snr]" section of the configurations.""" comp = "galactic/snr" - comp_enabled = configs.getn("common/components") + comp_enabled = configs.foregrounds[0] results = {} if comp in comp_enabled: # Only validate the configs if this component is enabled @@ -156,7 +167,7 @@ def check_extragalactic_clusters(configs): Check the "[extragalactic][clusters]" section of the configurations. """ comp = "extragalactic/clusters" - comp_enabled = configs.getn("common/components") + comp_enabled = configs.foregrounds[0] results = {} if comp in comp_enabled: # Only validate the configs if this component is enabled diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py index 7818d1c..1cddb75 100644 --- a/fg21sim/configs/manager.py +++ b/fg21sim/configs/manager.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Weitian LI +# Copyright (c) 2016-2017 Weitian LI # MIT license # # References: @@ -454,6 +454,22 @@ class ConfigManager: logger.warning("Cannot convert to absolute path: %s" % path) return os.path.normpath(path) + @property + def foregrounds(self): + """Get all available and enabled foreground components. + + Returns + ------- + enabled : list[str] + Enabled foreground components to be simulated + available : list[str] + All available foreground components + """ + fg = self.get("foregrounds") + avaliable = list(fg.keys()) + enabled = [key for key, value in fg.items() if value] + return (enabled, avaliable) + @property def frequencies(self): """Get or calculate if ``frequency/type = custom`` the frequencies -- cgit v1.2.2