openeo-gfmap 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,126 +0,0 @@
1
- """Meteo data fetchers."""
2
-
3
- from functools import partial
4
-
5
- import openeo
6
- from geojson import GeoJSON
7
-
8
- from openeo_gfmap import (
9
- Backend,
10
- BackendContext,
11
- FetchType,
12
- SpatialContext,
13
- TemporalContext,
14
- )
15
- from openeo_gfmap.fetching import CollectionFetcher
16
- from openeo_gfmap.fetching.commons import convert_band_names
17
- from openeo_gfmap.fetching.generic import (
18
- _get_generic_fetcher,
19
- _get_generic_processor,
20
- _load_collection,
21
- )
22
-
23
- WEATHER_MAPPING_TERRASCOPE = {
24
- "dewpoint-temperature": "AGERA5-DEWTEMP",
25
- "precipitation-flux": "AGERA5-PRECIP",
26
- "solar-radiation-flux": "AGERA5-SOLRAD",
27
- "temperature-max": "AGERA5-TMAX",
28
- "temperature-mean": "AGERA5-TMEAN",
29
- "temperature-min": "AGERA5-TMIN",
30
- "vapour-pressure": "AGERA5-VAPOUR",
31
- "wind-speed": "AGERA5-WIND",
32
- }
33
-
34
- WEATHER_MAPPING_STAC = {
35
- "dewpoint_temperature_mean": "AGERA5-DEWTEMP",
36
- "total_precipitation": "AGERA5-PRECIP",
37
- "solar_radiataion_flux": "AGERA5-SOLRAD",
38
- "2m_temperature_max": "AGERA5-TMAX",
39
- "2m_temperature_mean": "AGERA5-TMEAN",
40
- "2m_temperature_min": "AGERA5-TMIN",
41
- "vapour_pressure": "AGERA5-VAPOUR",
42
- "wind_speed": "AGERA5-WIND",
43
- }
44
-
45
-
46
- def stac_fetcher(
47
- connection: openeo.Connection,
48
- spatial_extent: SpatialContext,
49
- temporal_extent: TemporalContext,
50
- bands: list,
51
- fetch_type: FetchType,
52
- **params,
53
- ) -> openeo.DataCube:
54
- bands = convert_band_names(bands, WEATHER_MAPPING_STAC)
55
-
56
- cube = _load_collection(
57
- connection,
58
- bands,
59
- "https://stac.openeo.vito.be/collections/agera5_daily",
60
- spatial_extent,
61
- temporal_extent,
62
- fetch_type,
63
- is_stac=True,
64
- **params,
65
- )
66
-
67
- if isinstance(spatial_extent, GeoJSON) and fetch_type == FetchType.POLYGON:
68
- cube = cube.filter_spatial(spatial_extent)
69
-
70
- return cube
71
-
72
-
73
- METEO_BACKEND_MAP = {
74
- Backend.TERRASCOPE: {
75
- "fetch": partial(
76
- _get_generic_fetcher,
77
- collection_name="AGERA5",
78
- band_mapping=WEATHER_MAPPING_TERRASCOPE,
79
- ),
80
- "preprocessor": partial(
81
- _get_generic_processor,
82
- collection_name="AGERA5",
83
- band_mapping=WEATHER_MAPPING_TERRASCOPE,
84
- ),
85
- },
86
- Backend.CDSE: {
87
- "fetch": stac_fetcher,
88
- "preprocessor": partial(
89
- _get_generic_processor,
90
- collection_name="AGERA5",
91
- band_mapping=WEATHER_MAPPING_STAC,
92
- ),
93
- },
94
- Backend.CDSE_STAGING: {
95
- "fetch": stac_fetcher,
96
- "preprocessor": partial(
97
- _get_generic_processor,
98
- collection_name="AGERA5",
99
- band_mapping=WEATHER_MAPPING_STAC,
100
- ),
101
- },
102
- Backend.FED: {
103
- "fetch": stac_fetcher,
104
- "preprocessor": partial(
105
- _get_generic_processor,
106
- collection_name="AGERA5",
107
- band_mapping=WEATHER_MAPPING_STAC,
108
- ),
109
- },
110
- }
111
-
112
-
113
- def build_meteo_extractor(
114
- backend_context: BackendContext,
115
- bands: list,
116
- fetch_type: FetchType,
117
- **params,
118
- ) -> CollectionFetcher:
119
- backend_functions = METEO_BACKEND_MAP.get(backend_context.backend)
120
-
121
- fetcher, preprocessor = (
122
- partial(backend_functions["fetch"], fetch_type=fetch_type),
123
- backend_functions["preprocessor"](fetch_type=fetch_type),
124
- )
125
-
126
- return CollectionFetcher(backend_context, bands, fetcher, preprocessor, **params)