aboutsummaryrefslogtreecommitdiffstats
path: root/astro
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-07-23 16:10:31 +0800
committerAaron LI <aly@aaronly.me>2018-07-23 16:10:31 +0800
commit00dcca590cfe574651bf4fd8724fc93e08bfcff6 (patch)
treed2ac73a1da9553df5b837b49dba97b014583b339 /astro
parent276abb7e6c5213fe4f04f5778b18d65e8054eb05 (diff)
downloadatoolbox-00dcca590cfe574651bf4fd8724fc93e08bfcff6.tar.bz2
astro/fitscube.py: Add 'mul' (multiply) sub-command
Diffstat (limited to 'astro')
-rwxr-xr-xastro/fits/fitscube.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/astro/fits/fitscube.py b/astro/fits/fitscube.py
index 720e169..3eb6999 100755
--- a/astro/fits/fitscube.py
+++ b/astro/fits/fitscube.py
@@ -362,6 +362,31 @@ def cmd_add(args):
print("Saved FITS cube: %s" % args.outfile)
+def cmd_mul(args):
+ """
+ Sub-command: "mul", multiply two or more FITS cubes
+ """
+ if not args.clobber and os.path.exists(args.outfile):
+ raise FileExistsError("output file already exists: %s" % args.outfile)
+ if len(args.infiles) < 2:
+ raise RuntimeError("Two or more input FITS cubes required")
+
+ cube = FITSCube(args.infiles[0])
+ print("Data cube unit: %s" % cube.unit)
+ print("Image/slice size: %dx%d" % (cube.width, cube.height))
+ print("Number of slices: %d" % cube.nslice)
+
+ for f in args.infiles[1:]:
+ cube2 = FITSCube(f)
+ assert (cube.unit, cube.zunit) == (cube2.unit, cube2.zunit)
+ print("Multiplying cube %s ..." % f)
+ cube.data = cube.data * cube2.data
+
+ print("Saving FITS cube ...")
+ cube.write(args.outfile, clobber=args.clobber)
+ print("Saved FITS cube: %s" % args.outfile)
+
+
def cmd_sub(args):
"""
Sub-command: "sub", subtract one FITS cube by another one
@@ -626,6 +651,18 @@ def main():
help="two or more input FITS cubes")
parser_add.set_defaults(func=cmd_add)
+ # sub-command: "multiply"
+ parser_mul = subparsers.add_parser(
+ "mul", aliases=["multiply"],
+ help="multiply one FITS cube by another one")
+ parser_mul.add_argument("-C", "--clobber", action="store_true",
+ help="overwrite existing output file")
+ parser_mul.add_argument("-o", "--outfile", required=True,
+ help="output FITS cube filename")
+ parser_mul.add_argument("-i", "--infiles", nargs="+", required=True,
+ help="two or more input FITS cubes")
+ parser_mul.set_defaults(func=cmd_mul)
+
# sub-command: "subtract"
parser_sub = subparsers.add_parser(
"sub", aliases=["subtract"],