Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #49 from Open-EO/update-load-helper
Browse files Browse the repository at this point in the history
Handle large area processing
  • Loading branch information
sophieherrmann authored Oct 6, 2021
2 parents 2305438 + 09675ca commit 9727cc0
Show file tree
Hide file tree
Showing 8 changed files with 328 additions and 153 deletions.
4 changes: 0 additions & 4 deletions src/openeo_processes/arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,6 @@ def exec_xar(data, ignore_nodata=True, dimension=None):
while (data_first.fillna(999) != data_first).any() and i < len(data_dim):
data_first = data_first.fillna(data_dim[i])
i += 1
else:
pass
return data_first

@staticmethod
Expand Down Expand Up @@ -1030,8 +1028,6 @@ def exec_xar(data, ignore_nodata=True, dimension=None):
while (data_last.fillna(999) != data_last).any() and i >= 0:
data_last = data_last.fillna(data_dim[i])
i -= 1
else:
pass
return data_last

@staticmethod
Expand Down
61 changes: 31 additions & 30 deletions src/openeo_processes/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import xarray as xr
from openeo_processes.utils import process
from openeo_processes.utils import str2time
from openeo_processes.utils import keep_attrs


# TODO: test if this works for different data types
Expand Down Expand Up @@ -383,9 +384,9 @@ def exec_xar(x, y, delta=False, case_sensitive=True, reduce=False): # TODO: add
Parameters
----------
x : xr.DataArray
x : xr.DataArray, integer, float
First operand.
y : xr.DataArray
y : xr.DataArray, integer, float
Second operand.
delta : float, optional
Only applicable for comparing two arrays containing numbers. If this optional parameter is set to a
Expand Down Expand Up @@ -430,7 +431,7 @@ def exec_xar(x, y, delta=False, case_sensitive=True, reduce=False): # TODO: add
ar_eq = x_time == y_time # comparison of dates
else:
ar_eq = x == y

ar_eq = keep_attrs(x, y, ar_eq)
if reduce:
return ar_eq.all()
else:
Expand Down Expand Up @@ -546,9 +547,9 @@ def exec_xar(x, y, delta=None, case_sensitive=True, reduce=False): # TODO: add
Parameters
----------
x : xr.DataArray
x : xr.DataArray, integer, float
First operand.
y : xr.DataArray
y : xr.DataArray, integer, float
Second operand.
delta : float, optional
Only applicable for comparing two arrays containing numbers. If this optional parameter is set to a
Expand Down Expand Up @@ -687,7 +688,7 @@ def exec_xar(x, y, reduce=False):
Parameters
----------
x : xr.DataArray
x : xr.DataArray, integer, float
First operand.
y : xr.DataArray, integer, float
Second operand.
Expand All @@ -700,18 +701,17 @@ def exec_xar(x, y, reduce=False):
xr.DataArray: :
Returns True if `x` is strictly greater than `y`, None if any operand is None, otherwise False.
"""

## x has to be a datacube, whereas y can be another datacube, an integer or a float

if x is None or y is None:
return None
elif isinstance(y, xr.DataArray) or isinstance(y, int) or isinstance(y, float):
elif type(x) in [int, float, xr.DataArray] and type(y) in [int, float, xr.DataArray]:
gt_ar = x > y
gt_ar = keep_attrs(x, y, gt_ar)
if reduce:
return gt_ar.all()
else:
return gt_ar
else:
return False
return False

@staticmethod
def exec_da():
Expand Down Expand Up @@ -827,9 +827,9 @@ def exec_xar(x, y, reduce = False):
Parameters
----------
x : xr.DataArray
x : xr.DataArray, integer, float
First operand.
y : xr.DataArray
y : xr.DataArray, integer, float
Second operand.
reduce : bool, optional
If True, one value will be returned.
Expand All @@ -843,14 +843,14 @@ def exec_xar(x, y, reduce = False):
"""
if x is None or y is None:
return None
elif isinstance(y, xr.DataArray) or isinstance(y, int) or isinstance(y, float):
elif type(x) in [int, float, xr.DataArray] and type(y) in [int, float, xr.DataArray]:
gte_ar = ((x-y) >= 0)
gte_ar = keep_attrs(x, y, gte_ar)
if reduce:
return gte_ar.all()
else:
return gte_ar
else:
return False
return False

@staticmethod
def exec_da():
Expand Down Expand Up @@ -966,9 +966,9 @@ def exec_xar(x, y, reduce = False):
Parameters
----------
x : xr.DataArray
x : xr.DataArray, integer, float
First operand.
y : xr.DataArray
y : xr.DataArray, integer, float
Second operand.
reduce : bool, optional
If True, one value will be returned.
Expand All @@ -980,17 +980,16 @@ def exec_xar(x, y, reduce = False):
Returns True if `x` is strictly lower than `y`, None if any operand is None, otherwise False.
"""
## x has to be a datacube, whereas y can be another datacube, an integer or a float
if x is None or y is None:
return None
elif isinstance(y, xr.DataArray) or isinstance(y, int) or isinstance(y, float):
elif type(x) in [int, float, xr.DataArray] and type(y) in [int, float, xr.DataArray]:
lt_ar = x < y
lt_ar = keep_attrs(x, y, lt_ar)
if reduce:
return lt_ar.all()
else:
return lt_ar
else:
return False
return False

@staticmethod
def exec_da():
Expand Down Expand Up @@ -1106,9 +1105,9 @@ def exec_xar(x, y, reduce = False):
Parameters
----------
x : xr.DataArray
x : xr.DataArray, integer, float
First operand.
y : xr.DataArray
y : xr.DataArray, integer, float
Second operand.
reduce : bool, optional
If True, one value will be returned.
Expand All @@ -1120,17 +1119,16 @@ def exec_xar(x, y, reduce = False):
Returns True if `x` is strictly lower than or equal to `y`, None if any operand is None, otherwise False.
"""
## x has to be a datacube, whereas y can be another datacube, an integer or a float
if x is None or y is None:
return None
elif isinstance(y, xr.DataArray) or isinstance(y, int) or isinstance(y, float):
elif type(x) in [int, float, xr.DataArray] and type(y) in [int, float, xr.DataArray]:
lte_ar = x <= y
lte_ar = keep_attrs(x, y, lte_ar)
if reduce:
return lte_ar.all()
else:
return lte_ar
else:
return False
return False

@staticmethod
def exec_da():
Expand Down Expand Up @@ -1286,9 +1284,12 @@ def exec_xar(x, min, max, exclude_max=False, reduce=False):
return False

if exclude_max:
return xr.ufuncs.logical_and(Gte.exec_xar(x, min, reduce=reduce) , Lt.exec_xar(x, max, reduce=reduce))
bet = xr.ufuncs.logical_and(Gte.exec_xar(x, min, reduce=reduce) , Lt.exec_xar(x, max, reduce=reduce))
else:
return xr.ufuncs.logical_and(Gte.exec_xar(x, min, reduce=reduce) , Lte.exec_xar(x, max, reduce=reduce))
bet = xr.ufuncs.logical_and(Gte.exec_xar(x, min, reduce=reduce) , Lte.exec_xar(x, max, reduce=reduce))
if isinstance(x, xr.DataArray):
bet.attrs = x.attrs
return bet

@staticmethod
def exec_da():
Expand Down
Loading

0 comments on commit 9727cc0

Please sign in to comment.