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

Gradient calculations to python: slope and aspect #125

Closed scotthavens closed 4 years ago

scotthavens commented 5 years ago

In loadTopo the IPW gradient method is called to calculate the slope and aspect for use in stoporad. This is a fairly easy calculation that was converted over to Python. The method that IPW uses in gradient is a finite difference approach in just the x and y direction. Two new methods for calculating the slope and aspect are implemented.

Gradient methods

gradient_d4

The gradient_d4 method mimics the IPW gradient performing the finite difference in only the x and y direction.

gradient_d8

GIS frameworks like ArcGIS and GDAL use a second order finite difference, implemented in gradient_d8. The ArcGIS documentation has a good overview.

Other changes

Gradient differences

The changes in the calculation of the gradient method breaks the tests for RME and RME with HRRR. Due to the way SMRF handles the IPW gradient calculation with converting to IPW images and back, it was not expected for the new methods to match the old method.

RME dem

Comparing the methods over the dem show differences between the methods. The bottom line is the most pronounced but there is minimal difference between the slop and aspect between IPW gradient and gradient_d4. There are larger differences between IPW gradient and gradient_d8. The figures below are in tests/test_gradient.py.

smrf_gradient_images

The historgrams show that most of the differences is close to 0 with larger spread for the gradient_d8 method. smrf_gradient_hist

RME net solar radiation with gradient_d4

The gradient is used in the stoporad calculation which will affect the net solar radiation. The test now fail because of the differences above. The difference between the test and the net solar radiation with gradient_d4 shows small differences between the two, most likely because of the bottom row and bit resolution of the original IPW images.

smrf_gradient_net_solar_hist_d4

RME net solar radiation with gradient_d8

Removing the bottom row from the comparison shows that the gradient_d8 method has a good normal like distribution centered around 0 with +/- 2 W/m2 difference.

smrf_gradient_net_solar_hist_smal

RME HRRR net solar radiation with gradient_d8

Removing the bottom row from the comparison shows that the gradient_d8 method has a good normal like distribution centered around 0 with +/- 5 W/m2 difference, which is a little larger than with the station data.

smrf_gradient_hrrr_net_solar_hist_small

scotthavens commented 4 years ago

@Hedrick-ARS the tests don't pass because of the net solar. To make the tests pass we will need to update the gold files.

scotthavens commented 4 years ago

This looks like a good improvement, and a more accurate estimation of both slope and aspect.

Would it be worth adding tests with some flat or multifaceted surfaces (e.g., planes, pyramids)?

A plane would be a good test to see how it does with flat terrain. I will look into a pyramid as well, it will mainly be for testing the edges where the pyramid meets as the flat surfaces will be the same as the tests.

scotthavens commented 4 years ago

This looks like a good improvement, and a more accurate estimation of both slope and aspect.

Would it be worth adding tests with some flat or multifaceted surfaces (e.g., planes, pyramids)?

Added a flat slope to the gradient tests. IPW set's it convention for a flat slope to have 0 slope but south aspect.