aboutsummaryrefslogtreecommitdiffstats
path: root/astro/fits/fitsimgadd.py
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2017-12-05 22:55:43 +0800
committerAaron LI <aly@aaronly.me>2017-12-05 22:55:43 +0800
commitbe6297a655249cf963b7a50e65ed0881833de806 (patch)
tree5872df5bbba2b5d8d5062a0cbff251b5fd0998ba /astro/fits/fitsimgadd.py
parent09805bcdb9a948d434893e24fcbe515dc4ef5d2a (diff)
downloadatoolbox-be6297a655249cf963b7a50e65ed0881833de806.tar.bz2
Add astro/fitsimage.py: FITS image manipulation tool
Replace fitsimgadd.py and fitsimgsub.py
Diffstat (limited to 'astro/fits/fitsimgadd.py')
-rwxr-xr-xastro/fits/fitsimgadd.py57
1 files changed, 0 insertions, 57 deletions
diff --git a/astro/fits/fitsimgadd.py b/astro/fits/fitsimgadd.py
deleted file mode 100755
index 52afb95..0000000
--- a/astro/fits/fitsimgadd.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright (c) Weitian LI <weitian@aaronly.me>
-# MIT license
-#
-
-"""
-Add multiple FITS images of same shape.
-"""
-
-import os
-import sys
-import argparse
-
-from astropy.io import fits
-
-
-def main():
- parser = argparse.ArgumentParser(
- description="Add two or more FITS images of same shape")
- parser.add_argument("-C", "--clobber", action="store_true",
- help="overwrite existing files")
- parser.add_argument("-i", "--infile", nargs="+",
- help=">=2 FITS images to be added")
- parser.add_argument("-o", "--outfile", required=True,
- help="filename of added FITS image")
- args = parser.parse_args()
-
- nimg = len(args.infile)
- if nimg < 2:
- raise RuntimeError("more than 2 input FITS images required")
-
- if os.path.exists(args.outfile):
- if args.clobber:
- os.remove(args.outfile)
- print("WARNING: removed existing output file: %s" % args.outfile)
- else:
- raise OSError("output file already exists: %s" % args.outfile)
-
- with fits.open(args.infile[0]) as f:
- image = f[0].data
- header = f[0].header
- print("Opened 1st image: %s" % args.infile[0])
- print("Image shape: %s" % str(list(reversed(image.shape))))
-
- for fn in args.infile[1:]:
- print("Adding FITS image: %s ..." % fn)
- image += fits.open(fn)[0].data
-
- header.add_history(" ".join(sys.argv))
- hdu = fits.PrimaryHDU(data=image, header=header)
- hdu.writeto(args.outfile)
- print("Wrote added FITS image to: %s" % args.outfile)
-
-
-if __name__ == "__main__":
- main()