Skip to content

Instantly share code, notes, and snippets.

@cavedave
Created September 30, 2019 14:26
Show Gist options
  • Save cavedave/78cd17a3d8ec038329ee2de36775c168 to your computer and use it in GitHub Desktop.
Save cavedave/78cd17a3d8ec038329ee2de36775c168 to your computer and use it in GitHub Desktop.
Where hurricances became cat since 1967 when satellites could see them in the sea reliably. This is a copy of this map https://twitter.com/philklotzbach/status/1178137123687284737 by Philip Klotzbach but I couldn't find his code so I made my own. Data from https://www.nhc.noaa.gov/data/hurdat/hurdat2-1851-2018-051019.txt
#The start of this file is from https://www.reddit.com/r/CodingHelp/comments/9jguwj/help_with_python_data_analsyis/
#Specifically David Kopp http://www.cis.umassd.edu/~dkoop/ where he ingets the noaa data
import os
from urllib.request import urlretrieve
# download the data if we don't have it locally
url = "https://www.nhc.noaa.gov/data/hurdat/hurdat2-1851-2017-050118.txt"
local_fname = "hurdat2.txt"
if not os.path.exists("hurdat2.txt"):
urlretrieve(url, local_fname)
# very primtive way of reading the data
# can be improved
records = []
with open(local_fname,'r') as f:
for line in f:
if line.startswith("AL"):
record = line.strip()
reports = []
records.append((record, reports))
else:
reports.append(line.strip())
records
#Now get when wind goes over 130 knots
j=0
while j< len(records):
i=0
while i < len(records[j][1]):
testsplit=records[j][1][i].split(',')
speed=testsplit[6].lstrip()
if int(speed) >130:
print(records[j][0])
print(testsplit[4],testsplit[5],testsplit[6])
i=i+1
j=j+1
library("ggplot2")
theme_set(theme_bw())
library("sf")
library(tmap)
library("rnaturalearth")
library("rnaturalearthdata")
world <- ne_countries(scale = "medium", returnclass = "sf")
class(world)
ggplot(data = world) +
geom_sf() +
coord_sf(xlim = c(-5, -100), ylim = c(5, 45), expand = FALSE)+
ggtitle("Where Hurricanes became Cat 5",
subtitle = "sustained wind speeds > 136 knots. Since 1967")+
theme(
axis.title.x = element_blank(),plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5),
axis.title.y = element_blank(), axis.text.x = element_blank(),
axis.text.y = element_blank(),axis.ticks = element_blank())+
#AL031965, BETSY, 69, 28.3N 89.2W 135
annotate("point", x = -96, y =23.9, colour = "red", size = 2)+
# 24.3N 86.6W
annotate("point", x = -86.6, y =24.4, colour = "red", size = 2)+
#14.8N 83.2W
annotate("point", x = -83.2, y =14.8, colour = "red", size = 2)+
#AL051977, ANITA, 20,
# 24.6N 96.2W 140
annotate("point", x = -96.2, y =24.6, colour = "red", size = 2)+
#AL091979, DAVID, 55,
# 16.0N 64.2W 140
annotate("point", x = -64.2, y =16, colour = "red", size = 2)+
#AL041980, ALLEN, 46,
# 14.8N 66.7W 140
annotate("point", x = -66.7, y =14.8, colour = "red", size = 2)+
#AL081988, GILBERT, 49,
# 19.4N 82.5W 140
annotate("point", x = -82.5, y =19.4, colour = "red", size = 2)+
#AL111989, HUGO, 64,
# 14.6N 54.6W 140
annotate("point", x = -54.6, y =14.6, colour = "red", size = 2)+
# AL041992, ANDREW, 52,
# 25.4N 74.2W 145
annotate("point", x = -74.2, y =25.4, colour = "red", size = 2)+
#AL071998, GEORGES, 71,
#16.0N 56.3W 135
annotate("point", x = -56.3, y =16, colour = "red", size = 2)+
#AL131998, MITCH, 78,
# 16.4N 81.8W 135
annotate("point", x = -81.8, y =16.4, colour = "red", size = 2)+
#AL081999, FLOYD, 50,
#23.6N 70.0W 135
annotate("point", x = -70, y =23.6, colour = "red", size = 2)+
#AL161999, LENNY, 39,
#17.4N 64.8W 135
annotate("point", x = -64.8, y =17.4, colour = "red", size = 2)+
#AL132003, ISABEL, 58,
# 21.4N 54.0W 135
annotate("point", x = -54, y =21.4, colour = "red", size = 2)+
#AL092004, IVAN, 94,
# 13.7N 69.5W 140
annotate("point", x = -69.5, y =13.7, colour = "red", size = 2)+
#AL052005, EMILY, 45,
# 16.4N 78.0W 135
annotate("point", x = -78, y =16.4, colour = "red", size = 2)+
#AL122005, KATRINA, 34,
# 25.7N 87.7W 145
annotate("point", x = -87.7, y =25.7, colour = "red", size = 2)+
#AL182005, RITA, 36,
# 24.3N 86.2W 145
annotate("point", x = -86.2, y =24.3, colour = "red", size = 2)+
#AL252005, WILMA, 48,
# 17.0N 82.2W 150
annotate("point", x = -82.2, y =17, colour = "red", size = 2)+
#AL042007, DEAN, 42,
# 15.4N 68.0W 145
annotate("point", x = -68, y =15.4, colour = "red", size = 2)+
#AL062007, FELIX, 28,
# 13.8N 73.0W 150
annotate("point", x = -73, y =13.8, colour = "red", size = 2)+
#AL072008, GUSTAV, 50,
# 22.4N 83.1W 135
annotate("point", x = -83.1, y =22.4, colour = "red", size = 2)+
#AL112010, IGOR, 61,
# 18.9N 53.5W 135
annotate("point", x = -53.5, y =18.9, colour = "red", size = 2)+
#AL112015, JOAQUIN, 76,
# 25.4N 72.6W 135
annotate("point", x = -72.6, y =25.4, colour = "red", size = 2)+
#AL142016, MATTHEW, 50,
# 13.4N 71.9W 145
annotate("point", x = -71.9, y =13.4, colour = "red", size = 2)+
#AL112017, IRMA, 66,
# 16.6N 56.4W 135
annotate("point", x = -56.4, y =16.6, colour = "red", size = 2)+
#AL122017, JOSE, 85,
# 16.4N 57.8W 135
annotate("point", x = -57.8, y =16.4, colour = "red", size = 2)+
#AL152017, MARIA, 68,
#15.3N 61.1W 145
annotate("point", x = -61.1, y =15.3, colour = "red", size = 2)+
#Michael 30.2 85.4 https://www.nhc.noaa.gov/data/tcr/AL142018_Michael.pdf
annotate("point", x = -85.4, y =30.2, colour = "red", size = 2)+
#dorian latitude 26.5 North, longitude 76.5 West https://www.nhc.noaa.gov/archive/2019/al05/al052019.public_a.032.shtml
annotate("point", x = -76.5, y =26.5, colour = "red", size = 2)+
#lorenzo LOCATION...24.1N 45.0W https://www.nhc.noaa.gov/archive/2019/al13/al132019.update.09290207.shtml?
annotate("point", x = -45, y =24, colour = "blue", size = 3)+
annotate("text", x = -44, y =23, colour = "blue", size = 3, label="Lorenzo")+
#annotate("text", x = 25, y =36, colour = "black", size = 2.5, label="@iamreddave eurostat data ")+
ggsave("Hurricanes2.png", width = 15, height = 20, units = "cm")
@cavedave
Copy link
Author

Hurricanes2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment