From f50d166f80adcfaaa30a62c1e0b25bfc9d76a2a4 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 21 Feb 2017 20:17:39 +0800 Subject: Move various Python tools from 'scripts/' to 'bin/' --- scripts/renorm_spectrum.py | 75 ---------------------------------------------- 1 file changed, 75 deletions(-) delete mode 100755 scripts/renorm_spectrum.py (limited to 'scripts/renorm_spectrum.py') diff --git a/scripts/renorm_spectrum.py b/scripts/renorm_spectrum.py deleted file mode 100755 index 9a0c110..0000000 --- a/scripts/renorm_spectrum.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2017 Weitian LI -# MIT license - -""" -Renormalize the (background) spectrum by equaling its particle background -flux (e.g., 9.5-12.0 keV) with respect to its corresponding source spectrum. - -The ``BACKSCAL`` keyword of the background spectrum is modified to realize -the above renormalization. -""" - -import sys -import argparse -import subprocess - -from _context import acispy -from acispy.spectrum import Spectrum - - -def renorm_spectrum(specfile, specfile_ref, elow=9500, ehigh=12000): - """ - Modify the ``BACKSCAL`` of ``specfile`` in order to equal its - particle background flux to that of ``specfile_ref``. - - Parameters - ---------- - specfile : str - (background) spectrum to be renormalized/modified. - specfile_ref : str - (source/reference) spectrum - elow, ehigh : float, optional - Lower and upper energy limit of the particle background. - """ - spec = Spectrum(specfile) - spec_ref = Spectrum(specfile_ref) - flux = spec.calc_pb_flux(elow=elow, ehigh=ehigh) - flux_ref = spec_ref.calc_pb_flux(elow=elow, ehigh=ehigh) - bs_old = spec.BACKSCAL - bs_new = bs_old * flux / flux_ref - subprocess.check_call(["punlearn", "dmhedit"]) - subprocess.check_call([ - "dmhedit", "infile=%s" % specfile, - "filelist=none", "operation=add", - "key=BACKSCAL", "value=%s" % bs_new, - "comment='Old BACKSCAL: %s'" % bs_old - ]) - print("%s:BACKSCAL: %f -> %f" % (specfile, bs_old, bs_new), - file=sys.stderr) - - -def main(): - parser = argparse.ArgumentParser( - description="Renormalize background spectrum w.r.t. source spectrum") - 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("-r", "--spec-ref", dest="spec_ref", required=True, - help="Reference (source) spectrum") - parser.add_argument("spec", - help="(background) spectrum to be renormalized") - args = parser.parse_args() - - renorm_spectrum(specfile=args.spec, specfile_ref=args.spec_ref, - elow=args.elow, ehigh=args.ehigh) - - -if __name__ == "__main__": - main() -- cgit v1.2.2