diff options
Diffstat (limited to 'ciao_calc_csb.py')
-rwxr-xr-x | ciao_calc_csb.py | 77 |
1 files changed, 41 insertions, 36 deletions
diff --git a/ciao_calc_csb.py b/ciao_calc_csb.py index 24c130e..0389951 100755 --- a/ciao_calc_csb.py +++ b/ciao_calc_csb.py @@ -11,9 +11,11 @@ # # Aaron LI # Created: 2016-04-28 -# Updated: 2016-04-29 +# Updated: 2016-05-16 # -# Changelog: +# Change log: +# 2016-05-16: +# * PEP8 fixes # 2016-04-29: # * Fix order of executing ds9 and print message # * Fix C_SB calculation @@ -27,7 +29,6 @@ import sys import os import glob -import re import json import argparse import subprocess @@ -65,15 +66,15 @@ def calc_csb(evt, expmap, regfile, r1, r2): # calculate C_SB and error area_ratio = (r2 / r1) ** 2 csb = csb_s_val[0] / csb_s_val[1] / area_ratio - csb_err = csb * ((csb_s_err[0] / csb_s_val[0])**2 + \ + csb_err = csb * ((csb_s_err[0] / csb_s_val[0])**2 + (csb_s_err[1] / csb_s_val[1])**2) ** 0.5 results = OrderedDict([ - ("csb_s1", csb_s_val[0]), - ("csb_s1_err", csb_s_err[0]), - ("csb_s2", csb_s_val[1]), - ("csb_s2_err", csb_s_err[1]), - ("csb", csb), - ("csb_err", csb_err), + ("csb_s1", csb_s_val[0]), + ("csb_s1_err", csb_s_err[0]), + ("csb_s2", csb_s_val[1]), + ("csb_s2_err", csb_s_err[1]), + ("csb", csb), + ("csb_err", csb_err), ]) return results @@ -84,24 +85,29 @@ def main(): # exclusive argument group for C_SB definition grp_csb = parser.add_mutually_exclusive_group(required=True) grp_csb.add_argument("-K", "--kpc", dest="kpc", action="store_true", - help="C_SB = brightness(<=0.048R500) / brightness(<=0.45R500)") + help="C_SB = brightness(<=0.048R500) " + + "/ brightness(<=0.45R500)") grp_csb.add_argument("-R", "--r500", dest="r500", action="store_true", - help="C_SB = brightness(<=40kpc) / brightness(<=400kpc)") + help="C_SB = brightness(<=40kpc) " + + "/ brightness(<=400kpc)") # - parser.add_argument("-A", "--no-ask", dest="no_ask", required=False, - action="store_true", help="do NOT check region and ask") + parser.add_argument("-A", "--no-ask", dest="no_ask", + required=False, action="store_true", + help="do NOT check region and ask") parser.add_argument("-j", "--json", dest="json", required=False, - help="the *_INFO.json file (default: find ../*_INFO.json)") + help="the *_INFO.json file " + + "(default: find ../*_INFO.json)") parser.add_argument("-r", "--region", dest="region", - required=False, default="sbprofile.reg", - help="region from which to extract the center coordinate " + \ - "(default: sbprofile.reg)") + required=False, default="sbprofile.reg", + help="region from which to extract the center " + + "coordinate (default: sbprofile.reg)") parser.add_argument("-i", "--infile", dest="infile", required=True, - help="input energy-filtered EVT2 used to calculate the C_SB") + help="input energy-filtered EVT2 used to " + + "calculate the C_SB") parser.add_argument("-e", "--expmap", dest="expmap", required=True, - help="exposure map of the input image") + help="exposure map of the input image") parser.add_argument("-o", "--outfile", dest="outfile", required=True, - help="output json file to store the C_SB results") + help="output json file to store the C_SB results") # args = parser.parse_args() @@ -113,12 +119,12 @@ def main(): json_str = open(info_json).read().rstrip().rstrip(",") info = json.loads(json_str) - name = info["Source Name"] + name = info["Source Name"] obsid = int(info["Obs. ID"]) - r500 = get_r500(info) - r500_kpc = r500["r500_kpc"] - r500_pix = r500["r500_pix"] + r500 = get_r500(info) + r500_kpc = r500["r500_kpc"] + r500_pix = r500["r500_pix"] kpc_per_pix = r500["kpc_per_pix"] print("R500: %.2f (kpc), %.2f (pixel)" % (r500_kpc, r500_pix)) # get center coordinate @@ -130,7 +136,7 @@ def main(): r2 = 0.450 * r500_pix elif args.kpc: csb_type = "kpc" - r1 = 40.0 / kpc_per_pix + r1 = 40.0 / kpc_per_pix r2 = 400.0 / kpc_per_pix else: raise ValueError("Unknown C_SB definition") @@ -139,9 +145,9 @@ def main(): regfile = os.path.splitext(args.outfile)[0] + ".reg" make_csb_region(regfile, center=(xc, yc), r1=r1, r2=r2) # check region with DS9 - if args.no_ask == False: - print("Check the C_SB regions; overwrite the region file " + \ - "'%s' if modified" % regfile, flush=True, file=sys.stderr) + if not args.no_ask: + print("Check the C_SB regions; overwrite the region file " + + "'%s' if modified" % regfile, flush=True, file=sys.stderr) cmd = "ds9 %s -cmap he " % args.infile + \ "-regions format ciao -regions %s" % regfile subprocess.call(cmd, shell=True) @@ -159,13 +165,13 @@ def main(): # calculate the C_SB csb = calc_csb(args.infile, expmap=args.expmap, - regfile=regfile, r1=r1, r2=r2) + regfile=regfile, r1=r1, r2=r2) csb_data = OrderedDict([ - ("name", name), - ("obsid", obsid), - ("csb_type", csb_type), - ("csb_r1", r1), - ("csb_r2", r2), + ("name", name), + ("obsid", obsid), + ("csb_type", csb_type), + ("csb_r1", r1), + ("csb_r2", r2), ]) csb_data.update(csb) csb_data["csb_region"] = csb_region_note @@ -176,4 +182,3 @@ def main(): if __name__ == "__main__": main() - |