aboutsummaryrefslogtreecommitdiffstats
path: root/astro/fits/crop_image.py
blob: 9cfa7bfe42194be819abca71cf1c9513cf16c3ce (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
#!/usr/bin/env python3
#
# Copyright (c) 2017 Aaron LI <aly@aaronly.me>
# MIT license
#

"""
Crop out the central region of specified size from the FITS image.
"""

import argparse

from rescale_image import FITSImage


def main():
    parser = argparse.ArgumentParser(
        description="Rescale a FITS image to the desired size/resolution")
    parser.add_argument("-C", "--clobber", action="store_true",
                        help="overwrite existing output file")
    parser.add_argument("-s", "--size", type=float, required=True,
                        help="central crop box size [deg]")
    parser.add_argument("-i", "--infile", required=True,
                        help="input FITS image")
    parser.add_argument("-o", "--outfile", required=True,
                        help="output cropped FITS image")
    args = parser.parse_args()

    fitsimage = FITSImage(args.infile)
    fitsimage.crop(size=args.size)
    fitsimage.write(args.outfile, clobber=args.clobber)


if __name__ == "__main__":
    main()