-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
|
||
from geodataset.utils import fill_nan_gaps | ||
|
||
|
||
class TestsUtils(unittest.TestCase): | ||
def test_fill_nan_gaps(sefl): | ||
a = np.array( | ||
[[np.nan,np.nan,3],[np.nan,5,6],[7,8,9]], float) | ||
b = fill_nan_gaps(a) | ||
np.testing.assert_array_equal(b, | ||
np.array([[5,5,3],[7,5,6],[7,8,9]], float) | ||
) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
import numpy as np | ||
from scipy.ndimage.morphology import distance_transform_edt | ||
|
||
class InvalidDatasetError(Exception): pass | ||
|
||
def fill_nan_gaps(array, distance=5): | ||
""" Fill gaps in input array | ||
Parameters | ||
---------- | ||
array : 2D numpy.array | ||
Raster with data | ||
distance : int | ||
Minimum size of gap to fill | ||
Returns | ||
------- | ||
array : 2D numpy.array | ||
Raster with data with gaps filled | ||
""" | ||
dist, indi = distance_transform_edt( | ||
np.isnan(array), | ||
return_distances=True, | ||
return_indices=True) | ||
gpi = dist <= distance | ||
r, c = indi[:, gpi] | ||
array = np.array(array) | ||
array[gpi] = array[r, c] | ||
return array |