aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/fg21sim-download-data10
-rwxr-xr-xbin/healpix2hpx30
-rwxr-xr-xbin/hpx2healpix30
3 files changed, 64 insertions, 6 deletions
diff --git a/bin/fg21sim-download-data b/bin/fg21sim-download-data
new file mode 100755
index 0000000..db432f0
--- /dev/null
+++ b/bin/fg21sim-download-data
@@ -0,0 +1,10 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2016 Weitian LI <liweitianux@live.com>
+# MIT license
+
+"""
+Download the required data (e.g., template maps) for simulations.
+"""
+
+raise NotImplementedError("TODO")
diff --git a/bin/healpix2hpx b/bin/healpix2hpx
index 9887bc6..f90c637 100755
--- a/bin/healpix2hpx
+++ b/bin/healpix2hpx
@@ -11,12 +11,14 @@ Reorganize the sky map in HEALPix table format into image in HPX projection.
import os
import sys
import argparse
+import logging
import numpy as np
from astropy.io import fits
import fg21sim
-from fg21sim.utils import healpix2hpx
+from fg21sim.configs import configs
+from fg21sim.utils import healpix2hpx, setup_logging
def main():
@@ -28,16 +30,36 @@ def main():
help="overwrite the existing output file")
parser.add_argument("-F", "--float", action="store_true",
help="use float (single precision) instead of double")
+ parser.add_argument("-l", "--log", dest="loglevel", default=None,
+ help="log level (valid values: "
+ "DEBUG, INFO, WARNING, ERROR, CRITICAL)")
+ 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()
+ if args.quiet:
+ log_stream = ""
+ else:
+ log_stream = None
+
tool = os.path.basename(sys.argv[0])
+ pkgname = fg21sim.__pkgname__
+
+ setup_logging(dict_config=configs.logging,
+ level=args.loglevel,
+ stream=log_stream,
+ logfile=args.logfile)
+ logger = logging.getLogger(tool)
+ logger.info("COMMAND: {0}".format(" ".join(sys.argv)))
+
history = [
"TOOL: {0}".format(tool),
"PARAM: {0}".format(" ".join(sys.argv[1:])),
]
comments = [
- 'Tool "{0}" is part of the "{1}" package'.format(tool,
- fg21sim.__title__),
+ 'Tool "{0}" is part of the "{1}" package'.format(tool, pkgname),
'distributed under {0} license.'.format(fg21sim.__license__),
'See also {0}'.format(fg21sim.__url__)
]
@@ -46,9 +68,11 @@ def main():
append_history=history,
append_comment=comments)
if args.float:
+ logger.info("HPX FITS images: use single-precision float numbers")
hpx_data = hpx_data.astype(np.float32)
hdu = fits.PrimaryHDU(data=hpx_data, header=hpx_header)
hdu.writeto(args.outfile, clobber=args.clobber, checksum=True)
+ logger.info("HPX FITS images write to: %s" % args.outfile)
if __name__ == "__main__":
diff --git a/bin/hpx2healpix b/bin/hpx2healpix
index 6f83426..c9a916c 100755
--- a/bin/hpx2healpix
+++ b/bin/hpx2healpix
@@ -11,12 +11,14 @@ i.e., the reverse of `healpix2hpx.py`.
import os
import sys
import argparse
+import logging
import numpy as np
from astropy.io import fits
import fg21sim
-from fg21sim.utils import hpx2healpix
+from fg21sim.configs import configs
+from fg21sim.utils import hpx2healpix, setup_logging
# Reference:
@@ -39,16 +41,36 @@ def main():
help="overwrite the existing output file")
parser.add_argument("-F", "--float", action="store_true",
help="use float (single precision) instead of double")
+ parser.add_argument("-l", "--log", dest="loglevel", default=None,
+ help="log level (valid values: "
+ "DEBUG, INFO, WARNING, ERROR, CRITICAL)")
+ 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()
+ if args.quiet:
+ log_stream = ""
+ else:
+ log_stream = None
+
tool = os.path.basename(sys.argv[0])
+ pkgname = fg21sim.__pkgname__
+
+ setup_logging(dict_config=configs.logging,
+ level=args.loglevel,
+ stream=log_stream,
+ logfile=args.logfile)
+ logger = logging.getLogger(tool)
+ logger.info("COMMAND: {0}".format(" ".join(sys.argv)))
+
history = [
"TOOL: {0}".format(tool),
"PARAM: {0}".format(" ".join(sys.argv[1:])),
]
comments = [
- 'Tool "{0}" is part of the "{1}" package'.format(tool,
- fg21sim.__title__),
+ 'Tool "{0}" is part of the "{1}" package'.format(tool, pkgname),
'distributed under {0} license.'.format(fg21sim.__license__),
'See also {0}'.format(fg21sim.__url__)
]
@@ -57,12 +79,14 @@ def main():
append_history=history,
append_comment=comments)
if args.float:
+ logger.info("HEALPix data: use single-precision float numbers")
hp_data = hp_data.astype(np.float32)
hdu = fits.BinTableHDU.from_columns([
fits.Column(name="I", array=hp_data,
format=FITS_COLUMN_FORMATS.get(hp_data.dtype))
], header=hp_header)
hdu.writeto(args.outfile, clobber=args.clobber, checksum=True)
+ logger.info("HEALPix data write to FITS file: %s" % args.outfile)
if __name__ == "__main__":