Skip to content

Commit

Permalink
Fix! Blackified
Browse files Browse the repository at this point in the history
  • Loading branch information
GriffinBabe committed Feb 12, 2024
1 parent 97e31cb commit eff07d2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
3 changes: 1 addition & 2 deletions src/openeo_gfmap/fetching/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ def load_collection(
pre_mask = params.get("pre_mask", None)
if pre_mask is not None:
assert isinstance(pre_mask, openeo.DataCube), (
f"The 'pre_mask' parameter must be an openeo datacube, "
f"got {pre_mask}."
f"The 'pre_mask' parameter must be an openeo datacube, " f"got {pre_mask}."
)
cube = cube.mask(pre_mask.resample_cube_spatial(cube))

Expand Down
4 changes: 1 addition & 3 deletions src/openeo_gfmap/fetching/s1.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ def s1_grd_default_processor(cube: openeo.DataCube, **params):
)

cube = resample_reproject(
cube,
params.get("target_resolution", 10.0),
params.get("target_crs", None)
cube, params.get("target_resolution", 10.0), params.get("target_crs", None)
)

cube = rename_bands(cube, BASE_SENTINEL1_GRD_MAPPING)
Expand Down
17 changes: 13 additions & 4 deletions src/openeo_gfmap/preprocessing/compositing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
import openeo


def median_compositing(cube: openeo.DataCube, period: Union[str, list]) -> openeo.DataCube:
def median_compositing(
cube: openeo.DataCube, period: Union[str, list]
) -> openeo.DataCube:
"""Perfrom median compositing on the given datacube."""
if isinstance(period, str):
return cube.aggregate_temporal_period(period=period, reducer="median", dimension="t")
return cube.aggregate_temporal_period(
period=period, reducer="median", dimension="t"
)
elif isinstance(period, list):
return cube.aggregate_temporal(intervals=period, reducer="median", dimension="t")
return cube.aggregate_temporal(
intervals=period, reducer="median", dimension="t"
)


def mean_compositing(cube: openeo.DataCube, period: str) -> openeo.DataCube:
"""Perfrom mean compositing on the given datacube."""
if isinstance(period, str):
return cube.aggregate_temporal_period(period=period, reducer="mean", dimension="t")
return cube.aggregate_temporal_period(
period=period, reducer="mean", dimension="t"
)
elif isinstance(period, list):
return cube.aggregate_temporal(intervals=period, reducer="mean", dimension="t")
4 changes: 3 additions & 1 deletion src/openeo_gfmap/preprocessing/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import openeo


def linear_interpolation(cube: openeo.DataCube,) -> openeo.DataCube:
def linear_interpolation(
cube: openeo.DataCube,
) -> openeo.DataCube:
"""Perform linear interpolation on the given datacube."""
return cube.apply_dimension(dimension="t", process="array_interpolate_linear")
5 changes: 1 addition & 4 deletions src/openeo_gfmap/preprocessing/udf_rank.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import numpy as np
import xarray as xr
from openeo.udf import XarrayDataCube
Expand Down Expand Up @@ -31,9 +30,7 @@ def select_maximum(score: xr.DataArray):
# Convert YYYY-mm-dd to datetime64 objects
time_bins = [np.datetime64(interval[0]) for interval in intervals]

rank_mask = bap_score.groupby_bins('t', bins=time_bins).map(
select_maximum
)
rank_mask = bap_score.groupby_bins("t", bins=time_bins).map(select_maximum)
else:
raise ValueError("Period is not defined in the UDF. Cannot run it.")

Expand Down
8 changes: 2 additions & 6 deletions tests/test_openeo_gfmap/test_cloud_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,8 @@ def test_bap_quintad(backend: Backend):
backend_context = BackendContext(backend=backend)

# Additional parameters
fetching_parameters = {
"fetching_resolution": 10.0
}
preprocessing_parameters = {
"apply_scl_dilation": True
}
fetching_parameters = {"fetching_resolution": 10.0}
preprocessing_parameters = {"apply_scl_dilation": True}

# Fetch the datacube
s2_extractor = build_sentinel2_l2a_extractor(
Expand Down

0 comments on commit eff07d2

Please sign in to comment.