[PYTHON] Use of past meteorological data 1 (Display of AMeDAS points)

The Japan Meteorological Agency will provide historical weather data free of charge until the end of March 2020. (Reference) Usage environment of past weather data https://www.data.jma.go.jp/developer/past_data/index.html

The basic weather data is "Anyone can use it regardless of the purpose and target of use", so we will do something using the weather data.

Amedas point display

Although it is not the public data this time, first, let's display the AMeDAS point on the map.

Amedas point file download

Download the csv file for the AMeDAS site.

import os
import urllib.request

#Amedas point file download
url    = 'https://www.jma.go.jp/jma/kishou/know/amedas/ame_master.zip'
folder = 'amedas'
path   = 'amedas/ame_master.zip'
#Create folder
os.makedirs(folder, exist_ok=True)
if not os.path.exists(path):
    #download
    urllib.request.urlretrieve(url, path)

Data read

Load the data into pandas. You can also read directly in a zip file. Encoding settings are required.

import pandas as pd

#File reading
df = pd.read_csv('amedas/ame_master.zip', encoding='cp932')
#Data confirmation
df

Display Amedas points on the map

The downloaded AMeDAS point file contains the latitude and longitude of each point. Let's display the observatory points on the map using folium. The meteorological office is displayed in "red", and the AMeDAS point is displayed in "blue". The central point is "Tokyo". Please change as appropriate. Maps can be easily moved and scaled like other map apps. It's very convenient.

import folium

#Display Amedas points on a map
#Center point setting
po = 'Tokyo'  #Change to the point you want to check
po_df = df[df['Observatory name'] == po].iloc[0]
latitude  = po_df['latitude(Every time)'] + po_df['latitude(Minutes)']/60
longitude = po_df['longitude(Every time)'] + po_df['longitude(Minutes)']/60
map = folium.Map(location=[latitude, longitude], zoom_start=10)

#Set Amedas point
for index, row in df.iterrows():
    tooltip = row['Observatory name']
    if row['type'] == 'Government':
        #Meteorological office is red
        folium.Marker(location=[row['latitude(Every time)'] + row['latitude(Minutes)']/60, row['経Every time(Every time)'] + row['経Every time(Minutes)']/60], 
                      tooltip=tooltip, icon=folium.Icon(color='red')).add_to(map)
    else:
        #Amedas spot is blue
        folium.Marker(location=[row['latitude(Every time)'] + row['latitude(Minutes)']/60, row['経Every time(Every time)'] + row['経Every time(Minutes)']/60], 
                      tooltip=tooltip, icon=folium.Icon(color='blue')).add_to(map)
#Map display
map

The observatory name is displayed in the tooltip, but it is garbled in my Jupyter Notebook environment. When I saved it in html format and displayed it, it was displayed correctly.

#Save map
map.save(outfile="amedas_map.html")

Let's display the saved html.

map.png

First of all, I tried to display the Amedas point on the map.

The data will be released until the end of March 2020, so if you need it, we recommend you to download it as soon as possible.

Recommended Posts

Use of past meteorological data 1 (Display of AMeDAS points)
Use decorators to prevent re-execution of data processing
Data cleansing 3 Use of OpenCV and preprocessing of image data
Download the wind data of the Japan Meteorological Agency
Use data class for data storage of Python 3.7 or higher
About data preprocessing of systems that use machine learning
Let's use the open data of "Mamebus" in Python