#!/usr/bin/env python

# relative_rv.py

# Script to calculate the relative Radial Velocity between two given wavelengths

# Jason Neal
# December 2016
import argparse

def relative_rv(wav_1, wav_2):
    """ Calculate the radial velocity difference between two wavelength values"""
    c = 299792.458   #  km / s
    difference = wav_2 - wav_1
    relative = difference / wav_1
    return relative * c


def _parser():
    """Take care of all the argparse stuff.

    :returns: the args
    """
    parser = argparse.ArgumentParser(description='Calculate RV doppler shift between two wavelengths')
    parser.add_argument('original_wavelength', help='The original wavelength', type=float)
    parser.add_argument('new_wavelength', help='THe new wavelength', type=float)
    parser.add_argument('-m', '--mode', choices=['normal','reverse', 'iterable'], default='normal', help='Output mode', type=str)   # reverse, both, (iteratorable input)
    # TODO: Add these extra modes
    # parser.add_argument('-u', '--unit', help='Distance unit of measurement [km, m, cm]')
    # parser.add_argument('-r', '--round', help='Rounding on ouput, e.g. ["2dp", "3sf"]')
    args = parser.parse_args()
    return args

def main(original_wavelength, new_wavelength, mode=False):  # unit, rounding
    """ Obtian RV offset between wavelengths and print to screen.

    prints rv between the wavelength values.
    """
    if mode == "reverse":
        # Switch direction of doppler shift
        original_wavelength, new_wavelength = new_wavelength, original_wavelength

    rv = relative_rv(original_wavelength, new_wavelength)
    print("\n" + "-" * 20 )
    print("Original   -->   New   |  RV (km/s)" )
    print("-" * 20 )
    print("{0}  -->  {1}  |  {2}".format(original_wavelength, new_wavelength, rv))
    print("-" * 20 )


if __name__ == "__main__":
    args = vars(_parser())
    wave1 = args.pop('original_wavelength')
    wave2 = args.pop('new_wavelength')
    opts = {k: args[k] for k in args}

    main(wave1, wave2, **opts)

@@ -966,26 +966,24 @@
 ra modes%0A   
- #
  parser.add_
@@ -1043,16 +1043,20 @@
 rement %5B
+Mm, 
 km, m, c
@@ -1056,18 +1056,73 @@
 m, m, cm
-%5D'
+, mm%5D', choices=%5B%22Mm%22, %22km%22,%22m%22,%22cm%22, %22mm%22%5D, default=%22km%22
 )%0A    # 
@@ -1309,16 +1309,27 @@
 de=False
+, unit=%22km%22
 ):  # un
@@ -1671,16 +1671,223 @@
 elength)
+%0A%0A    if unit == %22mm%22:%0A        rv *= 1e6%0A    elif unit == %22cm%22:%0A        rv *= 1e5%0A    elif unit == %22m%22:%0A        rv *= 1e3%0A    elif unit == %22km%22:%0A        rv *= 1e0%0A    elif unit == %22Mm%22:%0A        rv *= 1e-3%0A%0A%0A
 %0A    pri
@@ -1952,14 +1952,28 @@
 RV (
-km
+%7B0%7D
 /s)%22
+.format(unit)
  )%0A 

Add units option - default is kilometers/second