aboutsummaryrefslogtreecommitdiffstats
path: root/astro
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2018-12-08 21:50:38 +0800
committerAaron LI <aly@aaronly.me>2018-12-08 21:50:38 +0800
commit210a7194b89834a8a97a0c39bb24be5a630d112d (patch)
tree345590ccc68e9413c5ae942362ae23099a0057cd /astro
parentd79e35072207450de8e49fe0e75d21fa3be37c93 (diff)
downloadatoolbox-210a7194b89834a8a97a0c39bb24be5a630d112d.tar.bz2
astro/fitscube.py: Add sub-command "d2f" (double to float)
Diffstat (limited to 'astro')
-rwxr-xr-xastro/fitscube.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/astro/fitscube.py b/astro/fitscube.py
index 5a1d3c3..c005e44 100755
--- a/astro/fitscube.py
+++ b/astro/fitscube.py
@@ -587,6 +587,21 @@ def cmd_pool(args):
print("Pooled FITS cube wrote to: %s" % args.outfile)
+def cmd_d2f(args):
+ """
+ Sub-command: "d2f", convert data type from double to float(32).
+ """
+ if not args.clobber and os.path.exists(args.outfile):
+ raise OSError("output file already exists: %s" % args.outfile)
+
+ cube = FITSCube(args.infile)
+ print("Data type: %s" % cube.data.dtype)
+ print("Converting to float(32) ...")
+ cube.data = cube.data.astype(np.float32)
+ cube.write(args.outfile, clobber=args.clobber)
+ print("FITS cube wrote to: %s" % args.outfile)
+
+
def main():
parser = argparse.ArgumentParser(
description="FITS image cube manipulation tool")
@@ -785,6 +800,18 @@ def main():
help="down-sampling method (default: mean)")
parser_pool.set_defaults(func=cmd_pool)
+ # 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 cube filename")
+ parser_d2f.add_argument("-o", "--outfile", required=True,
+ help="output converted FITS cube")
+ parser_d2f.set_defaults(func=cmd_d2f)
+
args = parser.parse_args()
args.func(args)