Skip to content

Commit f407e47

Browse files
author
Darius Couchard
committed
Added meteo data from preprocessed catalogue in inference
1 parent 1625b61 commit f407e47

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

src/worldcereal/openeo/feature_extractor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ def execute(self, inarr: xr.DataArray) -> xr.DataArray:
103103
)
104104

105105
self.logger.info("Extracting presto features")
106-
features = get_presto_features(inarr, presto_model_url, self.epsg)
106+
features = get_presto_features(
107+
inarr, presto_model_url, self.epsg, batch_size=8192
108+
)
107109
return features
108110

109111
def _execute(self, cube: XarrayDataCube, parameters: dict) -> XarrayDataCube:

src/worldcereal/openeo/preprocessing.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
SpatialContext,
1111
TemporalContext,
1212
)
13+
from openeo_gfmap.fetching.meteo import build_meteo_extractor
1314
from openeo_gfmap.fetching.generic import build_generic_extractor
1415
from openeo_gfmap.fetching.meteo import build_meteo_extractor
1516
from openeo_gfmap.fetching.s1 import build_sentinel1_grd_extractor
@@ -238,6 +239,39 @@ def raw_datacube_METEO(
238239
return extractor.get_cube(connection, spatial_extent, temporal_extent)
239240

240241

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

303337
dem_data = dem_data.linear_scale_range(0, 65534, 0, 65534)
304338

305-
meteo_data = raw_datacube_METEO(
339+
meteo_data = precomposited_datacube_METEO(
306340
connection=connection,
307-
backend_context=backend_context,
308341
spatial_extent=spatial_extent,
309342
temporal_extent=temporal_extent,
310-
fetch_type=FetchType.TILE,
311343
)
312344

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")
319-
320345
data = s2_data.merge_cubes(s1_data)
321346
data = data.merge_cubes(dem_data)
322-
data = data.merge_cubes(mean_temperature)
323-
data = data.merge_cubes(total_precipitation)
347+
data = data.merge_cubes(meteo_data)
324348

325349
return data

0 commit comments

Comments
 (0)