Skip to content

Commit

Permalink
r.external: testsuite added (#2291)
Browse files Browse the repository at this point in the history
This PR adds a testsuite (based on `r.in.gdal` testsuite).
  • Loading branch information
neteler committed Apr 2, 2022
1 parent d2317a2 commit a08769c
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 0 deletions.
140 changes: 140 additions & 0 deletions raster/r.external/testsuite/data/elevation.asc

Large diffs are not rendered by default.

Binary file added raster/r.external/testsuite/data/elevation.nc
Binary file not shown.
1 change: 1 addition & 0 deletions raster/r.external/testsuite/data/elevation.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["Lambert_Conformal_Conic",GEOGCS["GCS_grs80",DATUM["D_North_American_1983",SPHEROID["Geodetic_Reference_System_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",36.16666666666666],PARAMETER["standard_parallel_2",34.33333333333334],PARAMETER["latitude_of_origin",33.75],PARAMETER["central_meridian",-79],PARAMETER["false_easting",609601.22],PARAMETER["false_northing",0],UNIT["Meter",1]]
Binary file added raster/r.external/testsuite/data/elevation.tif
Binary file not shown.
Binary file added raster/r.external/testsuite/data/elevation.tiff
Binary file not shown.
Binary file added raster/r.external/testsuite/data/elevation3d.nc
Binary file not shown.
20 changes: 20 additions & 0 deletions raster/r.external/testsuite/data/generate_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# This script requires the GRASS 7 North Carolina location

export GRASS_OVERWRITE=1

# 2D output
g.region raster=elevation -p
g.region res=100 -p

r.out.gdal input=elevation output=elevation.tif format=GTiff
r.out.gdal input=elevation output=elevation.tiff format=GTiff
r.out.gdal input=elevation output=elevation.asc format=AAIGrid
r.out.gdal input=elevation output=elevation.nc format=netCDF

# 3D output
g.region b=0 t=5 res3=100 tbres=1 -p3

r.to.rast3 input=elevation output=elevation3d
r3.out.netcdf input=elevation3d output=elevation3d.nc

261 changes: 261 additions & 0 deletions raster/r.external/testsuite/test_r_external.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
"""Test of r.external
@author Markus Neteler
"""
from grass.gunittest.case import TestCase


class TestGdalImport(TestCase):
@classmethod
def setUpClass(cls):
"""Use temporary region settings"""
cls.use_temp_region()

@classmethod
def tearDownClass(cls):
"""!Remove the temporary region"""
cls.del_temp_region()

def tearDown(self):
self.runModule(
"g.remove", type="raster", flags="f", pattern="test_external_map*"
)

def test_1(self):

self.assertModule(
"r.external",
"Register GTiff Format",
input="data/elevation.tif",
output="test_external_map",
)

self.runModule("g.region", raster="test_external_map")

# Output of r.univar
univar_string = """n=20250
null_cells=0
cells=20250
min=56.1364936828613
max=156.221710205078
range=100.085216522217
mean=110.358078733845
mean_of_abs=110.358078733845
stddev=20.3247267738233
variance=413.09451843057
coeff_var=18.4170719597623
sum=2234751.09436035"""

self.assertRasterFitsUnivar(
raster="test_external_map", reference=univar_string, precision=3
)

def test_2(self):

self.assertModule(
"r.external",
"Register GTiff Format",
input="data/elevation.tiff",
output="test_external_map",
)

self.runModule("g.region", raster="test_external_map")

# Output of r.univar
univar_string = """n=20250
null_cells=0
cells=20250
min=56.1364936828613
max=156.221710205078
range=100.085216522217
mean=110.358078733845
mean_of_abs=110.358078733845
stddev=20.3247267738233
variance=413.09451843057
coeff_var=18.4170719597623
sum=2234751.09436035"""

self.assertRasterFitsUnivar(
raster="test_external_map", reference=univar_string, precision=3
)

def test_3(self):

self.assertModule(
"r.external",
"Register AAIGrid Format",
input="data/elevation.asc",
output="test_external_map",
)

self.runModule("g.region", raster="test_external_map")

# Output of r.univar
univar_string = """n=20250
null_cells=0
cells=20250
min=56.1364936828613
max=156.221710205078
range=100.085216522217
mean=110.358078733845
mean_of_abs=110.358078733845
stddev=20.3247267738233
variance=413.09451843057
coeff_var=18.4170719597623
sum=2234751.09436035"""

self.assertRasterFitsUnivar(
raster="test_external_map", reference=univar_string, precision=3
)

def test_4(self):

self.assertModule(
"r.external",
"Register netCDF Format",
input="data/elevation.nc",
output="test_external_map",
)

self.runModule("g.region", raster="test_external_map")

# Output of r.univar
univar_string = """n=20250
null_cells=0
cells=20250
min=56.1364936828613
max=156.221710205078
range=100.085216522217
mean=110.358078733845
mean_of_abs=110.358078733845
stddev=20.3247267738233
variance=413.09451843057
coeff_var=18.4170719597623
sum=2234751.09436035"""

self.assertRasterFitsUnivar(
raster="test_external_map", reference=univar_string, precision=3
)

def test_netCDF_3d_1(self):

self.assertModule(
"r.external",
"Register netCDF Format",
input="data/elevation3d.nc",
flags="o",
output="test_external_map",
)

# Output of r.info
info_string = """north=228500
south=215000
east=645000
west=630000
nsres=100
ewres=100
rows=135
cols=150
cells=20250
datatype=FCELL
ncats=0"""

self.assertRasterFitsInfo(
raster="test_external_map.1", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.2", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.3", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.4", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.5", reference=info_string, precision=3
)

def test_netCDF_3d_2(self):

self.assertModule(
"r.external",
"Register netCDF Format",
input="data/elevation3d.nc",
flags="o",
output="test_external_map",
)

# Output of r.info
info_string = """north=228500
south=215000
east=645000
west=630000
nsres=100
ewres=100
rows=135
cols=150
cells=20250
datatype=FCELL
ncats=0"""

self.assertRasterFitsInfo(
raster="test_external_map.1", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.2", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.3", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.4", reference=info_string, precision=3
)
self.assertRasterFitsInfo(
raster="test_external_map.5", reference=info_string, precision=3
)

def test_netCDF_3d_3(self):

self.assertModule(
"r.external",
"Register netCDF Format",
input="data/elevation3d.nc",
flags="o",
band=2,
output="test_external_map",
)

# Output of r.info
info_string = """north=228500
south=215000
east=645000
west=630000
nsres=100
ewres=100
rows=135
cols=150
cells=20250
datatype=FCELL
ncats=0"""

self.assertRasterFitsInfo(
raster="test_external_map", reference=info_string, precision=3
)


class TestExternalImportFails(TestCase):
def test_error_handling_1(self):
# Wrong band number
self.assertModuleFail(
"r.external",
input="data/elevation.nc",
band="-1",
output="test_external_map",
)


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

test()

0 comments on commit a08769c

Please sign in to comment.