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.
The RME zenith angle in degrees is similar, with absolute values less than 0.0002 degrees.
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.
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.
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 tostdout
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.
The RME zenith angle in degrees is similar, with absolute values less than 0.0002 degrees.
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.txtAffects 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.
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
andazimuth
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 theazimuth
does have some differences of around 1 degree from one side to the other.