aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-10-04 21:18:47 +0800
committerAaron LI <aaronly.me@outlook.com>2016-10-04 21:22:26 +0800
commitc3e2d564023c30271edbd7651ee3bd07e53ab9d8 (patch)
tree0b888000e37863c9570ee96027f7b8049ffe3ef5 /bin
parent085cb258fccb039180e52c8934451673d68e963f (diff)
downloadfg21sim-c3e2d564023c30271edbd7651ee3bd07e53ab9d8.tar.bz2
Add bin/fg21sim and some updates to galactic/synchrotron
* Add new executable "bin/fg21sim" * galactic/synchrotron: update to use "configs.get_path()" * galactic/synchrotron: create output dir if not exists * galactic/synchrotron: add logging support * galactic/synchrotron: append FITS extension to filename * galactic/synchrotron: pass the basic test TODO: * "output()" needs fixes with the FITS header
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fg21sim67
1 files changed, 67 insertions, 0 deletions
diff --git a/bin/fg21sim b/bin/fg21sim
new file mode 100755
index 0000000..8098ac3
--- /dev/null
+++ b/bin/fg21sim
@@ -0,0 +1,67 @@
+#!/usr/bin/env python3
+# -*- mode: python -*-
+#
+# Copyright (c) 2016 Weitian LI <liweitianux@live.com>
+# MIT license
+
+"""
+Simulate the low-frequency radio foregrounds for the 21cm EoR signal.
+"""
+
+import os
+import sys
+import argparse
+import logging
+
+import numpy as np
+
+from fg21sim.configs import configs, validate_configs
+from fg21sim.utils import setup_logging
+from fg21sim.galactic import Synchrotron as GalacticSynchrotron
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Simulate the radio foregrounds for 21cm EoR signal")
+ parser.add_argument("config", help="user configuration file")
+ parser.add_argument("-l", "--log", dest="loglevel", default=None,
+ choices=["DEBUG", "INFO", "WARNING",
+ "ERROR", "CRITICAL"],
+ help="set the log level")
+ parser.add_argument("-L", "--logfile", default=None,
+ help="filename where to save the log messages")
+ parser.add_argument("-Q", "--quiet", action="store_true",
+ help="be quiet so do not log messages to screen")
+ args = parser.parse_args()
+
+ configs.read_userconfig(args.config)
+ validate_configs(configs)
+
+ if args.quiet:
+ log_stream = ""
+ else:
+ log_stream = None
+
+ setup_logging(dict_config=configs.logging,
+ level=args.loglevel,
+ stream=log_stream,
+ logfile=args.logfile)
+ tool = os.path.basename(sys.argv[0])
+ logger = logging.getLogger(tool)
+ logger.info("COMMAND: {0}".format(" ".join(sys.argv)))
+
+ frequencies = np.array(configs.frequencies, ndmin=1)
+ freq_unit = configs.getn("frequency/unit")
+ logger.info("Simulation frequencies: "
+ "{min:.2f} - {max:.2f} {unit} (#{num:d})".format(
+ min=frequencies.min(), max=frequencies.max(),
+ num=len(frequencies), unit=freq_unit))
+
+ logger.info("Simulating the Galactic synchrotron foreground ...")
+ gsynchrotron = GalacticSynchrotron(configs)
+ map_gsync = gsynchrotron.simulate(frequencies)
+ logger.info("Done simulate Galactic synchrotron foreground!")
+
+
+if __name__ == "__main__":
+ main()