USDA-ARS-NWRC / smrf

SMRF was designed to increase the flexibility of taking measured weather data, or atmospheric models, and distributing the data across a watershed.
Other
12 stars 4 forks source link

Sun angle calculation now pure Python with Numpy support #122

Closed scotthavens closed 5 years ago

scotthavens commented 5 years ago

The sun angle calculation was done with a subprocess call to the IPW sunang function. The calculations were extracted from IPW and converted to Python. Tests were added to ensure that the sun angle functions were returning correct values and improved on the functionality. If latitude and longitude are provided as a numpy array, sunang will calculate the sun angle for every point.

At a point, single date

The first test replicates the example in the IPW man page for sunang with no difference between the example and the Python version. The values must be truncated in Python to match the print to stdout that SMRF reads from. The truncation can be turned off if needed or is a numpy array is passed.

At a point, whole water year

Comparing over a full water year for RME shows very little differences, most likely in the precision of the print statements. The azimuth below shows a difference in azimuth (degrees) of less that 0.01 degrees. smrf_sunang_azimuth

The RME zenith angle in degrees is similar, with absolute values less than 0.0002 degrees. smrf_sunang_zenith

This text (csv) file show the difference for every hour in this test. The code used to generate the figures and text file are in tests/test_radiation.py. sunang_comparison.txt

Affects to net solar radiation

With the small differences, the net solar radiation is not the same as the gold standard for RME causing the tests to fail. However, looking at the differences most values are about 0 with a maximum of 0.175 W/m2 which is insignificant for the magnitude of solar radiation. Accepting this PR will require an update in the gold standard. smrf_net_solar_diff

Sun angle for a whole basin

With the sun angle in Python, we can now pass latitude and longitude as an array. This will return an array of cosz and azimuth that can be provided to functions when they are ready. This will require rework of illumination angle and solar modules. Below is an example from the Tuolumne River Basin. cosz does not vary widely across the basin but the azimuth does have some differences of around 1 degree from one side to the other. smrf_sunang_cosz_tuolumne smrf_sunang_azimuth_tuolumne

scotthavens commented 5 years ago

This PR has been pulled into PR #123