[Python] I wrote the route of the typhoon on the map using folium

Article content

Did typhoons occur so often when you were a kid? Did a typhoon come to Japan around October? There was a vague question. I wanted to be able to solve this question using the data on typhoons released by the Japan Meteorological Agency, so I tried various things.

Data acquisition source

Obtained from a data catalog site operated by the government.

Data Catalog Site

Weather forecast_Weather forecast / Typhoon data Use "Typhoon Position Table CSV Data" on this page.

In this article, I used the CSV data from 2001 to 2019 posted in the link.

Try to write the route of the typhoon on the map using folium

Preparation

The header of the CSV data was Japanese, so I changed it to English. Quite suitable

year,month,day,hour(UTC),typhoon_no,typhoon_name,rank,latitude,longitude,central_pressure,max_wind_speed,50KT_LDD,50KT_LD,50KT_MA,30KT_LDD,30KT_LD,30KT_MA,landing

code

I haven't really devised it

import folium
import pandas as pd

pd.options.display.precision = 3

# Year of start and end
start_year = 2001
end_year = 2019

# Process on a yearly basis
for year in range(start_year, end_year+1):
    print('# ' + str(year) + ' year start')
 #Reading data
    df = pd.read_csv('./typhoon/table' + str(year) + '.csv',encoding="SHIFT-JIS")
    typhoon_names = list(df['typhoon_name'])
    latitude = list(df["latitude"])
    longitude = list(df["longitude"])
    landing = list(df["landing"])

    map = folium.Map(location=[35.6611098,139.6953576], zoom_start=3)

    target_typhoon = typhoon_names[0]
    target_location = []
    color = 'blue'
    typhoon_count = 0

 #Process CSV data line by line
    for lt, lo, name, land in zip(latitude, longitude, typhoon_names, landing):
 # If the name of the typhoon changes, write the information of the typhoon being processed on the map
        if name != target_typhoon:
            map.add_child(folium.PolyLine(locations=target_location, color=color))
            target_location = [[float(lt), float(lo)]]
            target_typhoon = name
            typhoon_count += 1
        else:
            target_location.append([float(lt), float(lo)])

    map.add_child(folium.PolyLine(locations=target_location, color=color))
    map.save('./output/' + str(year) + '_typhoon_location.html')
    print('# Number of typhoon : ' + str(typhoon_count))
    print('# ' + str(year) + ' year end')

Output result

The output result is output under the "output" folder every year. When you open the output HTML, it looks like this. 2019_typhoon.png I made a GIF that displays the output image from 2001 to 2019. typhoon.gif

Typhoon landing in Japan tries to change the color of the line

After all, I want to make the typhoon that landed in Japan stand out. There was an item called "landing" in the final item of the data. It is 1 if it has landed, and 0 if it has not. This data is used for color coding.

It should be noted that this "landing" is not "in Japan". Therefore, it was necessary to judge whether it was Japan or not.

code

import folium
import pandas as pd

pd.options.display.precision = 3

# Year of start and end
start_year = 2001
end_year = 2019

# Coordinates of the north, south, east and west edges of Japan
east_end = 153.5911
west_end = 122.5601
north_end = 45.3326
south_end = 20.2531

def is_japan_randing(lt, lo, randing):
    if south_end <= lt and lt <= north_end and west_end <= lo and lo <= east_end and randing == 1:
        return True
    else:
        return False

# Process on a yearly basis
for year in range(start_year, end_year+1):
    print('# ' + str(year) + ' year start')
 #Reading data
    df = pd.read_csv('./typhoon/table' + str(year) + '.csv',encoding="SHIFT-JIS")
    typhoon_names = list(df['typhoon_name'])
    latitude = list(df["latitude"])
    longitude = list(df["longitude"])
    landing = list(df["landing"])

    map = folium.Map(location=[35.6611098,139.6953576], zoom_start=3)

    target_typhoon = typhoon_names[0]
    target_location = []
    typhoon_count = 0
    color = 'blue'
    
 #Process CSV data line by line
    for lt, lo, name, land in zip(latitude, longitude, typhoon_names, landing):
 # If the name of the typhoon changes, write the information of the typhoon being processed on the map
        if name != target_typhoon:
            map.add_child(folium.PolyLine(locations=target_location, color=color))
            target_location = [[float(lt), float(lo)]]
            target_typhoon = name
            typhoon_count += 1
            color = 'blue'
        else:
            target_location.append([float(lt), float(lo)])
            if is_japan_randing(lt, lo, land):
                color = 'red'

    map.add_child(folium.PolyLine(locations=target_location, color=color))
    map.save('./output/' + str(year) + '_typhoon_location.html')
    print('# Number of typhoon : ' + str(typhoon_count))
    print('# ' + str(year) + ' year end')

