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

Return selected weather model on 'best_match' #90

Open
danicarovo opened this issue Mar 26, 2024 · 1 comment
Open

Return selected weather model on 'best_match' #90

danicarovo opened this issue Mar 26, 2024 · 1 comment

Comments

@danicarovo
Copy link

Our company uses Open-Meteo's Forecast API for the simulation of scenarios.
We allow users to select a weather model for wind simulations. We default to best_match if no weather model is provided or if the requested weather model is unavailable for the location. In this case, we would like to inform the user which weather model was selected.

Currently, when best_match is requested as a weather model, open-meteo's response returns best_match, and no information on which weather model was actually selected. We kindly ask for this information to be returned.

Here is some code to reproduce:

import openmeteo_requests

import requests_cache
import pandas as pd
from retry_requests import retry
from openmeteo_sdk import Model

# Returns model as string
def _model_to_string(model):
        """
        Convert the weather model to a string.

        Args:
            model: Weather model.

        Returns:
            str: Weather model as a string.
        """
        for name, value in Model.Model.__dict__.items():
            if value == model:
                return name
        return None

# Setup the Open-Meteo API client with cache and retry on error
cache_session = requests_cache.CachedSession('.cache', expire_after = 3600)
retry_session = retry(cache_session, retries = 5, backoff_factor = 0.2)
openmeteo = openmeteo_requests.Client(session = retry_session)

# Make sure all required weather variables are listed here
# The order of variables in hourly or daily is important to assign them correctly below
url = "https://api.open-meteo.com/v1/forecast"
params = {
	"latitude": 52.52,
	"longitude": 13.41,
	"hourly": "temperature_2m",
         # Non-valid wm for location: ["arpae_cosmo_2i"]. Valid wm for location: arpae_cosmo_5m
        "models": ["arpae_cosmo_2i","arpae_cosmo_5m","best_match"] 
}
responses = openmeteo.weather_api(url, params=params)

accepted_wms_names = []
accepted_wms_enums = []
for response in responses:
    accepted_wms_names.append(_model_to_string(response.Model()))
    accepted_wms_enums.append(response.Model())
print(accepted_wms_names)
print(accepted_wms_enums)

Returns:

['arpae_cosmo_5m', 'best_match']
[59, 1]

We wish that it returned (assuming that ecmwf_ifs04 was selected by open-meteo as the best weather model for the location):

['arpae_cosmo_5m', 'ecmwf_ifs04']
[59, 2]
@patrick-zippenfenig
Copy link
Member

Hi, thanks for the suggestion. best_match is a bit more complicated than just selecting a single weather model. Depending on the weather variable, different models might be used. Getting all meta data right will challenging. See #mete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants