def create_temperature_ts_plot(): """ Create plot for README sketch """ stations = DwdObservationRequest( DwdObservationParameterSet.CLIMATE_SUMMARY, DwdObservationResolution.DAILY, DwdObservationPeriod.HISTORICAL) df = stations.all() station_id, _, _, height, lat, lon, name, state = df.sort_values( "FROM_DATE").iloc[0].values name = name.replace(u"ß", "ss") data = DwdObservationValues( [station_id], DwdObservationParameter.DAILY.TEMPERATURE_AIR_200, DwdObservationResolution.DAILY, period=[DwdObservationPeriod.HISTORICAL]) df = data.all() df_annual = df.groupby(df.DATE.dt.year)["VALUE"].mean().reset_index() df_annual["DATE"] = pd.to_datetime(df_annual["DATE"], format="%Y") temp_mean = df["VALUE"].mean() fig, ax = plt.subplots(tight_layout=True) df.plot("DATE", "VALUE", ax=ax, color="blue", label="Tmean,daily", legend=False) df_annual.plot("DATE", "VALUE", ax=ax, color="orange", label="Tmean,annual", legend=False) ax.axhline(y=temp_mean, color="red", label="mean(Tmean,daily)") ax.text(0.2, 0.05, "Source: Deutscher Wetterdienst", ha='center', va='center', transform=ax.transAxes) ax.set_xlabel("Date") title = f"temperature (°C) at {name} (GER)\n" \ f"ID {station_id}\n" \ f"{lat}N {lon}E {height}m" ax.set_title(title) ax.legend(facecolor="white") ax.margins(x=0) plt.savefig(f"temperature_ts.png")
def create_weather_stations_map(): """ Create map of DWD weather stations_result in Germany """ stations = DwdObservationRequest(DwdObservationDataset.CLIMATE_SUMMARY, DwdObservationResolution.DAILY, DwdObservationPeriod.HISTORICAL) stations_df = stations.all().df fig, ax = plt.subplots() # Rainbow colormap cmap = colors.LinearSegmentedColormap.from_list("", [ '#86007D', '#0000F9', '#008018', '#FFFF41', '#FFA52C', '#FF0018', ]) bounds = stations_df.height.quantile( [0, 0.16666667, 0.33333333, 0.5, 0.66666667, 0.83333333, 1]).values norm = colors.BoundaryNorm(bounds, cmap.N) stations_df = stations_df.rename(columns={"height": "Height [m]"}) stations_df.plot.scatter(x="longitude", y="latitude", c="Height [m]", cmap=cmap, norm=norm, ax=ax) ax.set_xlabel("Longitude [°]") ax.set_ylabel("Latitude [°]") ax.set_title("German weather stations_result") ax.text(0.3, 0.05, "Source: Deutscher Wetterdienst", ha='center', va='center', transform=ax.transAxes) plt.savefig("german_weather_stations.png") return