diff options
Diffstat (limited to 'fg21sim')
-rw-r--r-- | fg21sim/configs/00-general.conf.spec | 151 | ||||
-rw-r--r-- | fg21sim/configs/10-galactic.conf.spec | 89 | ||||
-rw-r--r-- | fg21sim/configs/config.spec (renamed from fg21sim/configs/20-extragalactic.conf.spec) | 238 | ||||
-rw-r--r-- | fg21sim/configs/manager.py | 19 |
4 files changed, 234 insertions, 263 deletions
diff --git a/fg21sim/configs/00-general.conf.spec b/fg21sim/configs/00-general.conf.spec deleted file mode 100644 index 353e2cf..0000000 --- a/fg21sim/configs/00-general.conf.spec +++ /dev/null @@ -1,151 +0,0 @@ -# Configurations for "fg21sim" -# -*- mode: conf -*- -# -# Syntax: `ConfigObj`, https://github.com/DiffSK/configobj -# -# This file contains the general configurations, which control the general -# behaviors, or will be used in other configuration sections. - - -# Foreground components to be simulated -[foregrounds] -# Diffuse Galactic synchrotron emission (unpolarized) -galactic/synchrotron = boolean(default=False) - -# Diffuse Galactic free-free emission -galactic/freefree = boolean(default=False) - -# Galactic supernova remnants emission -galactic/snr = boolean(default=False) - -# Extragalactic clusters of galaxies emission -extragalactic/clusters = boolean(default=False) - -# 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) - - -# Simulation sky/region configurations -[sky] -# Type of the input/output simulation sky -# + patch: -# Input/output sky template is only a (square) patch of the sky. -# The simulated output maps have the same coverage/field as the -# input template, as well as the coordinate projection. -# + healpix: -# Input/output sky template covers (almost) all sky, and stored -# in HEALPix format. The simulated output maps will also be -# all-sky using the HEALPix projection. -type = option("patch", "healpix", default="patch") - - # Configurations for input/output sky patch - [[patch]] - # The (R.A., Dec.) coordinate of the sky patch center - # Unit: [deg] - # (MWA EoR0 field center: (0, -27)) - xcenter = float(default=0.0, min=0.0, max=360.0) - ycenter = float(default=-27.0, min=-90.0, max=90.0) - - # The image dimensions (i.e., number of pixels) of the sky patch, - # along the X (R.A./longitude) and Y (Dec./latitude) axes. - # Default: 1800x1800 => 10x10 [deg^2] (20 arcsec/pixel) - xsize = integer(default=1800, min=1) - ysize = integer(default=1800, min=1) - - # Pixel size [arcsec] - pixelsize = float(default=20.0, min=0.0) - - # Configurations for input/output HEALPix sky - [[healpix]] - # HEALPix Nside value, i.e., pixel resolution - nside = integer(default=1024, min=128) - - -# Frequencies specification of the simulation products -[frequency] -# How to specify the frequencies -# + custom: -# directly specify the frequency values using the "frequencies" config -# + calc: -# calculate the frequency values by "start", "stop", and "step" -type = option("custom", "calc", default="custom") - -# The frequency values to be simulated if above "type" is "custom". -# Unit: [MHz] -frequencies = float_list(default=list()) - -# Parameters to calculate the frequencies -# NOTE: "start" and "stop" frequencies are both inclusive. -# Unit: [MHz] -start = float(default=None, min=0.0) -stop = float(default=None, min=0.0) -step = float(default=None, min=0.0) - - -# Configuration for output products -[output] -# Filename pattern for the output products, which will be finally -# formatted using `str.format()`. -filename_pattern = string(default="{prefix}_{frequency:06.2f}.fits") - -# Use single-precision float instead of double (to save spaces) -float32 = boolean(default=True) - -# Whether to calculate the checksum for the output FITS file? -# NOTE: May cost significantly more time on writing FITS file. -checksum = boolean(default=False) - -# Whether to overwrite existing files (e.g., maps, catalogs, manifest, ...) -clobber = boolean(default=False) - -# Filename of the simulation products manifest (JSON format), which -# records all output products together with their sizes and MD5 hashes. -# Do not create such a manifest if this option is not specified. -manifest = string(default=None) - - -# Cosmological parameters -# References: Komatsu et al. 2011, ApJS, 192, 18; Tab.(1) -[cosmology] -# Hubble constant at z=0; [km/s/Mpc] -H0 = float(default=71.0, min=0.0) -# Density of non-relativistic matter in units of the critical density at z=0 -OmegaM0 = float(default=0.27, min=0.0, max=1.0) -# Density of the baryon at present day -Omegab0 = float(default=0.046, min=0.0, max=1.0) -# Present-day CMB temperature; [K] -Tcmb0 = float(default=2.725) -# Present-day rms density fluctuations on a scale of 8 h^-1 [Mpc] -sigma8 = float(default=0.81, min=0.0) -# Scalar spectral index -ns = float(default=0.96, min=0.0) - - -# Configurations for initialization/reconfiguration of the `logging` module -[logging] -# debug: Detailed information, typically of interest only when diagnosing -# problems. -# info: Confirmation that things are working as expected. -# warning: An indication that something unexpected happended, or indicative -# of some problem in the near future (e.g., "disk space low"). -# The software is still working as expected. -# error: Due to a more serious problem, the software has not been able to -# perform some function. -# critical: A serious error, indicating that the program itself may be unable -# to continue running. -level = option("debug", "info", "warning", "error", "critical", default="info") - -# Set the format of displayed messages -format = string(default="%(asctime)s [%(levelname)s] <%(name)s:%(lineno)d> %(message)s") - -# Set the date/time format in messages -datefmt = string(default="%H:%M:%S") - -# Set the logging filename (will create a `FileHandler`) -# If set to "" (empty string), then the `FileHandler` will be disabled. -filename = string(default="") - -# Set the stream used to initialize the `StreamHandler` -# If set to "" (empty string), then the `StreamHandler` will be disabled. -stream = option("stderr", "stdout", "", default="stderr") diff --git a/fg21sim/configs/10-galactic.conf.spec b/fg21sim/configs/10-galactic.conf.spec deleted file mode 100644 index 9185dc0..0000000 --- a/fg21sim/configs/10-galactic.conf.spec +++ /dev/null @@ -1,89 +0,0 @@ -# Configurations for "fg21sim" -# -*- mode: conf -*- -# -# Syntax: `ConfigObj`, https://github.com/DiffSK/configobj -# -# This file contains the options corresponding the Galactic emission -# components, which currently includes the following components: -# - synchrotron -# - freefree -# - snr - - -[galactic] - - # Synchrotron emission component (unpolarized) - [[synchrotron]] - # The template map for the simulation, e.g., Haslam 408 MHz survey. - # Unit: [K] (Kelvin) - template = string(default=None) - # The frequency of the template map. - # Unit: [MHz] - template_freq = float(default=None, min=0.0) - - # Spectral index map - indexmap = string(default=None) - - # Whether add fluctuations on the small scales according the angular - # power spectrum prediction? - add_smallscales = boolean(default=False) - # Range of multipole moments (l) of the angular power spectrum. - # The power spectrum will be cut off to a constant for multipole l < lmin. - # NOTE: Update the ``lmax`` accordingly w.r.t. ``sky/healpix/nside``. - # Generally, lmax = 3 * nside - 1 - lmin = integer(min=0, default=10) - lmax = integer(min=1, default=3071) - - # Filename prefix for this component - prefix = string(default="gsync") - # Output directory to save the simulated results - output_dir = string(default=None) - - # Free-free bremsstrahlung emission component - [[freefree]] - # The Hα map from which to derive the free-free emission - # Unit: [Rayleigh] - halphamap = string(default=None) - - # The 100-μm dust map used to correct Hα dust absorption - # Unit: [MJy/sr] - dustmap = string(default=None) - - # Effective dust fraction in the LoS actually absorbing Halpha - dust_fraction = float(default=0.33, min=0.1, max=1.0) - - # Halpha absorption threshold: - # When the dust absorption goes rather large, the true Halpha - # absorption can not well determined. This configuration sets the - # threshold below which the dust absorption can be well determined, - # while the sky regions with higher absorption are masked out due - # to unreliable absorption correction. - # Unit: [mag] - halpha_abs_th = float(default=1.0) - - # The electron temperature assumed for the ionized interstellar medium - # that generating H{\alpha} emission. - # Unit: [K] - electron_temperature = float(default=7000.0, min=1000) - - # Filename prefix for this component - prefix = string(default="gfree") - # Output directory to save the simulated results - output_dir = string(default=None) - - # Supernova remnants emission - [[snr]] - # The Galactic SNRs catalog data (CSV file) - catalog = string(default=None) - # Output the effective/inuse SNRs catalog data (CSV file) - catalog_outfile = string(default=None) - - # Resolution for simulating each SNR template, which are finally - # mapped to the all-sky HEALPix map if used. - # Unit: [arcsec] - resolution = float(default=30.0, min=5.0) - - # Filename prefix for this component - prefix = string(default="gsnr") - # Output directory to save the simulated results - output_dir = string(default=None) diff --git a/fg21sim/configs/20-extragalactic.conf.spec b/fg21sim/configs/config.spec index 943c7e0..6b871e4 100644 --- a/fg21sim/configs/20-extragalactic.conf.spec +++ b/fg21sim/configs/config.spec @@ -1,14 +1,240 @@ -# Configurations for "fg21sim" -# -*- mode: conf -*- # +# Configurations for "fg21sim" # Syntax: `ConfigObj`, https://github.com/DiffSK/configobj # -# This file contains the options corresponding the extragalactic emission -# components, which currently includes the following components: -# - clusters: halos -# - pointsources +# Foreground components to be simulated +[foregrounds] +# Diffuse Galactic synchrotron emission (unpolarized) +galactic/synchrotron = boolean(default=False) + +# Diffuse Galactic free-free emission +galactic/freefree = boolean(default=False) + +# Galactic supernova remnants emission +galactic/snr = boolean(default=False) + +# Extragalactic clusters of galaxies emission +extragalactic/clusters = boolean(default=False) + +# 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) + + +# Simulation sky/region configurations +[sky] +# Type of the input/output simulation sky +# + patch: +# Input/output sky template is only a (square) patch of the sky. +# The simulated output maps have the same coverage/field as the +# input template, as well as the coordinate projection. +# + healpix: +# Input/output sky template covers (almost) all sky, and stored +# in HEALPix format. The simulated output maps will also be +# all-sky using the HEALPix projection. +type = option("patch", "healpix", default="patch") + + # Configurations for input/output sky patch + [[patch]] + # The (R.A., Dec.) coordinate of the sky patch center + # Unit: [deg] + # (MWA EoR0 field center: (0, -27)) + xcenter = float(default=0.0, min=0.0, max=360.0) + ycenter = float(default=-27.0, min=-90.0, max=90.0) + + # The image dimensions (i.e., number of pixels) of the sky patch, + # along the X (R.A./longitude) and Y (Dec./latitude) axes. + # Default: 1800x1800 => 10x10 [deg^2] (20 arcsec/pixel) + xsize = integer(default=1800, min=1) + ysize = integer(default=1800, min=1) + + # Pixel size [arcsec] + pixelsize = float(default=20.0, min=0.0) + + # Configurations for input/output HEALPix sky + [[healpix]] + # HEALPix Nside value, i.e., pixel resolution + nside = integer(default=1024, min=128) + + +# Frequencies specification of the simulation products +[frequency] +# How to specify the frequencies +# + custom: +# directly specify the frequency values using the "frequencies" config +# + calc: +# calculate the frequency values by "start", "stop", and "step" +type = option("custom", "calc", default="custom") + +# The frequency values to be simulated if above "type" is "custom". +# Unit: [MHz] +frequencies = float_list(default=list()) + +# Parameters to calculate the frequencies +# NOTE: "start" and "stop" frequencies are both inclusive. +# Unit: [MHz] +start = float(default=None, min=0.0) +stop = float(default=None, min=0.0) +step = float(default=None, min=0.0) + + +# Configuration for output products +[output] +# Filename pattern for the output products, which will be finally +# formatted using `str.format()`. +filename_pattern = string(default="{prefix}_{frequency:06.2f}.fits") + +# Use single-precision float instead of double (to save spaces) +float32 = boolean(default=True) + +# Whether to calculate the checksum for the output FITS file? +# NOTE: May cost significantly more time on writing FITS file. +checksum = boolean(default=False) + +# Whether to overwrite existing files (e.g., maps, catalogs, manifest, ...) +clobber = boolean(default=False) + +# Filename of the simulation products manifest (JSON format), which +# records all output products together with their sizes and MD5 hashes. +# Do not create such a manifest if this option is not specified. +manifest = string(default=None) + + +# Cosmological parameters +# References: Komatsu et al. 2011, ApJS, 192, 18; Tab.(1) +[cosmology] +# Hubble constant at z=0; [km/s/Mpc] +H0 = float(default=71.0, min=0.0) +# Density of non-relativistic matter in units of the critical density at z=0 +OmegaM0 = float(default=0.27, min=0.0, max=1.0) +# Density of the baryon at present day +Omegab0 = float(default=0.046, min=0.0, max=1.0) +# Present-day CMB temperature; [K] +Tcmb0 = float(default=2.725) +# Present-day rms density fluctuations on a scale of 8 h^-1 [Mpc] +sigma8 = float(default=0.81, min=0.0) +# Scalar spectral index +ns = float(default=0.96, min=0.0) + + +# Configurations for initialization/reconfiguration of the `logging` module +[logging] +# debug: Detailed information, typically of interest only when diagnosing +# problems. +# info: Confirmation that things are working as expected. +# warning: An indication that something unexpected happended, or indicative +# of some problem in the near future (e.g., "disk space low"). +# The software is still working as expected. +# error: Due to a more serious problem, the software has not been able to +# perform some function. +# critical: A serious error, indicating that the program itself may be unable +# to continue running. +level = option("debug", "info", "warning", "error", "critical", default="info") + +# Set the format of displayed messages +format = string(default="%(asctime)s [%(levelname)s] <%(name)s:%(lineno)d> %(message)s") + +# Set the date/time format in messages +datefmt = string(default="%H:%M:%S") + +# Set the logging filename (will create a `FileHandler`) +# If set to "" (empty string), then the `FileHandler` will be disabled. +filename = string(default="") + +# Set the stream used to initialize the `StreamHandler` +# If set to "" (empty string), then the `StreamHandler` will be disabled. +stream = option("stderr", "stdout", "", default="stderr") + + +# +# Galactic emission components +# + +[galactic] + + # Synchrotron emission component (unpolarized) + [[synchrotron]] + # The template map for the simulation, e.g., Haslam 408 MHz survey. + # Unit: [K] (Kelvin) + template = string(default=None) + # The frequency of the template map. + # Unit: [MHz] + template_freq = float(default=None, min=0.0) + + # Spectral index map + indexmap = string(default=None) + + # Whether add fluctuations on the small scales according the angular + # power spectrum prediction? + add_smallscales = boolean(default=False) + # Range of multipole moments (l) of the angular power spectrum. + # The power spectrum will be cut off to a constant for multipole l < lmin. + # NOTE: Update the ``lmax`` accordingly w.r.t. ``sky/healpix/nside``. + # Generally, lmax = 3 * nside - 1 + lmin = integer(min=0, default=10) + lmax = integer(min=1, default=3071) + + # Filename prefix for this component + prefix = string(default="gsync") + # Output directory to save the simulated results + output_dir = string(default=None) + + # Free-free bremsstrahlung emission component + [[freefree]] + # The Hα map from which to derive the free-free emission + # Unit: [Rayleigh] + halphamap = string(default=None) + + # The 100-μm dust map used to correct Hα dust absorption + # Unit: [MJy/sr] + dustmap = string(default=None) + + # Effective dust fraction in the LoS actually absorbing Halpha + dust_fraction = float(default=0.33, min=0.1, max=1.0) + + # Halpha absorption threshold: + # When the dust absorption goes rather large, the true Halpha + # absorption can not well determined. This configuration sets the + # threshold below which the dust absorption can be well determined, + # while the sky regions with higher absorption are masked out due + # to unreliable absorption correction. + # Unit: [mag] + halpha_abs_th = float(default=1.0) + + # The electron temperature assumed for the ionized interstellar medium + # that generating H{\alpha} emission. + # Unit: [K] + electron_temperature = float(default=7000.0, min=1000) + + # Filename prefix for this component + prefix = string(default="gfree") + # Output directory to save the simulated results + output_dir = string(default=None) + + # Supernova remnants emission + [[snr]] + # The Galactic SNRs catalog data (CSV file) + catalog = string(default=None) + # Output the effective/inuse SNRs catalog data (CSV file) + catalog_outfile = string(default=None) + + # Resolution for simulating each SNR template, which are finally + # mapped to the all-sky HEALPix map if used. + # Unit: [arcsec] + resolution = float(default=30.0, min=5.0) + + # Filename prefix for this component + prefix = string(default="gsnr") + # Output directory to save the simulated results + output_dir = string(default=None) + + +# +# Extragalactic emission components +# + [extragalactic] # # Press-Schechter formalism to determine the cluster distributions diff --git a/fg21sim/configs/manager.py b/fg21sim/configs/manager.py index e2103da..07f6f77 100644 --- a/fg21sim/configs/manager.py +++ b/fg21sim/configs/manager.py @@ -31,22 +31,6 @@ from ..errors import ConfigError logger = logging.getLogger(__name__) -def _get_configspec(): - """Found and read all the configuration specifications""" - files = sorted(pkg_resources.resource_listdir(__name__, "")) - specfiles = [fn for fn in files if fn.endswith(".conf.spec")] - if os.environ.get("DEBUG_FG21SIM"): - print("DEBUG: Found config specifications: %s" % ", ".join(specfiles), - file=sys.stderr) - # NOTE: - # `resource_string()` returns the resource in *binary/bytes* string - configspec = "\n".join([ - pkg_resources.resource_string(__name__, fn).decode("utf-8") - for fn in specfiles - ]).split("\n") - return configspec - - def _flatten_dict(d, sep="/", parent_key=""): """ Recursively flatten a nested dictionary with keys compressed. @@ -147,7 +131,8 @@ class ConfigManager: If the ``userconfig`` provided, the user configurations is also loaded, validated, and merged. """ - configspec = _get_configspec() + configspec = pkg_resources.resource_string( + __name__, "config.spec").decode("utf-8") self._configspec = ConfigObj(configspec, interpolation=False, list_values=False, _inspec=True, encoding="utf-8") |