From 80792c8602966314e7da983ea20a245fd2a2ed4c Mon Sep 17 00:00:00 2001 From: Anna Petrasova Date: Fri, 12 May 2023 12:46:59 -0400 Subject: [PATCH] r.horizon: revert back to positive values only (#2955) Enabling negative angles in r.horizon requires more work, the current simple implementation has problems (e.g. flat areas). Also r.sun doesn't work well with negative horizon values. See #2935 for discussion. For now, reverting back to horizon values >= 0 seems best. Note was added to manual page. --- raster/r.horizon/main.c | 2 +- raster/r.horizon/r.horizon.html | 7 ++++--- raster/r.horizon/testsuite/test_r_horizon.py | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/raster/r.horizon/main.c b/raster/r.horizon/main.c index 34ea26c5f3f..39d7db7b0b0 100644 --- a/raster/r.horizon/main.c +++ b/raster/r.horizon/main.c @@ -773,7 +773,7 @@ double horizon_height(void) { double height; - tanh0 = -1.0 / 0.0; /* -inf */ + tanh0 = 0.; length = 0; height = searching(); diff --git a/raster/r.horizon/r.horizon.html b/raster/r.horizon/r.horizon.html index fd422dd2bd3..a67ed2aa949 100644 --- a/raster/r.horizon/r.horizon.html +++ b/raster/r.horizon/r.horizon.html @@ -134,9 +134,10 @@

METHOD

The output with the -d flag is azimuth degree (-90 to 90, where -0 is parallel with the focal cell). In case of negative horizon values -obtained this indicates that the horizon height is below the cell it is -computed from. +0 is parallel with the focal cell). + +

All horizon values are positive (or zero). While negative values are +in theory possible, r.horizon currently does not support them.

EXAMPLES

diff --git a/raster/r.horizon/testsuite/test_r_horizon.py b/raster/r.horizon/testsuite/test_r_horizon.py index 4a8376c4f8f..72a7868c98d 100644 --- a/raster/r.horizon/testsuite/test_r_horizon.py +++ b/raster/r.horizon/testsuite/test_r_horizon.py @@ -30,7 +30,7 @@ 280.000000,0.039774 300.000000,0.032360 320.000000,0.014804 -340.000000,-0.001438 +340.000000,0.000000 360.000000,0.004724 20.000000,0.012612 40.000000,0.015207 @@ -51,7 +51,7 @@ 280.000000,0.039774 300.000000,0.032360 320.000000,0.014804 -340.000000,-0.001438 +340.000000,0.000000 360.000000,0.004724 20.000000,0.012612 40.000000,0.015207 @@ -120,9 +120,9 @@ def test_raster_mode_one_direction(self): ) self.assertModule(module) ref = { - "min": -1.57079637050629, + "min": 0, "max": 0.70678365230560, - "stddev": 0.0708080140468585, + "stddev": 0.0360724286360789, } self.assertRasterFitsUnivar( raster="test_horizon_output_from_elevation_050", @@ -146,7 +146,10 @@ def test_raster_mode_multiple_direction(self): self.runModule(module_list) stdout = module_list.outputs.stdout.strip() self.assertMultiLineEqual( - first="test_horizon_output_from_elevation_010_000\ntest_horizon_output_from_elevation_025_512", + first=( + "test_horizon_output_from_elevation_010_000\n" + "test_horizon_output_from_elevation_025_512" + ), second=stdout, ) @@ -167,7 +170,10 @@ def test_raster_mode_multiple_direction_offset(self): self.runModule(module_list) stdout = module_list.outputs.stdout.strip() self.assertMultiLineEqual( - first="test_horizon_output_from_elevation_090_000\ntest_horizon_output_from_elevation_105_512", + first=( + "test_horizon_output_from_elevation_090_000\n" + "test_horizon_output_from_elevation_105_512" + ), second=stdout, )