-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a testsuite (based on `r.in.gdal` testsuite).
- Loading branch information
Showing
8 changed files
with
422 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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 @@ | ||
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 not shown.
Binary file not shown.
Binary file not shown.
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,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 | ||
|
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,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() |