Skip to content

Commit 84e628d

Browse files
committed
Beginning implementation of sentinel-3 preprocessing
1 parent 1e20caa commit 84e628d

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

efast/s2_processing_openeo.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def connect():
88
return openeo.connect("https://openeo.dataspace.copernicus.eu/")
99

1010

11+
# TODO move somewhere else, not specific to sentinel-2
1112
class TestArea:
1213
# aoi_wkt = "POINT (-15.432283 15.402828)"
1314
directions = ["west", "south", "east", "north"]
@@ -19,7 +20,12 @@ def __init__(
1920
*,
2021
bbox: Mapping[str, float] = bbox,
2122
s2_bands: Sequence[str] = ["B02", "B03", "B04", "B8A", "SCL"],
22-
s3_bands: Sequence[str] = ["SDR_Oa04", "SDR_Oa06", "SDR_Oa08", "SDR_Oa17"],
23+
s3_bands: Sequence[str] = [
24+
"Syn_Oa04_reflectance",
25+
"Syn_Oa06_reflectance",
26+
"Syn_Oa08_reflectance",
27+
"Syn_Oa17_reflectance",
28+
],
2329
temporal_extent: Sequence[str] = ["2022-06-01", "2022-06-30"],
2430
) -> None:
2531
self.bbox = bbox
@@ -35,6 +41,14 @@ def get_s2_cube(self, connection):
3541
bands=self.s2_bands,
3642
)
3743

44+
def get_s3_cube(self, connection):
45+
return connection.load_collection(
46+
"SENTINEL3_SYN_L2_SYN",
47+
spatial_extent=self.bbox,
48+
temporal_extent=self.temporal_extent,
49+
bands=self.s3_bands,
50+
)
51+
3852

3953
def extract_cloud_mask(cube: openeo.DataCube):
4054
scl = cube.filter_bands(["SCL"])

efast/s3_processing_openeo.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import openeo
2+
3+
def binning_s3():
4+
pass
5+
6+
7+

tests/test_preprocessing_openeo.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
TEST_DATE = "20220618"
3434
TEST_DATE_DASH = "2022-06-18"
3535

36-
SKIP_LOCAL = True
36+
SKIP_LOCAL = False
3737
SMALL_AREA = True
3838

3939

@@ -181,7 +181,8 @@ def extract_epsg_code_from_rasterio_crs(crs: rasterio.CRS) -> int:
181181

182182
def test_data_acquisition_s3():
183183
with create_temp_dir_and_copy_files(
184-
TEST_DATA_S3, sub="raw/", pattern=f"raw/*SY_2_SYN____{TEST_DATE}*"
184+
TEST_DATA_S3, sub="raw/", pattern=f"raw/*SY_2_SYN____2022061*"
185+
#TEST_DATA_S3, sub="raw/", pattern=f"raw/*SY_2_SYN____*"
185186
) as tmp:
186187
inner_data_acquisition_s3(tmp)
187188

@@ -201,15 +202,18 @@ def inner_data_acquisition_s3(tmpdir):
201202
}
202203

203204
if SMALL_AREA:
204-
dist = 900
205+
dist = 3600
205206
bounds["east"] = bounds["west"] + dist
206207
bounds["north"] = bounds["south"] + dist
207208

208209
# reference
209210

210211
s3_binning_dir = tmp / "binning"
212+
s3_composites_dir = tmp / "composites"
211213
s3_download_dir = tmp / "raw"
214+
212215
s3_binning_dir.mkdir()
216+
s3_composites_dir.mkdir()
213217
footprint = transform_bounds_to_wkt(
214218
bounds
215219
) # TODO probably needs to be converted to wkt
@@ -229,6 +233,14 @@ def inner_data_acquisition_s3(tmpdir):
229233
snap_parallelization=1, # TODO more than 1?
230234
)
231235

236+
s3_processing.produce_median_composite(
237+
s3_binning_dir,
238+
s3_composites_dir,
239+
mosaic_days=100,
240+
step=2,
241+
s3_bands=None,
242+
)
243+
232244
shutil.copytree(s3_binning_dir, download_dir, dirs_exist_ok=True)
233245

234246
# openeo
@@ -283,3 +295,14 @@ def transform_bounds_to_wkt(bounds: dict):
283295
minx=minx_wgs84, miny=miny_wgs84, maxx=maxx_wgs84, maxy=maxy_wgs84
284296
)
285297
return wkt.dumps(bbox)
298+
299+
METADATA_UDF = openeo.UDF("""
300+
import numpy as np
301+
import xarray as xr
302+
from openeo.udf import XarrayDataCube
303+
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
304+
array = cube.get_array()
305+
array = array < {tolerance_percentage}
306+
#return XarrayDataCube(xr.DataArray(array, dims=["t", "x", "y", "bands"]))
307+
return XarrayDataCube(xr.DataArray(array, dims=["bands", "x", "y"]))
308+
""")

0 commit comments

Comments
 (0)