summaryrefslogtreecommitdiffstats
path: root/make_overdensity_config.py
blob: 7ff0a2fa7863360bc1ce85f871475fb7864ba260 (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
#!/usr/bin/env python3
#
# Make the configuration file for `calc_overdensity.py`
#
# Aaron LI
# Created: 2016-07-13
# Updated: 2016-07-13
#

import glob
import argparse

from info import get_redshift


sample_config = """
## Configuration file for `calc_overdensity.py`

# redshift of the source (critical density)
redshift = %(redshift).6f
"""


def make_config(info):
    cfg_data = {
        "redshift": get_redshift(info),
    }
    cfg = sample_config % cfg_data
    return cfg


def main():
    parser = argparse.ArgumentParser(
        description="Make the config for 'calc_overdensity.py'")
    parser.add_argument("-j", "--json", dest="json", required=False,
                        help="the *_INFO.json file " +
                             "(default: find ../*_INFO.json)")
    parser.add_argument("outfile", nargs="?", default="overdensity.conf",
                        help="filename of the output overdensity config " +
                             "(default: overdensity.conf)")
    args = parser.parse_args()

    # default "*_INFO.json"
    info_json = glob.glob("../*_INFO.json")[0]
    if args.json:
        info_json = args.json

    config = make_config(info_json)
    open(args.outfile, "w").write(config)


if __name__ == "__main__":
    main()