Wildfire rates for each of the 54 weeks of the year.
import geopandas as gpd
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
sns.set_theme(style='darkgrid')
# Wildland Fire Incident Locations data acquired from the National Interagency Fire Center
# https://data-nifc.opendata.arcgis.com/datasets/nifc::wildland-fire-incident-locations/about
gdf = gpd.read_file("../Data/Wildland_Fire_Incident_Locations.geojson")
gdf.head()
%%capture --no-stdout
# suppresses pandas warnings
df = pd.DataFrame()
df['Timestamp'] = gdf['FireDiscoveryDateTime']
df['Week/Year'] = df['Timestamp'].apply(lambda x: "%d/%d" % (x.week, x.year))
countdf = df.groupby(['Week/Year']).count()
count_dict = countdf.to_dict()['Timestamp']
week_count = {'2014': [0]*54,
'2015': [0]*54,
'2016': [0]*54,
'2017': [0]*54,
'2018': [0]*54,
'2019': [0]*54,
'2020': [0]*54,
'2021': [0]*54,
'2022': [0]*54}
for key, val in countdf.to_dict()['Timestamp'].items():
year = key[-4:]
if year in week_count:
week = int(key[:-5])
week_count[year][week - 1] = count_dict[key]
fig, ax = plt.subplots(1)
ax.stackplot(list(range(1,55)), *week_count.values(), labels=week_count.keys())
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[::-1], labels[::-1], title='Year', loc='upper right')
month_ticks = [x * 4.345 - 4.345/2 for x in range(1,13)]
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
plt.xticks(month_ticks, months, rotation=40)
plt.ylabel('Number of Incidents Reported')
plt.tight_layout()
plt.savefig('Incidents_Stacked.png', dpi=300)
mean_year = pd.DataFrame(week_count).mean(axis=1)
for key, val in week_count.items():
plt.plot(val, color='maroon', alpha=0.2)
plt.plot(mean_year, label='Mean')
plt.legend()
plt.xticks(month_ticks, months, rotation=40)
plt.ylabel('Number of Incidents Reported')
plt.tight_layout()
plt.savefig('Incidents_Mean.png', dpi=300)