From 66ee073f818254c9d976f9c71b568dafc157f9e0 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 8 Dec 2018 21:50:48 +0800 Subject: astro/fitsimage.py: Add sub-command "d2f" (double to float) --- astro/fitsimage.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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) -- cgit v1.2.2