Skip to content

Commit

Permalink
r.tpi use 'int' instead of np.int; add test (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpawley committed Oct 29, 2023
1 parent 26df529 commit 01aba18
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/raster/r.tpi/r.tpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def main():

# calculate radi for generalization
radi = np.logspace(
np.log(minradius), np.log(maxradius), steps, base=np.exp(1), dtype=np.int
np.log(minradius), np.log(maxradius), steps, base=np.exp(1), dtype="int"
)
radi = np.unique(radi)
sizes = radi * 2 + 1
Expand Down
56 changes: 56 additions & 0 deletions src/raster/r.tpi/testsuite/test_tpi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3

"""
MODULE: Test of r.tpi
AUTHOR(S): Steven Pawley <dr.stevenpawley gmail com>
PURPOSE: Test of r.tpi basic operation
COPYRIGHT: (C) 2022 by Steven Pawley 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 grass.script as gs

from grass.gunittest.case import TestCase
from grass.gunittest.main import test


class TestClassification(TestCase):
"""Test basic operation of r.tpi"""

# input rasters
dem_map = "elevation"
tpi_map = "mtpi"

@classmethod
def setUpClass(cls):
"""Setup that is required for all tests"""
cls.use_temp_region()
cls.runModule("g.region", raster=cls.dem_map)

@classmethod
def tearDownClass(cls):
"""Remove the temporary region (and anything else we created)"""
cls.del_temp_region()
cls.runModule("g.remove", flags="f", type="raster", name=cls.tpi_map)

def test_mtpi(self):
"""Checks that the output is created"""
# train model
self.assertModule(
"r.tpi",
input=self.dem_map,
minradius=1,
maxradius=31,
steps=5,
output=self.tpi_map,
)
self.assertRasterExists(self.tpi_map, msg="Output was not created")


if __name__ == "__main__":
test()

0 comments on commit 01aba18

Please sign in to comment.