-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from EnvModellingGroup/nan_distance
Add ability to create distance based on missing data (nodata) in the rasters, as well as the edge. This allows for partial spatial data sets, e.g. processed bathymetry surveys, rather than just DEM "products", such as GEBCO. Fixes #4
- Loading branch information
Showing
6 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
# Copyright Jon Hill, University of York, [email protected] | ||
|
||
test_file_name1 = "tests/test_raster_large.tif" | ||
test_file_name2 = "tests/test_raster_nodata_centre.tif" | ||
temp_file = "temp.tif" | ||
|
||
class TestBufferCreator(unittest.TestCase): | ||
|
@@ -87,5 +88,32 @@ def test_simple_distance_setres(self): | |
self.assertEqual(rci.get_val(point3),1.0) | ||
self.assertAlmostEqual(rci.get_val(point4),0.5,delta=0.01) | ||
|
||
def test_simple_distance_nan(self): | ||
""" Very simple test with a raster object like thus: | ||
1 2 3 4 | ||
5 6 7 8 | ||
9 NAN NAN 12 | ||
13 14 15 16 | ||
(on a 20x20 grid, not 4x4 as above...only so much space | ||
in comments!). The slightly-left-of-centre has been | ||
replaced by NaN | ||
LLC is 0,0 and upper right is 4,4. (hence dx is 0.2) | ||
The data are stored in cell centres and we ask for a few coords. | ||
We check that the value is 1 at the distance, 0 at the boundary | ||
and, for this test, the value is 0 in the centre. | ||
""" | ||
rbuff = CreateBuffer(test_file_name2, 1.0) | ||
point1 = [0.2, 3.85] # should return ~0 | ||
point2 = [0.7, 2] # should be 0.4 | ||
point3 = [1.7, 2] # should be 0 (in the centre) | ||
rbuff.make_buffer(temp_file) | ||
# we now read in the buffer using the rasterinterpolator class | ||
rci = RasterInterpolator(temp_file) | ||
rci.set_band() | ||
self.assertAlmostEqual(rci.get_val(point1),0.0, delta=0.03) | ||
self.assertAlmostEqual(rci.get_val(point2),0.4, delta=0.03) | ||
self.assertEqual(rci.get_val(point3),0.0) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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
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
Binary file not shown.