summaryrefslogtreecommitdiffstats
path: root/info.py
blob: 14d5fd159e8539c9124d8b6908cc56495da8524f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
# Aaron LI
# Created: 2016-05-04
# Updated: 2016-05-04
#

"""
module to process the INFO.json file, contains some handy functions
to extract the needed information.
"""

import json


def load_info(info):
    """
    Load data from the INFO.json if necessary.
    """
    if isinstance(info, str):
        json_str = open(info).read().rstrip().rstrip(",")
        return json.loads(json_str)
    else:
        # assuming that the provided `info` is already a Python dictionary
        return info


def get_r500(info):
    """
    Get the R500 value (in unit pixel and kpc), as well as its errors.

    Arguments:
      * info: filename of the INFO.json, or the info dictionary

    Return:
      a dictionary contains the necessary results
    """
    info = load_info(info)

    if "IN_SAMPLE" in info.keys():
        # ZZH's INFO
        r500_kpc = float(info["R500"])
        r500EL_kpc = float(info["R500_err_lower"])
        r500EU_kpc = float(info["R500_err_upper"])
    else:
        # LWT's INFO
        r500_kpc = float(info["R500 (kpc)"])
        r500EL_kpc = float(info["R500_err_lower (1sigma)"])
        r500EU_kpc = float(info["R500_err_upper (1sigma)"])

    # Convert kpc to Chandra ACIS pixel
    rmax_sbp_pix = float(info["Rmax_SBP (pixel)"])
    rmax_sbp_kpc = float(info["Rmax_SBP (kpc)"])
    kpc_per_pix = rmax_sbp_kpc / rmax_sbp_pix
    r500_pix = r500_kpc / kpc_per_pix
    r500EL_pix = r500EL_kpc / kpc_per_pix
    r500EU_pix = r500EU_kpc / kpc_per_pix

    results = {
            "r500_kpc":    r500_kpc,
            "r500EL_kpc":  r500EL_kpc,
            "r500EU_kpc":  r500EU_kpc,
            "r500_pix":    r500_pix,
            "r500EL_pix":  r500EL_pix,
            "r500EU_pix":  r500EU_pix,
            "kpc_per_pix": kpc_per_pix,
    }
    return results