Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed meteo extractor #156

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
51 changes: 47 additions & 4 deletions src/openeo_gfmap/fetching/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,36 @@
"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):
if backend not in [Backend.TERRASCOPE, Backend.FED]:
raise ValueError(
GriffinBabe marked this conversation as resolved.
Show resolved Hide resolved
f"Collection {collection_name} is only supported on Terrascope/FED backend."
)
band_mapping = AGERA5_STAC_MAPPING

def generic_default_fetcher(
connection: openeo.Connection,
Expand Down Expand Up @@ -68,6 +86,7 @@ def generic_default_fetcher(
spatial_extent,
temporal_extent,
fetch_type,
is_stac=is_stac,
**params,
)
except OpenEoApiError as e:
Expand All @@ -86,7 +105,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 +116,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 +149,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.

Loading