Package: simple-dwd-weatherforecast
Simple DWD weather forecastDISCLAIMER: This project is a private open source project and doesn't have any connection with Deutscher Wetterdienst.Weather dataThis is a python package for simple access to hourly forecast data for the next 10 days. The data is updated every six hours and updated when needed. Some stations also have actual reported weather, which you can also retrieve.Available station-IDs can be foundhereor you can use the methoddwdforecast.get_nearest_station_id(latitude, longitude)which tries to find it for you.Forecasted weather conditions are evaluated using thistableand then converted into these possible weather conditions:cloudyfoglightning-rainypartlycloudypouringrainysnowysnowy-rainysunnyThe reported weather is delayed (roughly one hour), so have a close look at the time within the presented data.The weather report for the region which is available on the DWD homepage (see an examplehere) can also be retrieved via a method which maps the station to the relevant region.Weather mapsYou can also retrieve weather maps from the DWD GeoServer with this package.Installationpython3-mpipinstallsimple_dwd_weatherforecastUsageWeather dataUsage examplefromsimple_dwd_weatherforecastimportdwdforecastfromdatetimeimportdatetime,timedelta,timezone#Find nearest Station-ID automatically#id = dwdforecast.get_nearest_station_id(50.1109221, 8.6821267)dwd_weather=dwdforecast.Weather("10385")# Station-ID For BERLIN-SCHOENEFELDtime_now=datetime.now(timezone.utc)temperature_now=dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.TEMPERATURE,time_now)time_tomorrow=datetime.now(timezone.utc)+timedelta(days=1)temperature_tomorrow=dwd_weather.get_forecast_data(dwdforecast.WeatherDataType.TEMPERATURE,time_tomorrow)Available methodsAll methods return their values as string. The datetime value has to be in UTC. If no data is available for this datetime, None will be returned. With the optional booleanshouldUpdatean automated check for new updates can be prevented by setting this parameter toFalse. Otherwise data is updated if new data is available with every function call.There is also data available which is updated every hour by DWD. Be careful though, as this will download each time roughly 37MB of data. Furthermore, some elements are missing from this data:PRECIPITATION_PROBABILITYPRECIPITATION_DURATIONYou can use this data by using the optional parameterforce_hourly=True.is_valid_station_id(station_id)#Checks if given station_id is validget_nearest_station_id(latitude,longitude)#Returns nearest Station-ID for the coordinates. latitude and longitude expect float values.update(optionalboolforce_hourly)#Force fetch of new data from the DWD server. With this parameter set to True, there will be missing the precipitation forecast. See above.classWeatherDataType(Enum):CONDITION="condition"TEMPERATURE="TTT"# Unit: KDEWPOINT="Td"# Unit: KPRESSURE="PPPP"# Unit: PaWIND_SPEED="FF"# Unit: m/sWIND_DIRECTION="DD"# Unit: DegreesWIND_GUSTS="FX1"# Unit: m/sPRECIPITATION="RR1c"# Unit: kg/m2PRECIPITATION_PROBABILITY="wwP"# Unit: % (0..100)PRECIPITATION_DURATION="DRR1"# Unit: sCLOUD_COVERAGE="N"# Unit: % (0..100)VISIBILITY="VV"# Unit: mSUN_DURATION="SunD1"# Unit: sSUN_IRRADIANCE="Rad1h"# Unit: W/m2FOG_PROBABILITY="wwM"# Unit: % (0..100)HUMIDITY="humidity"# Unit: %classWeather:get_station_name(optionalboolshouldUpdate)# Return Station nameget_forecast_data(weatherDataType:seeWeatherDataType,datetime,optionalboolshouldUpdate)# Returns the requested weather dataget_get_reported_weather(weatherDataType:seeWeatherDataType,optionalboolshouldUpdate)# Returns the latest actual reported value if available for this stationget_daily_max(weatherDataType:seeWeatherDataType,datetime,optionalboolshouldUpdate)# Returns the maximum daily valueget_timeframe_max(weatherDataType:seeWeatherDataType,datetime,timeframe:hoursafterdatetimeasint,optionalboolshouldUpdate)# Returns the maximum of that value within the time frameget_daily_min(weatherDataType:seeWeatherDataType,datetime,optionalboolshouldUpdate)# Returns the minimum daily valueget_timeframe_min(weatherDataType:seeWeatherDataType,datetime,timeframe:hoursafterdatetimeasint,optionalboolshouldUpdate)# Returns the minimum of that value within the time frameget_daily_sum(weatherDataType:seeWeatherDataType,datetime,optionalboolshouldUpdate)# Returns the daily sum of that valueget_timeframe_sum(weatherDataType:seeWeatherDataType,datetime,timeframe:hoursafterdatetimeasint,optionalboolshouldUpdate)# Returns the sum of that value within the time frameget_timeframe_avg(weatherDataType:seeWeatherDataType,datetime,timeframe:hoursafterdatetimeasint,optionalboolshouldUpdate)# Returns the average of that value within the time frameget_forecast_condition(datetime,optionalboolshouldUpdate)# Result is condition as textget_daily_condition(datetime,optionalboolshouldUpdate)# Result is an approximate "feeled" condition at this dayget_timeframe_condition(datetime,timeframe:hoursafterdatetimeasint,optionalboolshouldUpdate)# Result is an approximate "feeled" condition at this time frameget_weather_report(optionalboolshouldUpdate)# Returns the weather report for the geographical region of the station as HTMLget_uv_index(intday_from_today(values:0-2))# Returns the UV index for the nearest station available for today, tomorrow or the day after tomorrowupdate(self,optionalboolforce_hourly(default:False),optionalboolwith_forecast(default:True),optionalboolwith_measurements(default:False),optionalboolwith_report(default:False),optionalboolwith_uv(default:True))# Updates the weather dataAdvanced UsageIf you want to access the forecast data for the next 10 days directly for further processing, you can do so. All data is stored in dictonary and can be accessed like this:fromsimple_dwd_weatherforecastimportdwdforecastdwd_weather​​=​​dwdforecast​.​Weather​(​"10385"​)# Station-ID For BERLIN-SCHOENEFELD​dwd_weather.update()# This has to be done manually to fetch the data from the DWD serveraccess_forecast_dict=dwd_weather.forecast_data# dwd_weather.forecast_data contains the forecast as a dictKeep in mind that the weather condition is stored as the original digit value as provided by DWD. So if you want to use them, you have to convert these yourself. You can use my simplified conversion from the source code in the variableweather_codesor the original conversion availablehere.Weather mapsYou can download weather maps from the DWD GeoServer with this package. There are different options for the displayed foreground and background data. See below for further information.Usage examplefromsimple_dwd_weatherforecastimportdwdmapimage=dwdmap.get_from_location(51.272,8.84,radius_km=100,map_type=dwdmap.WeatherMapType.NIEDERSCHLAGSRADAR,background_type=dwdmap.WeatherBackgroundMapType.BUNDESLAENDER)image.save("niederschlag.png")image=dwdmap.get_germany(map_type=dwdmap.WeatherMapType.UVINDEX,image_width=520,image_height=580)image.save("uvindex.png")Available methodsclassWeatherMapType(Enum):NIEDERSCHLAGSRADAR="dwd:Niederschlagsradar"MAXTEMP="dwd:GefuehlteTempMax"UVINDEX="dwd:UVI_CS"POLLENFLUG="dwd:Pollenflug"SATELLITE_RGB="dwd:Satellite_meteosat_1km_euat_rgb_day_hrv_and_night_ir108_3h"SATELLITE_IR="dwd:Satellite_worldmosaic_3km_world_ir108_3h"WARNUNGEN_GEMEINDEN="dwd:Warnungen_Gemeinden"WARNUNGEN_KREISE="dwd:Warnungen_Landkreise"classWeatherBackgroundMapType(Enum):LAENDER="dwd:Laender"BUNDESLAENDER="dwd:Warngebiete_Bundeslaender"KREISE="dwd:Warngebiete_Kreise"GEMEINDEN="dwd:Warngebiete_Gemeinden"SATELLIT="dwd:bluemarble"defget_from_location(longitude,latitude,radius_km,map_type:WeatherMapType,background_type:WeatherBackgroundMapType,optionalintegerimage_width,optionalintegerimage_height)#Returns map as pillow image with given radius from coordinatesget_germany(map_type:WeatherMapType,optionalWeatherBackgroundMapTypebackground_type,optionalintegerimage_width,optionalintegerimage_height,optionalstringsave_to_filename)#Returns map as pillow image of whole germanyget_map(minx,miny,maxx,maxy,map_type:WeatherMapType,background_type:WeatherBackgroundMapType,optionalintegerimage_width,optionalintegerimage_height,optionalstringsave_to_filename)#Returns map as pillow imageHelp and ContributionFeel free to open an issue if you find one and I will do my best to help you. If you want to contribute, your help is appreciated! If you want to add a new feature, add a pull request first so we can chat about the details.LicensesThis package uses public data fromDWD OpenData. The Copyright can be viewedhere.