Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.sim.sediment: add simple test #4978

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
106 changes: 106 additions & 0 deletions raster/r.sim/r.sim.sediment/testsuite/test_r_sim_sediment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
from grass.gunittest.case import TestCase


class TestRSimSediment(TestCase):
"""Test r.sim.sediment"""

# Set up the necessary raster maps for testing
elevation = "elevation"
dx = "tmp_dx"
dy = "tmp_dy"
depth_default = "depth_default"
tranin = "tranin"
detin = "detin"
tauin = "tauin"
sedflux = "sedflux"
erdep = "erdep"
reference_sedflux = "reference_sedflux"
reference_erdep = "reference_erdep"

@classmethod
def setUpClass(cls):
"""Set up region, create necessary data"""
cls.runModule("g.region", n=224000, s=223000, e=637000, w=636000, res=10)
cls.runModule("r.slope.aspect", elevation=cls.elevation, dx=cls.dx, dy=cls.dy)
cls.runModule(
"r.unpack",
input="data/depth_default.pack",
output=cls.depth_default,
)
cls.runModule("r.mapcalc", expression=f"{cls.tranin} = 0.001")
cls.runModule("r.mapcalc", expression=f"{cls.detin} = 0.001")
cls.runModule("r.mapcalc", expression=f"{cls.tauin} = 0.01")
cls.runModule(
"r.unpack",
input="data/reference_sedflux.pack",
output=cls.reference_sedflux,
)
cls.runModule(
"r.unpack", input="data/reference_erdep.pack", output=cls.reference_erdep
)

@classmethod
def tearDownClass(cls):
"""Clean up test environment"""
cls.runModule(
"g.remove",
flags="f",
type="raster",
name=[
cls.elevation,
cls.dx,
cls.dy,
cls.depth_default,
cls.tranin,
cls.detin,
cls.tauin,
cls.reference_sedflux,
cls.reference_erdep,
],
)

def tearDown(self):
"""Clean up test environment"""
self.runModule(
"g.remove",
flags="f",
type="raster",
name=f"{self.sedflux},{self.erdep}",
)

def test_default(self):
"""Test r.sim.sediment execution with defaults"""
# Run the r.sim.sediment simulation
self.assertModule(
"r.sim.sediment",
elevation=self.elevation,
dx=self.dx,
dy=self.dy,
water_depth=self.depth_default,
man_value=0.05,
detachment_coeff=self.detin,
transport_coeff=self.tranin,
shear_stress=self.tauin,
sediment_flux=self.sedflux,
erosion_deposition=self.erdep,
random_seed=1,
)

# Assert that the output rasters exist
self.assertRasterExists(self.sedflux)
self.assertRasterExists(self.erdep)
# Assert that the output rasters are the same
self.assertRastersEqual(
self.sedflux, reference=self.reference_sedflux, precision="0.000001"
)
self.assertRastersEqual(
self.erdep,
reference=self.reference_erdep,
precision="0.000001",
)


if __name__ == "__main__":
from grass.gunittest.main import test

test()
Loading