diff --git a/flexmeasures_openweathermap/__init__.py b/flexmeasures_openweathermap/__init__.py index e62a566..6a905c9 100644 --- a/flexmeasures_openweathermap/__init__.py +++ b/flexmeasures_openweathermap/__init__.py @@ -29,6 +29,7 @@ DEFAULT_DATA_SOURCE_NAME = "OpenWeatherMap" DEFAULT_WEATHER_STATION_NAME = "weather station (created by FM-OWM)" WEATHER_STATION_TYPE_NAME = "weather station" +DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE = 1 __version__ = "0.1" __settings__ = { @@ -48,6 +49,10 @@ description=f"Name of the weather station asset, defaults to '{DEFAULT_WEATHER_STATION_NAME}'", level="debug", ), + "OPENWEATHERMAP_MAXIMAL_DEGREE_LOCATION_DISTANCE": dict( + descripion=f"Maximum distance (in degrees latitude & longitude) for weather stations from forecast location, defaults to {DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE}", + level="debug", + ), } # CLI diff --git a/flexmeasures_openweathermap/utils/owm.py b/flexmeasures_openweathermap/utils/owm.py index 35c98f0..5f34f5b 100644 --- a/flexmeasures_openweathermap/utils/owm.py +++ b/flexmeasures_openweathermap/utils/owm.py @@ -14,6 +14,7 @@ from flexmeasures.data.models.time_series import Sensor, TimedBelief from flexmeasures.data.utils import save_to_db +from flexmeasures_openweathermap import DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE from .locating import find_weather_sensor_by_location from ..sensor_specs import mapping from .modeling import ( @@ -72,7 +73,6 @@ def call_openweatherapi( def save_forecasts_in_db( api_key: str, locations: List[Tuple[float, float]], - max_degree_difference_for_nearest_weather_sensor: int = 2, ): """Process the response from OpenWeatherMap API into timed beliefs. Collects all forecasts for all locations and all sensors at all locations, then bulk-saves them. @@ -80,7 +80,10 @@ def save_forecasts_in_db( click.echo("[FLEXMEASURES-OWM] Getting weather forecasts:") click.echo("[FLEXMEASURES-OWM] Latitude, Longitude") click.echo("[FLEXMEASURES-OWM] -----------------------") - + max_degree_difference_for_nearest_weather_sensor = current_app.config.get( + "OPENWEATHERMAP_MAXIMAL_DEGREE_LOCATION_DISTANCE", + DEFAULT_MAXIMAL_DEGREE_LOCATION_DISTANCE, + ) for location in locations: click.echo("[FLEXMEASURES] %s, %s" % location) weather_sensors: Dict[