| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
""" |
| 4 |
MODULE: Test of r.surf.gauss |
| 5 |
|
| 6 |
AUTHOR(S): Corey White <ctwhite48 gmail com> |
| 7 |
|
| 8 |
PURPOSE: Tests random gauss surface generation |
| 9 |
|
| 10 |
COPYRIGHT: (C) 2023 - 2024 by Corey White and the GRASS Development Team |
| 11 |
|
| 12 |
This program is free software under the GNU General Public |
| 13 |
License (>=v2). Read the file COPYING that comes with GRASS |
| 14 |
for details. |
| 15 |
""" |
| 16 |
|
| 17 |
import os |
| 18 |
from grass.gunittest.case import TestCase |
| 19 |
from grass.gunittest.main import test |
| 20 |
|
| 21 |
|
| 22 |
class MeanSigmaTestCase(TestCase): |
| 23 |
"""Test r.surf.gauss module""" |
| 24 |
|
| 25 |
# Raster map name be used as output |
| 26 |
output = "random_result" |
| 27 |
|
| 28 |
@classmethod |
| 29 |
def setUpClass(cls): |
| 30 |
"""Ensures expected computational region""" |
| 31 |
os.environ["GRASS_RANDOM_SEED"] = "42" |
| 32 |
# modifying region just for this script |
| 33 |
cls.use_temp_region() |
| 34 |
cls.runModule("g.region", rows=10, cols=10) |
| 35 |
|
| 36 |
@classmethod |
| 37 |
def tearDownClass(cls): |
| 38 |
"""Remove the temporary region""" |
| 39 |
cls.del_temp_region() |
| 40 |
|
| 41 |
def tearDown(self): |
| 42 |
"""Remove the output created from the module""" |
| 43 |
self.runModule("g.remove", flags="f", type="raster", name=[self.output]) |
| 44 |
|
| 45 |
def test_defaut_settings(self): |
| 46 |
"""Check to see if univariate statistics match for default""" |
| 47 |
self.assertModule("r.surf.gauss", output=self.output) |
| 48 |
self.assertRasterFitsUnivar( |
| 49 |
self.output, |
| 50 |
reference={"mean": -0.044860, "stddev": 1.019485}, |
| 51 |
precision=1e-6, |
| 52 |
) |
| 53 |
|
| 54 |
def test_mean_sigma_params(self): |
| 55 |
"""Check if mean and sigma params are accepted""" |
| 56 |
mean_value = 3.0 |
| 57 |
sigma_value = 5.8 |
| 58 |
self.assertModule( |
| 59 |
"r.surf.gauss", |
| 60 |
mean=mean_value, |
| 61 |
sigma=sigma_value, |
| 62 |
output=self.output, |
| 63 |
) |
| 64 |
self.assertRasterExists(self.output, msg="Output was not created") |
| 65 |
self.assertRasterFitsUnivar( |
| 66 |
self.output, |
| 67 |
reference={"mean": 2.739812, "stddev": 5.913014}, |
| 68 |
precision=1e-6, |
| 69 |
) |
| 70 |
|
| 71 |
def test_random_seed_option(self): |
| 72 |
"""Checks if random seed option sets random number""" |
| 73 |
mean_value = 3.0 |
| 74 |
sigma_value = 5.8 |
| 75 |
self.assertModule( |
| 76 |
"r.surf.gauss", |
| 77 |
mean=mean_value, |
| 78 |
sigma=sigma_value, |
| 79 |
output=self.output, |
| 80 |
seed=22, |
| 81 |
) |
| 82 |
self.assertRasterExists(self.output, msg="Output was not created") |
| 83 |
self.assertRasterFitsUnivar( |
| 84 |
self.output, |
| 85 |
reference={"mean": 3.183532, "stddev": 6.050756}, |
| 86 |
precision=1e-6, |
| 87 |
) |
| 88 |
|
| 89 |
|
| 90 |
if __name__ == "__main__": |
| 91 |
test() |