aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-12-08 21:50:48 +0800
committerAaron LI <aly@aaronly.me>2018-12-08 21:50:48 +0800
commit66ee073f818254c9d976f9c71b568dafc157f9e0 (patch)
tree7a2b963cf3d9f07fd53fb635b6ef29d5fa532306
parent210a7194b89834a8a97a0c39bb24be5a630d112d (diff)
downloadatoolbox-66ee073f818254c9d976f9c71b568dafc157f9e0.tar.bz2
astro/fitsimage.py: Add sub-command "d2f" (double to float)
-rwxr-xr-xastro/fitsimage.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/astro/fitsimage.py b/astro/fitsimage.py
index 620373b..61be6da 100755
--- a/astro/fitsimage.py
+++ b/astro/fitsimage.py
@@ -386,6 +386,18 @@ def cmd_shift(args):
print("Saved shifted FITS image to: %s" % args.outfile)
+def cmd_d2f(args):
+ """
+ Sub-command: "d2f", convert data type from double to float(32).
+ """
+ fimage = FITSImage(args.infile)
+ print("Data type: %s" % fimage.data.dtype)
+ print("Converting to float(32) ...")
+ fimage.data = fimage.data.astype(np.float32)
+ fimage.write(args.outfile, clobber=args.clobber)
+ print("Saved FITS image to: %s" % args.outfile)
+
+
def main():
parser = argparse.ArgumentParser(
description="FITS image manipulation tool")
@@ -552,6 +564,18 @@ def main():
help="numer of vertical pixels")
parser_sft.set_defaults(func=cmd_shift)
+ # sub-command: "d2f"
+ parser_d2f = subparsers.add_parser(
+ "d2f",
+ help="convert data type from double to float(32)")
+ parser_d2f.add_argument("-C", "--clobber", action="store_true",
+ help="overwrite existing output file")
+ parser_d2f.add_argument("-i", "--infile", required=True,
+ help="input FITS image")
+ parser_d2f.add_argument("-o", "--outfile", required=True,
+ help="output converted FITS image")
+ parser_d2f.set_defaults(func=cmd_d2f)
+
args = parser.parse_args()
args.func(args)