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

Ecmwf simplify config #1433

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
23 changes: 14 additions & 9 deletions eodag/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ def list_queryables(
properties, associating parameters to their annotated type, and a additional_properties attribute
"""
# only fetch providers if product type is not found
available_product_types = [
available_product_types: List[str] = [
pt["ID"]
for pt in self.list_product_types(provider=provider, fetch_providers=False)
]
Expand Down Expand Up @@ -2300,12 +2300,12 @@ def list_queryables(
)

queryables: QueryablesDict = QueryablesDict(
additional_properties=True, additional_information="", **{}
additional_properties=False, additional_information="", **{}
)

for plugin in self._plugins_manager.get_search_plugins(product_type, provider):
# attach product type config
product_type_configs = {}
product_type_configs: Dict[str, Any] = {}
if product_type:
self._attach_product_type_config(plugin, product_type)
product_type_configs[product_type] = plugin.config.product_type_config
Expand All @@ -2325,20 +2325,25 @@ def list_queryables(
"queryables from provider %s could not be fetched due to an authentication error",
plugin.provider,
)

plugin_queryables = plugin.list_queryables(
kwargs,
available_product_types,
product_type_configs,
product_type,
pt_alias,
)
queryables.update(plugin_queryables)
if not plugin_queryables.additional_properties:
queryables.additional_properties = False

information = queryables.additional_information
if plugin_queryables.additional_information:
queryables.additional_information += (
f"{provider}: {plugin_queryables.additional_information}"
)
information += f"{provider}: {plugin_queryables.additional_information}"

queryables = QueryablesDict(
queryables.additional_properties
or plugin_queryables.additional_properties,
information,
**{**plugin_queryables, **queryables},
)

return queryables

Expand Down
22 changes: 8 additions & 14 deletions eodag/api/product/_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class EOProduct:
search_intersection: Optional[BaseGeometry]
assets: AssetsDict

driver: DatasetDriver
downloader: Optional[Union[Api, Download]] = None
downloader_auth: Optional[Authentication] = None

def __init__(
self, provider: str, properties: Dict[str, Any], **kwargs: Any
) -> None:
Expand All @@ -136,18 +140,10 @@ def __init__(
and value != NOT_MAPPED
and NOT_AVAILABLE not in str(value)
}
if "geometry" not in properties or (
(
properties["geometry"] == NOT_AVAILABLE
or properties["geometry"] == NOT_MAPPED
)
and "defaultGeometry" not in properties
):
raise MisconfiguredError(
f"No geometry available to build EOProduct(id={properties.get('id', None)}, provider={provider})"
)
elif not properties["geometry"] or properties["geometry"] == NOT_AVAILABLE:
product_geometry = properties.pop("defaultGeometry", DEFAULT_GEOMETRY)

default_geometry = properties.pop("defaultGeometry", DEFAULT_GEOMETRY)
if properties.get("geometry") in (None, NOT_AVAILABLE, NOT_MAPPED):
product_geometry = default_geometry
else:
product_geometry = properties["geometry"]

Expand All @@ -171,8 +167,6 @@ def __init__(
)
self.search_intersection = None
self.driver = self.get_driver()
self.downloader: Optional[Union[Api, Download]] = None
self.downloader_auth: Optional[Authentication] = None

def as_dict(self) -> Dict[str, Any]:
"""Builds a representation of EOProduct as a dictionary to enable its geojson
Expand Down
23 changes: 3 additions & 20 deletions eodag/api/product/metadata_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ def convert_get_hydrological_year(date: str):
date_object = datetime.strptime(utc_date, "%Y-%m-%dT%H:%M:%S.%fZ")
date_object_second_year = date_object + relativedelta(years=1)
return [
f'{date_object.strftime("%Y")}_{date_object_second_year.strftime("%y")}'
f"{date_object.strftime('%Y')}_{date_object_second_year.strftime('%y')}"
]

@staticmethod
Expand Down Expand Up @@ -1326,8 +1326,8 @@ def format_query_params(
query_params[eodag_search_key] = formatted_query_param
else:
provider_search_key, provider_value = parts
query_params.setdefault(provider_search_key, []).append(
format_metadata(provider_value, product_type, **query_dict)
query_params[provider_search_key] = format_metadata(
provider_value, product_type, **query_dict
)
else:
query_params[provider_search_key] = user_input
Expand Down Expand Up @@ -1546,23 +1546,6 @@ def get_provider_queryable_key(
return eodag_key


def eodag_key_from_provider_key(
provider_key: str,
metadata_mapping: Dict[str, Union[List[Any], str]],
) -> str:
"""Get eodag key for provider key based on the metadata mapping if the provider key
appears in the metadata mapping, otherwise the provider key is returned

:param provider_key: name of the variable received from the provider
:param metadata_mapping: metadata mapping of the provider
:returns: eodag key
"""
for mm, mv in metadata_mapping.items():
if isinstance(mv, list) and len(mv) > 1 and provider_key == mv[0]:
return mm
return provider_key


# Keys taken from OpenSearch extension for Earth Observation http://docs.opengeospatial.org/is/13-026r9/13-026r9.html
# For a metadata to be queryable, The way to query it must be specified in the
# provider metadata_mapping configuration parameter. It will be automatically
Expand Down
8 changes: 2 additions & 6 deletions eodag/plugins/apis/ecmwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
from eodag.plugins.apis.base import Api
from eodag.plugins.search import PreparedSearch
from eodag.plugins.search.base import Search
from eodag.plugins.search.build_search_result import (
ECMWF_KEYWORDS,
ECMWFSearch,
keywords_to_mdt,
)
from eodag.plugins.search.build_search_result import ECMWFSearch, ecmwf_mtd
from eodag.utils import (
DEFAULT_DOWNLOAD_TIMEOUT,
DEFAULT_DOWNLOAD_WAIT,
Expand Down Expand Up @@ -93,7 +89,7 @@ class EcmwfApi(Api, ECMWFSearch):
def __init__(self, provider: str, config: PluginConfig) -> None:
# init self.config.metadata_mapping using Search Base plugin
config.metadata_mapping = {
**keywords_to_mdt(ECMWF_KEYWORDS, "ecmwf"),
**ecmwf_mtd(),
**config.metadata_mapping,
}
Search.__init__(self, provider, config)
Expand Down
22 changes: 8 additions & 14 deletions eodag/plugins/search/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,18 @@ def build_sort_by(

def _get_product_type_queryables(
self, product_type: Optional[str], alias: Optional[str], filters: Dict[str, Any]
) -> Dict[str, Annotated[Any, FieldInfo]]:
) -> QueryablesDict:
default_values: Dict[str, Any] = deepcopy(
getattr(self.config, "products", {}).get(product_type, {})
)
default_values.pop("metadata_mapping", None)
try:
filters["productType"] = product_type
return self.discover_queryables(**{**default_values, **filters}) or {}
queryables = self.discover_queryables(**{**default_values, **filters}) or {}
except NotImplementedError:
return self.queryables_from_metadata_mapping(product_type, alias)
queryables = self.queryables_from_metadata_mapping(product_type, alias)

return QueryablesDict(**queryables)

def list_queryables(
self,
Expand Down Expand Up @@ -369,17 +371,9 @@ def list_queryables(
if product_type:
self.config.product_type_config = product_type_configs[product_type]
queryables = self._get_product_type_queryables(product_type, alias, filters)
if getattr(self.config, "discover_queryables", {}).get(
"constraints_url", ""
):
additional_properties = False
else:
additional_properties = True
return QueryablesDict(
additional_properties=additional_properties,
additional_information=additional_info,
**queryables,
)
queryables.additional_information = additional_info

return queryables
else:
all_queryables: Dict[str, Any] = {}
for pt in available_product_types:
Expand Down
Loading
Loading