HURRICANE
Introduction
Software: Python Turtle
Hurricane is a project that writes code in Python Turtle and asks users to open the files of hurricanes and animate paths of hurricanes along their tracks ( figure1.0).
Goals:
Understanding loops, file i/o, string manipulation, and a start to graphics, write a program to process real-world hurricane data and animate the path of hurricanes.
Data & Image:
-
Image file from NASA
-
CSV data files from Weather Underground's website
.png)
figure 1.0 Tracks of hurricanes
Technical Breakdown
Step 1: Define a window_setup function
Define hurricane_setup function to setup window & image ( figure 2.0)
-
Create the screen, turtle, and turtle shape
-
Set up the background image of the Atlantic ocean
-
Set the coordinates of the screen to match the latitude and longitude on the map
.png)
figure 2.0 window_setup function
Step 2: Deal with data
There are five hurricane CSV files named "irma2017", "jose2017", "michael2018", "florence2018", "dorian2019" respectively.
Each file column is separated by commas. The data needed is Lat, Lon, and Wind (mph), Category. ( figure 3.0)
-
Lat, Lon dictate positions
-
Category can be printed (no value if Tropical Storm)
-
The wind can be used for turtle speed.
.png)

figure 3.0 File data
figure 4.0 Deal with file data
Define a hurricane function to read data in for loop and deal with data (figure 4.0)
-
Declare category of a hurricane
-
Declare wind_speed, get rid of "mph" by using [:-3], then turn them into values that fit turtle speed range from 0.5 - 10.
-
Turn string lat, long into floats, and declare the position.
Step 3: Category
Change the color and thickness of the line in proportion to the category
-
Red for category 5 | Orange for category 4 | Yellow for category 3 | Green for category 2 | Blue for category 1 | White if no hurricane strength


figure 5.0 Category
-
Use if statement to replace Tropical Hurricane category "-" with "0", and convert other categories 1- 5 into int values.
-
Use the if & Elif statement to change the color and thickness of tracks.
-
Use if statement to print category only when it changes
Now I get one colorful hurricane track as figure 6.0 shows.

figure 6.0 A hurricane track
Step 4: User input
Create a user_input function that allows users to input file names and hurricane paths drawn all in one window.
For this function, firstly users can choose the numbers of hurricanes they'd like to draw, they can type numbers ranging from 1 to 4, or they can simply type "all" to draw all hurricane tracks.
-
If users type "all", all five hurricanes will draw on the canvas one by one (loop the name list and call the hurricane function five times)
-
if users type a number "num", they will be asked to type a filename of the hurricane from a list, and this action will execute until hurricanes equal the user's input number at the beginning (input name and call hurricane function "num" times).
At the end of the programming, define the main function and call the user_input function inside it.
.png)
figure 7.0 user_input function
Step 5: Add labels
Add a label for each track of the hurricane to make a clearer visual ( figure 8.0)
-
The label is added at the end of the hurricane function, and print the name of the hurricane at the end of its tacking position.
.png)
figure 8.0 Add labels
Full Code
Here is the full code of the hurricane program
PDF Breakdown
Author: Yachan Yuan
Date: 24/4/2022