From d63e9ea3d6dd4f3d0b3d78809cec07269b806c73 Mon Sep 17 00:00:00 2001 From: Caleb Bell Date: Sat, 6 Jun 2020 15:39:56 -0600 Subject: [PATCH] 0.1.81 release --- docs/tutorial.rst | 9 ++++---- fluids/atmosphere.py | 2 ++ tests/test_atmosphere.py | 46 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/docs/tutorial.rst b/docs/tutorial.rst index c070c39f..5fdf1b8e 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -530,6 +530,7 @@ you have to convert the time inputs to that time zone initially. So to find the solar position at 6 AM in Perth, Australia (offset -8 hours), we would manually convert the time zone. + >>> from datetime import datetime, timedelta >>> solar_position(datetime(2020, 6, 6, 14, 30, 0) - timedelta(hours=8), -31.95265, 115.85742) [63.40805686233129, 63.44000181582068, 26.591943137668704, 26.559998184179317, 325.1213762464115, 75.74674754854641] @@ -750,7 +751,7 @@ Determining pipe length from known diameter, pressure drop, and mass flow 937.3258027759333 Not all specified mass flow rates are possible. At a certain downstream -pressure, chocked flow will develop - that downstream pressure is that +pressure, choked flow will develop - that downstream pressure is that at which the mass flow rate reaches a maximum. An exception will be raised if such an input is specified: @@ -767,7 +768,7 @@ Traceback (most recent call last): due to the formation of choked flow at P2=%f, specified outlet pressure was %f' % (Pcf, P2)) Exception: Given outlet pressure is not physically possible due to the formation of choked flow at P2=389699.731765, specified outlet pressure was 300000.000000 -The downstream pressure at which chocked flow occurs can be calculated directly +The downstream pressure at which choked flow occurs can be calculated directly as well: >>> P_isothermal_critical_flow(P=1E6, fd=0.00185, L=1000., D=0.5) @@ -848,7 +849,7 @@ following inputs: None of these models include an acceleration term. In addition to reducing their accuracy, it allows all solutions for the above variables to be analytical. -These models cannot predict the occurrence of chocked flow, and model only +These models cannot predict the occurrence of choked flow, and model only turbulent, not laminar, flow. Most of these models do not depend on the gas's viscosity. @@ -1188,7 +1189,7 @@ pressure drop: 87.31399925838778 The approach documented above is not an adequate procedure for sizing valves -however because chocked flow, compressible flow, the effect of inlet and outlet +however because choked flow, compressible flow, the effect of inlet and outlet reducers, the effect of viscosity and the effect of laminar/turbulent flow all have large influences on the performance of control valves. diff --git a/fluids/atmosphere.py b/fluids/atmosphere.py index 8fd28b17..92580b72 100644 --- a/fluids/atmosphere.py +++ b/fluids/atmosphere.py @@ -899,6 +899,7 @@ def solar_position(moment, latitude, longitude, Z=0.0, T=298.15, P=101325.0, >>> import pytz Perth, Australia - sunrise + >>> solar_position(pytz.timezone('Australia/Perth').localize(datetime(2020, 6, 6, 7, 10, 57)), -31.95265, 115.85742) [90.89617025931763, 90.89617025931763, -0.8961702593176304, -0.8961702593176304, 63.60160176917509, 79.07112321438035] @@ -909,6 +910,7 @@ def solar_position(moment, latitude, longitude, Z=0.0, T=298.15, P=101325.0, [63.40805686233129, 63.44000181582068, 26.591943137668704, 26.559998184179317, 325.1213762464115, 75.74674754854641] Perth, Australia - time input without timezone; must be converted by user to UTC! + >>> solar_position(datetime(2020, 6, 6, 14, 30, 0) - timedelta(hours=8), -31.95265, 115.85742) [63.40805686233129, 63.44000181582068, 26.591943137668704, 26.559998184179317, 325.1213762464115, 75.74674754854641] diff --git a/tests/test_atmosphere.py b/tests/test_atmosphere.py index a6807aac..dd932a29 100644 --- a/tests/test_atmosphere.py +++ b/tests/test_atmosphere.py @@ -24,8 +24,10 @@ import os from fluids.atmosphere import * import fluids +from fluids.numerics import assert_close, assert_close1d import fluids.optional -from datetime import datetime +from datetime import datetime, timedelta +import pytz import pytest try: import pvlib @@ -201,16 +203,44 @@ def test_hwm14(): assert_allclose(MER_CALC, AP_PROFILE_MER) assert_allclose(ZON_CALC, AP_PROFILE_ZON) + +def test_solar_position(): + pos = solar_position(pytz.timezone('Australia/Perth').localize(datetime(2020, 6, 6, 7, 10, 57)), -31.95265, 115.85742) + pos_expect = [90.89617025931763, 90.89617025931763, -0.8961702593176304, -0.8961702593176304, 63.60160176917509, 79.07112321438035] + assert_close1d(pos, pos_expect, rtol=1e-9) + + pos = solar_position(pytz.timezone('Australia/Perth').localize(datetime(2020, 6, 6, 14, 30, 0)), -31.95265, 115.85742) + pos_expect = [63.40805686233129, 63.44000181582068, 26.591943137668704, 26.559998184179317, 325.1213762464115, 75.74674754854641] + assert_close1d(pos, pos_expect, rtol=1e-9) + + pos = solar_position(datetime(2020, 6, 6, 14, 30, 0) - timedelta(hours=8), -31.95265, 115.85742) + pos_expect = [63.40805686233129, 63.44000181582068, 26.591943137668704, 26.559998184179317, 325.1213762464115, 75.74674754854641] + assert_close1d(pos, pos_expect, rtol=1e-9) + + local_time = datetime(2018, 4, 15, 6, 43, 5) + local_time = pytz.timezone('America/Edmonton').localize(local_time) + assert_close(solar_position(local_time, 51.0486, -114.07)[0], 90.00054676987014, rtol=1e-9) + + pos = solar_position(pytz.timezone('America/Edmonton').localize(datetime(2018, 4, 15, 20, 30, 28)), 51.0486, -114.07) + pos_expect = [89.9995695661236, 90.54103812161853, 0.00043043387640950836, -0.5410381216185247, 286.8313781904518, 6.631429525878048] + assert_close1d(pos, pos_expect, rtol=1e-9) + def test_earthsun_distance(): dt = earthsun_distance(datetime(2003, 10, 17, 13, 30, 30)) - assert_allclose(dt, 149090925951.18338) + assert_allclose(dt, 149090925951.18338, rtol=1e-10) dt = earthsun_distance(datetime(2013, 1, 1, 21, 21, 0, 0)) - assert_allclose(dt, 147098127628.8943) + assert_allclose(dt, 147098127628.8943, rtol=1e-10) dt = earthsun_distance(datetime(2013, 7, 5, 8, 44, 0, 0)) - assert_allclose(dt, 152097326908.20578) + assert_allclose(dt, 152097326908.20578, rtol=1e-10) + + assert_close(earthsun_distance(pytz.timezone('America/Edmonton').localize(datetime(2020, 6, 6, 10, 0, 0, 0))), + 151817805599.67142, rtol=1e-10) + + assert_close(earthsun_distance(datetime(2020, 6, 6, 10, 0, 0, 0)), + 151812898579.44104, rtol=1e-10) @pytest.mark.skipif(not has_pvlib, @@ -232,3 +262,11 @@ def test_sunrise_sunset(): assert sunrise == sunrise_expected assert sunset == sunset_expected assert transit == transit_expected + + calgary = pytz.timezone('America/Edmonton') + sunrise, sunset, transit = sunrise_sunset(calgary.localize(datetime(2018, 4, 17)), 51.0486, -114.07) + assert sunrise == calgary.localize(datetime(2018, 4, 16, 6, 39, 1, 570479)) + assert sunset == calgary.localize(datetime(2018, 4, 16, 20, 32, 25, 778162)) + assert transit == calgary.localize(datetime(2018, 4, 16, 13, 36, 0, 386341)) + +