Closed scotthavens closed 4 years ago
Wondering if there is an opportunity to use much of the constants or standard solar calculations from the astropy package? https://www.astropy.org
Perhaps. At one time I did look around at other packages but they seem to either be tailored to astronomy or solar panel applications. I currently haven't found a package that is specific the the problem that the the toporad
functions solve. However, the constants should almost all be the same but should we have another dependency just for constants?
However, the constants should almost all be the same but should we have another dependency just for constants?
I agree that a dependency for constants is not worthwhile. Mostly wondering more about the standard solar angle calculations , since those seem standard.
I think it would be something to look at in the future and see how they compare. Since you'll be working with albedo which is a calculation dependent on the solar angles, might be worth looking into it.
I think it would be something to look at in the future and see how they compare. Since you'll be working with albedo which is a calculation dependent on the solar angles, might be worth looking into it.
Really nice improvement to the readability of the radiation component!
One thought I want to throw out there is to add a ticket to improve performance by vectorizing a lot of those functions? Without looking much into it, most calculations look like they can be easily converted with numba for instance.
I've tried to keep them as vectorized as possible to take advantage of numpy. Numba could definitely help on the larger basins or high resolution DEM's perhaps. As it stands, the straight python versions of these functions are 20x faster than the IPW versions. A 4 month simulations I did for a 500x1000 domain completed in like an hour instead of 3-4 hours (and not even threaded). So we're already seeing huge speed ups from this.
The tests freaked me out a little bit because the tests went from ~90 seconds to ~13 seconds. I thought that some of the tests were being skipped but they weren't.
Really nice improvement to the readability of the radiation component! One thought I want to throw out there is to add a ticket to improve performance by vectorizing a lot of those functions? Without looking much into it, most calculations look like they can be easily converted with numba for instance.
I've tried to keep them as vectorized as possible to take advantage of numpy. Numba could definitely help on the larger basins or high resolution DEM's perhaps. As it stands, the straight python versions of these functions are 20x faster than the IPW versions. A 4 month simulations I did for a 500x1000 domain completed in like an hour instead of 3-4 hours (and not even threaded). So we're already seeing huge speed ups from this.
The tests freaked me out a little bit because the tests went from ~90 seconds to ~13 seconds. I thought that some of the tests were being skipped but they weren't.
That is a really good boost. Looking forward to apply that to ERW. Part of the improvement probably is from removing all the calls to a subprocess, which can be expensive with many at once.
And many of the IPW functions have a lot of file IO. For stoporad there are probably 6 or so temporary files that are generated and removing the IO can be fairly significant.
SMRF uses
stoporad
from IPW to estimate the clear sky radiation over snow. This PR implements a full Python version of 3 main IPW utilities:elevrad
,toporad
andstoporad
.TL;DR
elevrad
is within the bit resolution noise of the IPWelevrad
toporad
is within the bit resolution noise of the IPWtoporad
stoporad
has differences of +/- a fewW/m2
due to slightly different calculations forhorizon
andalbedo
envphys
to split up the monsterradiation.py
into manageable pieces that are also more intuiative (see below)loadTopo
, the newbasin_setup
has they
direction decreasing which creates a negativedy
. This negativedy
is passed to the gradient function which flips everything up/down.distribute.solar
was simplified as seperate threads for the IPW calls are no longer needed.New file structure in
envphys
Takes the old
radiation.py
and seperates into asolar
andthermal
package with organized files.stoporad validation
Validation of the new functions were performed against the IPW versions. Everything was held constant between the two as much as possible. A notebook containing the comparisons are in
notebooks/toporad_comparison.ipynb
. All comparisons were done in the Lakes.elevrad
elevrad
is the spatial version oftwostream
which was implemented in PR #123. Comparison with the IPW version show bit resolution noise from the 8-bit IPW output image. All values are inW/m2
.toporad
toporad
uses the output ofelevrad
and adjusts for topography affects. Comparison with the IPW version show bit resolution noise from the 8-bit IPW output image. All values are inW/m2
.stoporad
stoporad
in IPW is a shell script that runs multiple functions, includingelevrad
andtoporad
. Thestoporad
function calls are specific for either the visible or infrared wavelengths. There are differences in both the visible and infrared images but are minimal. These differences are caused by using a differenthorizon
andalbedo
function before callingelevrad
andtoporad
. For the visible, the largest differences are single pixels that are different from the twohorizon
outputs. All values are inW/m2
.Gold changes
RME stations
All variables are 0 expect net solar with minimal changes.
RME HRRR
All variables are 0 expect net solar with minimal changes.
Lakes HRRR
All variables are 0 except net solar and thermal. The cause for the large changes were an issue with
loadTopo
as thetopo.y
variable is decreasing, hence dy is negative which is passed to the gradient calculation. The RME y increases so this wasn't noticed.