aboutsummaryrefslogtreecommitdiffstats
path: root/astro/fits
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-01-02 14:47:33 +0800
committerAaron LI <aly@aaronly.me>2018-01-02 14:47:33 +0800
commit7d1524b31f33679fe8d8747a0296f7b4b55a8d66 (patch)
tree903cef0120eb293814228bf0a22d4ecc85690efe /astro/fits
parent76725258574c2787702486cc07fa57d801e1e2e5 (diff)
downloadatoolbox-7d1524b31f33679fe8d8747a0296f7b4b55a8d66.tar.bz2
astro/fitsimage.py: "info" command support multiple files
Diffstat (limited to 'astro/fits')
-rwxr-xr-xastro/fits/fitsimage.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/astro/fits/fitsimage.py b/astro/fits/fitsimage.py
index 6238f60..db7030e 100755
--- a/astro/fits/fitsimage.py
+++ b/astro/fits/fitsimage.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (c) Weitian LI <weitian@aaronly.me>
+# Copyright (c) 2017-2018 Weitian LI <weitian@aaronly.me>
# MIT license
#
@@ -159,11 +159,11 @@ class FITSImage:
hdu.writeto(outfile, clobber=clobber)
-def cmd_info(args):
+def show_info(filename, abs_=None, center=None):
"""
- Sub-command: "info", show FITS image information
+ Show FITS image information.
"""
- fimage = FITSImage(args.infile)
+ fimage = FITSImage(filename)
print("Image data shape: {0}".format(fimage.shape))
print("Image size: %dx%d" % (fimage.Nx, fimage.Ny))
print("Data unit: [%s]" % fimage.bunit)
@@ -172,13 +172,13 @@ def cmd_info(args):
print("Pixel size: %.1f [arcsec]" % pixelsize)
print("Field of view: (%.2f, %.2f) [deg]" % fimage.fov)
data = fimage.image
- if args.abs:
+ if abs_:
data = np.abs(data)
- if args.center:
- print("Central box size: %d" % args.center)
+ if center:
+ print("Central box size: %d" % center)
rows, cols = data.shape
rc, cc = rows//2, cols//2
- cs1, cs2 = args.center//2, (args.center+1)//2
+ cs1, cs2 = center//2, (center+1)//2
data = data[(rc-cs1):(rc+cs2), (cc-cs1):(cc+cs2)]
mean = np.mean(data)
median = np.median(data)
@@ -194,6 +194,16 @@ def cmd_info(args):
print("rms: %13.6e (root-mean-squared)" % rms)
+def cmd_info(args):
+ """
+ Sub-command: "info", show FITS image information
+ """
+ for fn in args.files:
+ print(">>> %s <<<" % fn)
+ show_info(fn, abs_=args.abs, center=args.center)
+ print("")
+
+
def cmd_add(args):
"""
Sub-command: "add", add the image by a number or other image(s)
@@ -289,7 +299,7 @@ def main():
help="choose central region of specified size")
parser_info.add_argument("-a", "--abs", dest="abs", action="store_true",
help="take absolute values of image pixels")
- parser_info.add_argument("infile", help="FITS image filename")
+ parser_info.add_argument("files", nargs="+", help="FITS image filename")
parser_info.set_defaults(func=cmd_info)
# sub-command: "add"