def test_deci2sexa_pre_should_work_as_expected(): """The pre keyword should round decimal places to required values.""" assert deci2sexa(-11.2345678) == (-1, 11, 14, 4.444) assert deci2sexa(-11.2345678, pre=5) == (-1, 11, 14, 4.44408) assert deci2sexa(-11.2345678, pre=2) == (-1, 11, 14, 4.44) assert deci2sexa(-11.2345678, pre=0) == (-1, 11, 14, 4.0) assert deci2sexa(-11.2345678, pre=-1) == (-1, 11, 14, 0.0)
def test_deci2sexa_upper_trim_should_trim_upper_limit(): assert deci2sexa(24, upper_trim=True) == (1, 24, 0.0, 0.0) assert deci2sexa(24, lower=0, upper=24, upper_trim=True) == (1, 0.0, 0.0, 0.0) x = 23+59/60.0+59.99999/3600.0 assert deci2sexa(x, lower=0, upper=24, pre=3, upper_trim=True) == (1, 0, 0, 0) assert deci2sexa(x, lower=0, upper=24, pre=5, upper_trim=True) == (1, 23, 59, 59.99999)
def test_deci2sexa_upper_trim_should_trim_upper_limit(): assert deci2sexa(24, upper_trim=True) == (1, 24, 0.0, 0.0) assert deci2sexa(24, lower=0, upper=24, upper_trim=True) == (1, 0.0, 0.0, 0.0) x = 23 + 59 / 60.0 + 59.99999 / 3600.0 assert deci2sexa(x, lower=0, upper=24, pre=3, upper_trim=True) == (1, 0, 0, 0) assert deci2sexa(x, lower=0, upper=24, pre=5, upper_trim=True) == (1, 23, 59, 59.99999)
def test_deci2sexa_normalize_should_work_as_expected(): """deci should get properly normlized when lower and upper bounds are given.""" assert deci2sexa(10, lower=0, upper=360) == (1, 10, 0.0, 0.0) assert deci2sexa(361, lower=0, upper=360) == (1, 1, 0.0, 0.0) assert deci2sexa(-2, lower=0, upper=360) == (1, 358, 0.0, 0.0) assert deci2sexa(10, lower=-90, upper=90) == (1, 10, 0.0, 0.0) assert deci2sexa(-91, lower=-90, upper=90) == (1, 89, 0.0, 0.0) assert deci2sexa(-91, lower=-90, upper=90, b=True) == (-1, 89, 0.0, 0.0)
def direccion(punto1, punto2, formato='rumbo', decimales_segundos=0): delta_x = punto2.X-punto1.X delta_y = punto2.Y-punto1.Y hemisferio_ns = '' hemisferio_ew = '' angulo = deci2sexa(np.degrees(np.arctan(abs(delta_x)/abs(delta_y))),pre=decimales_segundos) if delta_y > 0: hemisferio_ns = 'N' else: hemisferio_ns = 'S' if delta_x > 0: hemisferio_ew = 'E' else: hemisferio_ew = 'W' if formato.lower() == 'rumbo': return "{0} {1:02d}°{2:02d}'{3:02d}\" {4}".format(hemisferio_ns, int(angulo[1]), int(angulo[2]), int(angulo[3]), hemisferio_ew) elif formato.lower() == 'azimut': return "{0:02d}°{1:02d}'{2:02d}\"".format(int(angulo[1]), int(angulo[2]), int(angulo[3]))
def test_deci2sexa_trunc_should_truncate_values(): """trunc should truncate values.""" x = 23 + 59 / 60.0 + 59.99999 / 3600.0 assert deci2sexa(x, pre=3, trunc=True) == (1, 23, 59, 59.999) assert deci2sexa(x, pre=4, trunc=True) == (1, 23, 59, 59.9999)
def test_deci2sexa_pre_should_handle_nines(): """deci2sexa pre should recover nines.""" x = 23 + 59 / 60.0 + 59.99999 / 3600.0 assert deci2sexa(x, pre=3) == (1, 24, 0.0, 0.0) assert deci2sexa(x, pre=4) == (1, 24, 0.0, 0.0) assert deci2sexa(x, pre=5) == (1, 23, 59, 59.99999)
def test_deci2sexa_trunc_should_truncate_values(): """trunc should truncate values.""" x = 23+59/60.0+59.99999/3600.0 assert deci2sexa(x, pre=3, trunc=True) == (1, 23, 59, 59.999) assert deci2sexa(x, pre=4, trunc=True) == (1, 23, 59, 59.9999)
def test_deci2sexa_pre_should_handle_nines(): """deci2sexa pre should recover nines.""" x = 23+59/60.0+59.99999/3600.0 assert deci2sexa(x, pre=3) == (1, 24, 0.0, 0.0) assert deci2sexa(x, pre=4) == (1, 24, 0.0, 0.0) assert deci2sexa(x, pre=5) == (1, 23, 59, 59.99999)