-
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.
Merge pull request #68 from Open-EO/additional-mask
Fixed scl mask
- Loading branch information
Showing
5 changed files
with
96 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,4 +161,5 @@ cython_debug/ | |
#.idea/ | ||
|
||
tests/test_openeo_gfmap/results/ | ||
notebook/ | ||
notebook/ | ||
data/ |
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,36 @@ | ||
import numpy as np | ||
import xarray as xr | ||
from openeo.udf import XarrayDataCube | ||
|
||
|
||
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube: | ||
""" | ||
Computes a cloud mask covering a full observation or nothing depending on the percentage of | ||
high probability cloud pixels. If the amount of before mentioned pixels is higher than 95%, | ||
then returns a mask covering the whole observation, otherwise returns an empty mask. | ||
""" | ||
array = cube.get_array().transpose("t", "bands", "y", "x") | ||
|
||
output_array = np.zeros( | ||
shape=(array.shape[0], 1, array.shape[2], array.shape[3]), dtype=np.uint8 | ||
) | ||
|
||
for i in range(array.shape[0]): | ||
high_proba_count = ((array[i] == 9) * 1).sum() | ||
high_proba_percentage = high_proba_count / (array.shape[2] * array.shape[3]) | ||
|
||
if high_proba_percentage > 0.95: | ||
output_array[i] = 1 | ||
|
||
output_array = xr.DataArray( | ||
output_array, | ||
dims=["t", "bands", "y", "x"], | ||
coords={ | ||
"t": array.t, | ||
"bands": ["mask"], | ||
"y": array.y, | ||
"x": array.x, | ||
}, | ||
) | ||
|
||
return XarrayDataCube(output_array) |