aboutsummaryrefslogtreecommitdiffstats
path: root/bin/make-ska1low-model
blob: 7ed99620c5c90cd193fdffbd7f84fd76a4658417 (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
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
# -*- mode: python -*-
#
# Copyright (c) 2017 Weitian LI <weitian@aaronly.me>
# MIT license
#

"""
Make SKA1-low telescope model for OSKAR[1] simulation usage.

[1] OSKAR: https://github.com/OxfordSKA/OSKAR
"""

import os
import sys
import argparse
import logging

from pkg_resources import resource_exists, resource_filename

from fg21sim.share import CONFIGS
from fg21sim.utils import setup_logging
from fg21sim.uvsim import telescope


def main():
    layoutfile = "ska1low.layout.txt"
    layoutfile_required = True
    if resource_exists(telescope.__package__, layoutfile):
        layoutfile = resource_filename(telescope.__package__, layoutfile)
        layoutfile_required = False
    else:
        layoutfile = None

    parser = argparse.ArgumentParser(
        description="Make SKA1-low telescope model for OSKAR")
    parser.add_argument("-d", "--debug", dest="debug", action="store_true",
                        help="show verbose debug information")
    parser.add_argument("-C", "--clobber", dest="clobber",
                        action="store_true",
                        help="overwrite the existing output files")
    parser.add_argument("-p", "--plot", dest="plot",
                        action="store_true",
                        help="make plots for telescope and stations")
    parser.add_argument("-l", "--layout-file", dest="layoutfile",
                        required=layoutfile_required,
                        default=layoutfile,
                        help="SKA1-low layout configuration " +
                        "(default: %s)" % layoutfile)
    parser.add_argument("-o", "--outdir", dest="outdir",
                        required=True,
                        help="output telescope model directory")
    parser.add_argument("--position",
                        help="telescope position on Earth; " +
                        "longitude,latitude [deg]")
    args = parser.parse_args()

    loglevel = "DEBUG" if args.debug else "INFO"
    setup_logging(dict_config=CONFIGS.logging, level=loglevel)
    tool = os.path.basename(sys.argv[0])
    logger = logging.getLogger(tool)
    logger.info("COMMAND: {0}".format(" ".join(sys.argv)))

    position = None
    if args.position:
        position = list(map(float, args.position.split(",")))
        logger.info("Telescope position: (%f, %f) [deg]" % tuple(position))
    ska1low = telescope.SKA1Low(args.layoutfile, position=position)
    ska1low.generate_stations()
    ska1low.make_oskar_model(args.outdir, clobber=args.clobber)
    if args.plot:
        ska1low.plot_telescope(outdir=args.outdir)
        ska1low.plot_stations(outdir=args.outdir)


if __name__ == "__main__":
    main()