アメダス実況値(気温)をPythonで地図作成することに成功しました。
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
import matplotlib as mpl
from matplotlib.colors import ListedColormap,LinearSegmentedColormap
import numpy as np
import shutil
from PIL import Image
import requests
url = "https://www.jma.go.jp/bosai/amedas/const/amedastable.json"
with requests.get(url) as response: json = response.json()
df = pd.DataFrame(json).transpose()
df["lat"] = df["lat"].str[0] + df["lat"].str[1]/60
df["lon"] = df["lon"].str[0] + df["lon"].str[1]/60
url = "https://www.jma.go.jp/bosai/amedas/data/map/yyyymmddhhmm00.json"
with requests.get(url) as response: json = response.json()
df_amedas = pd.DataFrame(json).transpose()
for col in df_amedas.columns: df_amedas[col] = df_amedas[col].dropna().str[0].dropna()
df_amedas["lon"] = df.loc[df_amedas.index, "lon"]
df_amedas["lat"] = df.loc[df_amedas.index, "lat"]
fig, ax = plt.subplots(figsize = (21,16))
cmap = mpl.colors.ListedColormap(['darkblue','mediumblue','blue','deepskyblue','cyan','skyblue','lightblue','white','palegreen','lightgreen','greenyellow','yellow','orange','red'])
cmap.set_under('navy')
cmap.set_over('purple')
bounds = [-35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
vmin, vmax = min(bounds), max(bounds)
plt.xlim(128, 149)
plt.ylim(30, 46)
plt.xticks([])
plt.yticks([])
plt.gca().spines['left'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['bottom'].set_visible(False)
japan_resize.plot(ax=ax, facecolor='white', edgecolor='black', linewidth=1)
ax.scatter(x, y, c=temp, s=50, alpha=0.75, edgecolors="lightgray", cmap=cmap, vmin=-35, vmax=35)
plt.xlabel("")
plt.ylabel("")
fig.savefig("hokkaido-kyushu_amedas_temp.png")
fig, ax = plt.subplots(figsize = (10,6.6))
plt.xlim(122, 132)
plt.ylim(23.5, 30.1)
plt.xticks([])
plt.yticks([])
plt.gca().spines['left'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
japan_resize.plot(ax=ax, facecolor='white', edgecolor='black', linewidth=1)
ax.scatter(x, y, c=temp, s=50, alpha=0.75, edgecolors="lightgray", cmap=cmap, vmin=-35, vmax=35)
plt.xlabel("")
plt.ylabel("")
plt.show()
fig.savefig("okinawa_amedas_temp.png")
fig, ax = plt.subplots(figsize = (0.5,1))
plt.xlim(142, 142.5)
plt.ylim(27, 28)
plt.xticks([])
plt.yticks([])
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['bottom'].set_visible(False)
japan_resize.plot(ax=ax, facecolor='white', edgecolor='black', linewidth=1)
ax.scatter(x, y, c=temp, s=50, alpha=0.75, edgecolors="lightgray", cmap=cmap, vmin=-35, vmax=35)
plt.xlabel("")
plt.ylabel("")
plt.show()
fig.savefig("ogasawara_amedas_temp.png")
im1 = Image.open('/home/yasube873/Python/weather/map/00_japan/hokkaido-kyushu_amedas_temp.png')
im2 = Image.open('/home/yasube873/Python/weather/map/00_japan/okinawa_amedas_temp.png')
back_im = im1.copy()
back_im.paste(im2, (135, 110))
back_im.save('/home/yasube873/Python/weather/map/00_japan/japan_resize_amedas_temp.png')
im1 = Image.open('/home/yasube873/Python/weather/map/00_japan/japan_resize_amedas_temp.png')
im2 = Image.open('/home/yasube873/Python/weather/map/00_japan/ogasawara_amedas_temp.png')
back_im = im1.copy()
back_im.paste(im2, (1300, 1300))
back_im.save('/home/yasube873/Python/weather/map/00_japan/japan_resize_amedas_temp.png')
back_im.show()
cmap = mpl.colors.ListedColormap(['darkblue','mediumblue','blue','deepskyblue','cyan','skyblue','lightblue','white','palegreen','lightgreen','greenyellow','yellow','orange','red'])
cmap.set_under('navy')
cmap.set_over('purple')
bounds = [-35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25, 30, 35]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
vmin, vmax = min(bounds), max(bounds)
fig, ax2 = plt.subplots(figsize=(17.5, 0.75))
fig.subplots_adjust(bottom=0.5)
cb = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm, boundaries=[-10] + bounds + [10], extend='both', extendfrac='auto', ticks=bounds, spacing='uniform', orientation='horizontal')
cb.ax.tick_params(labelsize=22.5)
cb.set_label('')
fig.savefig("amedas_temp_calorbar.png")
im1 = Image.open('/home/yasube873/Python/weather/map/00_japan/japan_resize_amedas_temp.png')
im2 = Image.open('/home/yasube873/Python/weather/map/00_japan/amedas_temp_calorbar.png')
im2 = Image.open('/home/yasube873/Python/weather/map/00_japan/amedas_temp_calorbar.png')
back_im = im1.copy()
back_im.paste(im2, (150, 1500))
back_im.save('/home/yasube873/Python/weather/map/00_japan/japan_resize_amedas_temp_yyyymmddhhmm00.png')
back_im.show()
(yyyymmddhhmmに年月日時分を入力)
(yyyymmddhhmm→202304181500)
個人的には納得。
ここまでできたので、少し休みます。
back_im.paste(im2, (150, 1500))
back_im.save('/home/yasube873/Python/weather/map/00_japan/japan_resize_amedas_temp_yyyymmddhhmm00.png')
back_im.show()
(yyyymmddhhmmに年月日時分を入力)
(yyyymmddhhmm→202304181500)
個人的には納得。
ここまでできたので、少し休みます。