Skip to content

Commit

Permalink
Merge pull request #156 from Open-EO/delete-meteo-fetcher
Browse files Browse the repository at this point in the history
Removed meteo extractor
  • Loading branch information
VincentVerelst authored Sep 11, 2024
2 parents 8f8ccd0 + 278613d commit 4e568b0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 134 deletions.
20 changes: 16 additions & 4 deletions src/openeo_gfmap/fetching/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@

import logging

from .fetching import CollectionFetcher, FetchType
from .s1 import build_sentinel1_grd_extractor
from .s2 import build_sentinel2_l2a_extractor

_log = logging.getLogger(__name__)
_log.setLevel(logging.INFO)

ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch.setFormatter(formatter)

_log.addHandler(ch)

__all__ = [
"build_sentinel2_l2a_extractor",
"CollectionFetcher",
"FetchType",
"build_sentinel1_grd_extractor",
"build_generic_extractor",
"build_generic_extractor_stac",
]

from .fetching import CollectionFetcher, FetchType # noqa: E402
from .generic import build_generic_extractor, build_generic_extractor_stac # noqa: E402
from .s1 import build_sentinel1_grd_extractor # noqa: E402
from .s2 import build_sentinel2_l2a_extractor # noqa: E402
47 changes: 43 additions & 4 deletions src/openeo_gfmap/fetching/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,32 @@
"vapour-pressure": "AGERA5-VAPOUR",
"wind-speed": "AGERA5-WIND",
}
AGERA5_STAC_MAPPING = {
"dewpoint_temperature_mean": "AGERA5-DEWTEMP",
"total_precipitation": "AGERA5-PRECIP",
"solar_radiation_flux": "AGERA5-SOLRAD",
"2m_temperature_max": "AGERA5-TMAX",
"2m_temperature_mean": "AGERA5-TMEAN",
"2m_temperature_min": "AGERA5-TMIN",
"vapour_pressure": "AGERA5-VAPOUR",
"wind_speed": "AGERA5-WIND",
}
KNOWN_UNTEMPORAL_COLLECTIONS = ["COPERNICUS_30"]

AGERA5_TERRASCOPE_STAC = "https://stac.openeo.vito.be/collections/agera5_daily"


def _get_generic_fetcher(
collection_name: str, fetch_type: FetchType, backend: Backend
collection_name: str, fetch_type: FetchType, backend: Backend, is_stac: bool
) -> Callable:
band_mapping: Optional[dict] = None

if collection_name == "COPERNICUS_30":
band_mapping = BASE_DEM_MAPPING
elif collection_name == "AGERA5":
band_mapping = BASE_WEATHER_MAPPING
elif is_stac and (AGERA5_TERRASCOPE_STAC in collection_name):
band_mapping = AGERA5_STAC_MAPPING

def generic_default_fetcher(
connection: openeo.Connection,
Expand Down Expand Up @@ -68,6 +82,7 @@ def generic_default_fetcher(
spatial_extent,
temporal_extent,
fetch_type,
is_stac=is_stac,
**params,
)
except OpenEoApiError as e:
Expand All @@ -86,7 +101,9 @@ def generic_default_fetcher(
return generic_default_fetcher


def _get_generic_processor(collection_name: str, fetch_type: FetchType) -> Callable:
def _get_generic_processor(
collection_name: str, fetch_type: FetchType, is_stac: bool
) -> Callable:
"""Builds the preprocessing function from the collection name as it stored
in the target backend.
"""
Expand All @@ -95,6 +112,8 @@ def _get_generic_processor(collection_name: str, fetch_type: FetchType) -> Calla
band_mapping = BASE_DEM_MAPPING
elif collection_name == "AGERA5":
band_mapping = BASE_WEATHER_MAPPING
elif is_stac and (AGERA5_TERRASCOPE_STAC in collection_name):
band_mapping = AGERA5_STAC_MAPPING

def generic_default_processor(cube: openeo.DataCube, **params):
"""Default collection preprocessing method for generic datasets.
Expand Down Expand Up @@ -126,9 +145,29 @@ def build_generic_extractor(
fetch_type: FetchType,
collection_name: str,
**params,
) -> CollectionFetcher:
"""Creates a generic extractor adapted to the given backend. Provides band mappings for known
collections, such as AGERA5 available on Terrascope/FED and Copernicus 30m DEM in all backends.
"""
fetcher = _get_generic_fetcher(
collection_name, fetch_type, backend_context.backend, False
)
preprocessor = _get_generic_processor(collection_name, fetch_type, False)

return CollectionFetcher(backend_context, bands, fetcher, preprocessor, **params)


def build_generic_extractor_stac(
backend_context: BackendContext,
bands: list,
fetch_type: FetchType,
collection_url: str,
**params,
) -> CollectionFetcher:
"""Creates a generic extractor adapted to the given backend. Currently only tested with VITO backend"""
fetcher = _get_generic_fetcher(collection_name, fetch_type, backend_context.backend)
preprocessor = _get_generic_processor(collection_name, fetch_type)
fetcher = _get_generic_fetcher(
collection_url, fetch_type, backend_context.backend, True
)
preprocessor = _get_generic_processor(collection_url, fetch_type, True)

return CollectionFetcher(backend_context, bands, fetcher, preprocessor, **params)
126 changes: 0 additions & 126 deletions src/openeo_gfmap/fetching/meteo.py

This file was deleted.

0 comments on commit 4e568b0

Please sign in to comment.