Skip to content

Commit 1c1c483

Browse files
author
Darius Couchard
authored
Merge pull request #60 from WorldCereal/56-meteo-inference
56 meteo inference
2 parents 679f33c + a98a840 commit 1c1c483

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

src/worldcereal/openeo/preprocessing.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
TemporalContext,
1212
)
1313
from openeo_gfmap.fetching.generic import build_generic_extractor
14+
from openeo_gfmap.fetching.meteo import build_meteo_extractor
1415
from openeo_gfmap.fetching.s1 import build_sentinel1_grd_extractor
1516
from openeo_gfmap.fetching.s2 import build_sentinel2_l2a_extractor
1617
from openeo_gfmap.preprocessing.compositing import mean_compositing, median_compositing
@@ -229,15 +230,47 @@ def raw_datacube_METEO(
229230
temporal_extent: TemporalContext,
230231
fetch_type: FetchType,
231232
) -> DataCube:
232-
extractor = build_generic_extractor(
233+
extractor = build_meteo_extractor(
233234
backend_context=backend_context,
234235
bands=["AGERA5-TMEAN", "AGERA5-PRECIP"],
235236
fetch_type=fetch_type,
236-
collection_name="AGERA5",
237237
)
238238
return extractor.get_cube(connection, spatial_extent, temporal_extent)
239239

240240

241+
def precomposited_datacube_METEO(
242+
connection: Connection,
243+
spatial_extent: SpatialContext,
244+
temporal_extent: TemporalContext,
245+
) -> DataCube:
246+
"""Extract the precipitation and temperature AGERA5 data from a
247+
pre-composited and pre-processed collection. The data is stored in the
248+
CloudFerro S3 stoage, allowing faster access and processing from the CDSE
249+
backend.
250+
251+
Limitations:
252+
- Only monthly composited data is available.
253+
- Only two bands are available: precipitation-flux and temperature-mean.
254+
- This function do not support fetching points or polygons, but only
255+
tiles.
256+
"""
257+
temporal_extent = [temporal_extent.start_date, temporal_extent.end_date]
258+
spatial_extent = dict(spatial_extent)
259+
260+
# Monthly composited METEO data
261+
cube = connection.load_stac(
262+
"https://s3.waw3-1.cloudferro.com/swift/v1/agera/stac/collection.json",
263+
spatial_extent=spatial_extent,
264+
temporal_extent=temporal_extent,
265+
bands=["precipitation-flux", "temperature-mean"],
266+
)
267+
cube = cube.rename_labels(
268+
dimension="bands", target=["AGERA5-PRECIP", "AGERA5-TMEAN"]
269+
)
270+
271+
return cube
272+
273+
241274
def worldcereal_preprocessed_inputs_gfmap(
242275
connection: Connection,
243276
backend_context: BackendContext,
@@ -302,24 +335,14 @@ def worldcereal_preprocessed_inputs_gfmap(
302335

303336
dem_data = dem_data.linear_scale_range(0, 65534, 0, 65534)
304337

305-
# meteo_data = raw_datacube_METEO(
306-
# connection=connection,
307-
# backend_context=backend_context,
308-
# spatial_extent=spatial_extent,
309-
# temporal_extent=temporal_extent,
310-
# fetch_type=FetchType.TILE,
311-
# )
312-
313-
# # Perform compositing differently depending on the bands
314-
# mean_temperature = meteo_data.band("AGERA5-TMEAN")
315-
# mean_temperature = mean_compositing(mean_temperature, period="month")
316-
317-
# total_precipitation = meteo_data.band("AGERA5-PRECIP")
318-
# total_precipitation = sum_compositing(total_precipitation, period="month")
338+
meteo_data = precomposited_datacube_METEO(
339+
connection=connection,
340+
spatial_extent=spatial_extent,
341+
temporal_extent=temporal_extent,
342+
)
319343

320344
data = s2_data.merge_cubes(s1_data)
321345
data = data.merge_cubes(dem_data)
322-
# data = data.merge_cubes(mean_temperature)
323-
# data = data.merge_cubes(total_precipitation)
346+
data = data.merge_cubes(meteo_data)
324347

325348
return data

0 commit comments

Comments
 (0)