Judgment in Japan is made in "is_japan_randing". I think it's very rough, but is the latitude in the northernmost and southernmost range of Japan? Is longitude the westernmost and easternmost range? Is judged.

result

2019_color.png Only the line landing in Japan turned red. There are lines that are quite close to Kyushu and Honshu. Below is a quote from Weather.com.

Typhoon landing means that the center of the typhoon reaches the coasts of Hokkaido, Honshu, Kyushu, and Shikoku. (Okinawa is not called a landing of a typhoon, but a passing.) An approaching typhoon means entering within a radius of 300 km.

Thinking this way, you can see again that this line is the coordinates of the center.

At the end

Did such a typhoon land in Japan in recent years? I tried this from the question, but it seems that the number of landings has not changed much since 2001. Next, I would like to visualize the scale of the typhoon.

Recommended Posts

[Python] I wrote the route of the typhoon on the map using folium
I wrote the basic grammar of Python with Jupyter Lab
[Python] I tried collecting data using the API of wikipedia
I wrote the queue in Python
I wrote the stack in Python
I wrote the code to write the code of Brainf * ck in python
I didn't know the basics of Python
The Python project template I think of.
Study on Tokyo Rent Using Python (3-1 of 3)
[Python beginner] I collected the articles I wrote
Get images of great find / 47 sites using Python (Part 2/2: I published the target list on github)
[Python, ObsPy] I drew a beach ball on the map with Cartopy + ObsPy.
I tried cluster analysis of the weather map
vprof --I tried using the profiler for Python
Python: Try using the UI on Pythonista 3 on iPad
Compare the speed of Python append and map
Folium: Visualize data on a map with Python
Try the free version of Progate [Python I]
I tried using the Datetime module by Python
I touched some of the new features of Python 3.8 ①
Sound the buzzer using python on Raspberry Pi 3!
Try using the collections module (ChainMap) of python3
Find the geometric mean of n! Using Python
At the time of python update on ubuntu
Operate Route53 on the command line using AWS-CLI.
I tried using the image filter of OpenCV
I want to use Python in the environment of pyenv + pipenv on Windows 10
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
Plot the environmental concentration of organofluorine compounds on a map using open data
I made a script to record the active window using win32gui of Python
I tried to display the infection condition of coronavirus on the heat map of seaborn
[Trainer's Recipe] I touched the flame of the Python framework.
Explanation of the concept of regression analysis using python Part 2
Basics of I / O screen using tkinter in python3
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
I tried Python on Mac for the first time.
Cut a part of the string using a Python slice
I tried to draw a route map with Python
Python practice 100 knocks I tried to visualize the decision tree of Chapter 5 using graphviz
Maybe I overestimated the impact of ShellShock on CGI
the zen of Python
I tried python on heroku for the first time
Drawing on Jupyter using the plot function of pandas
The pain of gRPC using Python. November 2019. (Personal memo)
I checked out the versions of Blender and Python
I want to take a screenshot of the site on Docker using any font
Explanation of the concept of regression analysis using Python Part 1
I tried using the API of the salmon data project
Explanation of the concept of regression analysis using Python Extra 1
Study from the beginning of Python Hour8: Using packages
I tried using Python (3) instead of a scientific calculator
I tried using folium
I tried using folium
I tried to summarize the string operations of Python
I wrote a Python script that exports all my posts using the Qiita API v2
How to know the number of GPUs from python ~ Notes on using multiprocessing with pytorch ~
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried to find the entropy of the image with python
I tried "gamma correction" of the image with Python + OpenCV
I tried the accuracy of three Stirling's approximations in python
I tried using the Python library from Ruby with PyCall