From fd5ba7ad61a8c7c9aad6b3f1404d819ae21085d1 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 4 Mar 2017 17:30:28 +0800 Subject: Add 'calc_pb_flux.py' to calculate the particle background --- bin/calc_pb_flux.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 bin/calc_pb_flux.py 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 +# 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() -- cgit v1.2.2