From 1a8e01791f64591e3cd01621bfd9577e4ff864e8 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 17 Jan 2018 00:32:27 +0800 Subject: Move radec.py to astro directory --- astro/radec.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bin/radec.py | 57 --------------------------------------------------------- 2 files changed, 57 insertions(+), 57 deletions(-) create mode 100755 astro/radec.py delete mode 100755 bin/radec.py diff --git a/astro/radec.py b/astro/radec.py new file mode 100755 index 0000000..4cc2b71 --- /dev/null +++ b/astro/radec.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Aaron LI +# MIT License +# + +""" +Convert among various (R.A., Dec.) coordinate formats. +""" + +import argparse + +from astropy import units as au +from astropy.coordinates import Angle + + +def parse_coord(c): + if len(c) == 6: + # h m s d m s + ra = Angle((float(c[0]), float(c[1]), float(c[2])), unit=au.hourangle) + dec = Angle((float(c[3]), float(c[4]), float(c[5])), unit=au.deg) + elif len(c) == 2: + ra = Angle(float(c[0]), unit=au.deg) + dec = Angle(float(c[1]), unit=au.deg) + else: + raise ValueError("invalid coordinate: {0}".format(c)) + return (ra, dec) + + +def main(): + parser = argparse.ArgumentParser( + description="Convert among multiple coordinate formats") + parser.add_argument("coord", nargs="+") + args = parser.parse_args() + + ra, dec = parse_coord(args.coord) + info = ( + "%-14s %-14s\n" % ("R.A.", "Dec.") + + "%s--%s\n" % ("-"*14, "-"*14) + + "%-14.3f %-+14.3f\n" % (ra.deg, dec.deg) + + "%-14s %-14s\n" % ( + ra.to_string(unit=au.hourangle, precision=4), + dec.to_string(unit=au.deg, alwayssign=True, precision=3)) + + "%-14s %-14s\n" % ( + ra.to_string(unit=au.hourangle, sep=":", precision=4), + dec.to_string(unit=au.deg, alwayssign=True, + sep=":", precision=3)) + + "%-14s %-14s\n" % ( + ra.to_string(unit=au.hourangle, sep=" ", precision=4), + dec.to_string(unit=au.deg, alwayssign=True, + sep=" ", precision=3)) + ) + print(info) + + +if __name__ == "__main__": + main() diff --git a/bin/radec.py b/bin/radec.py deleted file mode 100755 index 4cc2b71..0000000 --- a/bin/radec.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (c) 2017 Aaron LI -# MIT License -# - -""" -Convert among various (R.A., Dec.) coordinate formats. -""" - -import argparse - -from astropy import units as au -from astropy.coordinates import Angle - - -def parse_coord(c): - if len(c) == 6: - # h m s d m s - ra = Angle((float(c[0]), float(c[1]), float(c[2])), unit=au.hourangle) - dec = Angle((float(c[3]), float(c[4]), float(c[5])), unit=au.deg) - elif len(c) == 2: - ra = Angle(float(c[0]), unit=au.deg) - dec = Angle(float(c[1]), unit=au.deg) - else: - raise ValueError("invalid coordinate: {0}".format(c)) - return (ra, dec) - - -def main(): - parser = argparse.ArgumentParser( - description="Convert among multiple coordinate formats") - parser.add_argument("coord", nargs="+") - args = parser.parse_args() - - ra, dec = parse_coord(args.coord) - info = ( - "%-14s %-14s\n" % ("R.A.", "Dec.") + - "%s--%s\n" % ("-"*14, "-"*14) + - "%-14.3f %-+14.3f\n" % (ra.deg, dec.deg) + - "%-14s %-14s\n" % ( - ra.to_string(unit=au.hourangle, precision=4), - dec.to_string(unit=au.deg, alwayssign=True, precision=3)) + - "%-14s %-14s\n" % ( - ra.to_string(unit=au.hourangle, sep=":", precision=4), - dec.to_string(unit=au.deg, alwayssign=True, - sep=":", precision=3)) + - "%-14s %-14s\n" % ( - ra.to_string(unit=au.hourangle, sep=" ", precision=4), - dec.to_string(unit=au.deg, alwayssign=True, - sep=" ", precision=3)) - ) - print(info) - - -if __name__ == "__main__": - main() -- cgit v1.2.2