-
-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r.surf.gauss: Added seed option and flag (#2931)
* r.surf.gauss: Added seed option and flag * Updated seed options, flags and tests * r.surf.gauss: switch seed to long from int * Update raster/r.surf.gauss/main.c Co-authored-by: Anna Petrasova <[email protected]> * Changed message to warning * Change to G_warning * Update test to check univar stats * Updated tests to check default params univar stats * Removed random seed flag -s * Updated warning message and copywrite * Fixed typo * Update raster/r.surf.gauss/main.c Co-authored-by: Anna Petrasova <[email protected]> * Change test file name to meet convention * Reduced the extent of the test raster to speed up tests * Apply suggestions from code review * Removed old comment * change the tests to use fixed reference values --------- Co-authored-by: Corey White <[email protected]> Co-authored-by: Anna Petrasova <[email protected]>
- Loading branch information
1 parent
2aa98a1
commit 23d28c0
Showing
3 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
MODULE: Test of r.surf.gauss | ||
AUTHOR(S): Corey White <ctwhite48 gmail com> | ||
PURPOSE: Tests random gauss surface generation | ||
COPYRIGHT: (C) 2023 - 2024 by Corey White and the GRASS Development Team | ||
This program is free software under the GNU General Public | ||
License (>=v2). Read the file COPYING that comes with GRASS | ||
for details. | ||
""" | ||
|
||
import os | ||
from grass.gunittest.case import TestCase | ||
from grass.gunittest.main import test | ||
|
||
|
||
class MeanSigmaTestCase(TestCase): | ||
"""Test r.surf.gauss module""" | ||
|
||
# Raster map name be used as output | ||
output = "random_result" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Ensures expected computational region""" | ||
os.environ["GRASS_RANDOM_SEED"] = "42" | ||
# modifying region just for this script | ||
cls.use_temp_region() | ||
cls.runModule("g.region", rows=10, cols=10) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Remove the temporary region""" | ||
cls.del_temp_region() | ||
|
||
def tearDown(self): | ||
"""Remove the output created from the module""" | ||
self.runModule("g.remove", flags="f", type="raster", name=[self.output]) | ||
|
||
def test_defaut_settings(self): | ||
"""Check to see if univariate statistics match for default""" | ||
self.assertModule("r.surf.gauss", output=self.output) | ||
self.assertRasterFitsUnivar( | ||
self.output, | ||
reference=dict(mean=-0.044860, stddev=1.019485), | ||
precision=1e-6, | ||
) | ||
|
||
def test_mean_sigma_params(self): | ||
"""Check if mean and sigma params are accepted""" | ||
mean_value = 3.0 | ||
sigma_value = 5.8 | ||
self.assertModule( | ||
"r.surf.gauss", | ||
mean=mean_value, | ||
sigma=sigma_value, | ||
output=self.output, | ||
) | ||
self.assertRasterExists(self.output, msg="Output was not created") | ||
self.assertRasterFitsUnivar( | ||
self.output, | ||
reference=dict(mean=2.739812, stddev=5.913014), | ||
precision=1e-6, | ||
) | ||
|
||
def test_random_seed_option(self): | ||
"""Checks if random seed option sets random number""" | ||
mean_value = 3.0 | ||
sigma_value = 5.8 | ||
self.assertModule( | ||
"r.surf.gauss", | ||
mean=mean_value, | ||
sigma=sigma_value, | ||
output=self.output, | ||
seed=22, | ||
) | ||
self.assertRasterExists(self.output, msg="Output was not created") | ||
self.assertRasterFitsUnivar( | ||
self.output, | ||
reference=dict(mean=3.183532, stddev=6.050756), | ||
precision=1e-6, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
test() |