|
@ -1,8 +1,9 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
|
|
|
import csv |
|
|
import csv |
|
|
from dataclasses import dataclass |
|
|
|
|
|
|
|
|
from dataclasses import dataclass, field |
|
|
from datetime import datetime |
|
|
from datetime import datetime |
|
|
|
|
|
from typing import List |
|
|
|
|
|
|
|
|
import cartopy.crs as ccrs |
|
|
import cartopy.crs as ccrs |
|
|
import matplotlib.pyplot as plt |
|
|
import matplotlib.pyplot as plt |
|
@ -73,6 +74,7 @@ class Tornado: |
|
|
self.slat = float(self.slat) |
|
|
self.slat = float(self.slat) |
|
|
self.elon = float(self.elon) |
|
|
self.elon = float(self.elon) |
|
|
self.elat = float(self.elat) |
|
|
self.elat = float(self.elat) |
|
|
|
|
|
self.mag = int(self.mag) |
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
def __repr__(self): |
|
|
return "<tornado {id} {date}>".format(id=self.id, date=self.dt) |
|
|
return "<tornado {id} {date}>".format(id=self.id, date=self.dt) |
|
@ -87,34 +89,76 @@ def read_data(): |
|
|
return tornados |
|
|
return tornados |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def draw_map(lons, lats): |
|
|
|
|
|
|
|
|
def draw_map(f_unknown, f_zero, f_one, f_two, f_three, f_four, f_five): |
|
|
fig = plt.figure(frameon=False, figsize=(8, 4.61)) |
|
|
fig = plt.figure(frameon=False, figsize=(8, 4.61)) |
|
|
ax = fig.add_axes([0, 0, 1, 1], projection=proj) |
|
|
ax = fig.add_axes([0, 0, 1, 1], projection=proj) |
|
|
ax.background_patch.set_facecolor(water_blue) |
|
|
ax.background_patch.set_facecolor(water_blue) |
|
|
ax.set_extent([-122, -65, 20, 50], ccrs.Geodetic()) |
|
|
ax.set_extent([-122, -65, 20, 50], ccrs.Geodetic()) |
|
|
ax.add_feature(land, facecolor="#f0f0f0") |
|
|
ax.add_feature(land, facecolor="#f0f0f0") |
|
|
ax.add_feature(rivers, edgecolor=water_blue) |
|
|
|
|
|
|
|
|
# ax.add_feature(rivers, edgecolor=water_blue) |
|
|
ax.add_feature(lakes, facecolor=water_blue) |
|
|
ax.add_feature(lakes, facecolor=water_blue) |
|
|
|
|
|
|
|
|
ax.add_feature(countries, edgecolor="grey", linewidth=0.2, alpha=0.6, dashes='--') |
|
|
ax.add_feature(countries, edgecolor="grey", linewidth=0.2, alpha=0.6, dashes='--') |
|
|
ax.add_feature(states, edgecolor="grey", linewidth=0.2, alpha=0.4, dashes='--') |
|
|
ax.add_feature(states, edgecolor="grey", linewidth=0.2, alpha=0.4, dashes='--') |
|
|
|
|
|
|
|
|
ax.plot(lons, lats, 'r', lw=0.2, alpha=0.7, transform=ccrs.Geodetic()) |
|
|
|
|
|
|
|
|
geodetic = ccrs.Geodetic() |
|
|
|
|
|
ax.plot(f_unknown.lons, f_unknown.lats, 'k', lw=0.2, alpha=0.7, label="Unknown", transform=geodetic) |
|
|
|
|
|
ax.plot(f_zero.lons, f_zero.lats, '#ffbb00', lw=0.1, alpha=1, label="F0", transform=geodetic) |
|
|
|
|
|
ax.plot(f_one.lons, f_one.lats, '#ff7700', lw=0.1, alpha=1, label="F1", transform=geodetic) |
|
|
|
|
|
ax.plot(f_two.lons, f_two.lats, '#ff4400', lw=0.2, alpha=0.8, label="F2", transform=geodetic) |
|
|
|
|
|
ax.plot(f_three.lons, f_three.lats, '#ff1100', lw=0.3, alpha=0.8, label="F3", transform=geodetic) |
|
|
|
|
|
ax.plot(f_four.lons, f_four.lats, 'r', lw=0.4, alpha=0.8, label="F4", transform=geodetic) |
|
|
|
|
|
ax.plot(f_five.lons, f_five.lats, 'r', lw=0.6, alpha=0.7, label="F5", transform=geodetic) |
|
|
|
|
|
|
|
|
ax.axis('off') |
|
|
ax.axis('off') |
|
|
|
|
|
|
|
|
|
|
|
plt.legend(loc=4, title="Intensity", fontsize='small') |
|
|
plt.savefig("tornados_us.png", dpi=320) |
|
|
plt.savefig("tornados_us.png", dpi=320) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass |
|
|
|
|
|
class Fmag: |
|
|
|
|
|
lons: List[int] = field(default_factory=list) |
|
|
|
|
|
lats: List[int] = field(default_factory=list) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def append(collection, tornado): |
|
|
|
|
|
collection.lons.append(tornado.slon) |
|
|
|
|
|
collection.lats.append(tornado.slat) |
|
|
|
|
|
if tornado.elon < 0: |
|
|
|
|
|
collection.lons.append(tornado.elon) |
|
|
|
|
|
collection.lats.append(tornado.elat) |
|
|
|
|
|
else: |
|
|
|
|
|
collection.lons.append(tornado.slon) |
|
|
|
|
|
collection.lats.append(tornado.slat) |
|
|
|
|
|
collection.lons.append(None) |
|
|
|
|
|
collection.lats.append(None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
ts = read_data() |
|
|
ts = read_data() |
|
|
lons = [] |
|
|
|
|
|
lats = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f_unknown = Fmag() |
|
|
|
|
|
f_zero = Fmag() |
|
|
|
|
|
f_one = Fmag() |
|
|
|
|
|
f_two = Fmag() |
|
|
|
|
|
f_three = Fmag() |
|
|
|
|
|
f_four = Fmag() |
|
|
|
|
|
f_five = Fmag() |
|
|
for t in ts: |
|
|
for t in ts: |
|
|
if t.elon < 0: |
|
|
|
|
|
lons.append(t.slon) |
|
|
|
|
|
lons.append(t.elon) |
|
|
|
|
|
lons.append(None) |
|
|
|
|
|
lats.append(t.slat) |
|
|
|
|
|
lats.append(t.elat) |
|
|
|
|
|
lats.append(None) |
|
|
|
|
|
draw_map(lons, lats) |
|
|
|
|
|
|
|
|
if t.mag == 0: |
|
|
|
|
|
append(f_zero, t) |
|
|
|
|
|
elif t.mag == 1: |
|
|
|
|
|
append(f_one, t) |
|
|
|
|
|
elif t.mag == 2: |
|
|
|
|
|
append(f_two, t) |
|
|
|
|
|
elif t.mag == 3: |
|
|
|
|
|
append(f_three, t) |
|
|
|
|
|
elif t.mag == 4: |
|
|
|
|
|
append(f_four, t) |
|
|
|
|
|
elif t.mag == 5: |
|
|
|
|
|
append(f_five, t) |
|
|
|
|
|
else: |
|
|
|
|
|
append(f_unknown, t) |
|
|
|
|
|
|
|
|
|
|
|
draw_map(f_unknown, f_zero, f_one, f_two, f_three, f_four, f_five) |