diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-03-04 17:30:28 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-03-04 17:30:28 +0800 |
commit | fd5ba7ad61a8c7c9aad6b3f1404d819ae21085d1 (patch) | |
tree | b2c16fdeaa4b18a81d2d00a2c826e82a030affe8 | |
parent | 6ce0d5aa7c3d9280bde5e5b35606b3b9a56cafc3 (diff) | |
download | chandra-acis-analysis-fd5ba7ad61a8c7c9aad6b3f1404d819ae21085d1.tar.bz2 |
Add 'calc_pb_flux.py' to calculate the particle background
-rwxr-xr-x | bin/calc_pb_flux.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/bin/calc_pb_flux.py b/bin/calc_pb_flux.py new file mode 100755 index 0000000..0d4c5dd --- /dev/null +++ b/bin/calc_pb_flux.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Weitian LI <liweitianux@live.com> +# MIT license + +""" +Calculate the particle background flux (e.g., 9.5-12.0 keV) of the spectra. + +flux = counts / exposure / area +where 'counts' is the total photon counts within the specified energy range; +'area' is the value of the ``BACKSCAL`` stored in the spectrum. +therefore, the output flux has arbitrary unit. +""" + +import argparse + +from _context import acispy +from acispy.spectrum import Spectrum + + +def main(): + parser = argparse.ArgumentParser( + description="Calculate the particle background for spectra") + parser.add_argument("-L", "--energy-low", dest="elow", + type=int, default=9500, + help="lower energy limit of the particle " + + "background [eV] (default: 9500 eV)") + parser.add_argument("-H", "--energy-high", dest="ehigh", + type=int, default=12000, + help="upper energy limit of the particle " + + "background [eV] (default: 12000 eV)") + parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", + help="show verbose information") + parser.add_argument("infile", nargs="+", + help="input spectra") + args = parser.parse_args() + + for f in args.infile: + print("=== %s ===" % f) + spec = Spectrum(f) + flux = spec.calc_pb_flux(elow=args.elow, ehigh=args.ehigh, + verbose=args.verbose) + print("flux = %.5g" % flux) + + +if __name__ == "__main__": + main() |