Spaces:
Sleeping
Sleeping
File size: 4,628 Bytes
b9aa7ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
import streamlit as st
import geopandas as gpd
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from io import BytesIO
import requests
import folium
import zipfile
from streamlit.components.v1 import html
# Función para descargar y descomprimir el archivo
def download_and_extract_data():
url = 'https://fire.ak.blm.gov/content/maps/aicc/Data/Data%20(zipped%20Shapefiles)/CurrentYearLightning_SHP.zip'
response = requests.get(url)
zip_file = zipfile.ZipFile(BytesIO(response.content))
zip_file.extractall("CurrentYearLightning_SHP")
# Descargar y descomprimir los datos
st.title('Alaska Lightning Detection Network Analysis')
st.subheader('How its works: Explorar y comprender mejor la actividad de los rayos. ')
with st.spinner('Downloading and extracting data...'):
download_and_extract_data()
# Cargar el shapefile
shapefile_path = 'CurrentYearLightning_SHP/TOA_STRIKES.shp'
alaskaP = gpd.read_file(shapefile_path)
st.subheader('Current Year Lightning Strikes in Alaska')
m = folium.Map(location=[alaskaP['LATITUDE'].mean(), alaskaP['LONGITUDE'].mean()], zoom_start=6)
for _, row in alaskaP.iterrows():
folium.CircleMarker(
location=[row['LATITUDE'], row['LONGITUDE']],
radius=3,
weight=1,
color='red',
fill=True,
fill_color='red'
).add_to(m)
# Renderizar el mapa usando st.components.v1.html
folium_html = m._repr_html_()
html(folium_html, width=700, height=500)
# Convertir a datetime
alaskaP['STRIKETIME'] = pd.to_datetime(alaskaP['STRIKETIME'])
alaskaP['year'] = alaskaP['STRIKETIME'].dt.year
alaskaP['month'] = alaskaP['STRIKETIME'].dt.month
alaskaP['day'] = alaskaP['STRIKETIME'].dt.day
alaskaP['hour'] = alaskaP['STRIKETIME'].dt.hour
alaskaP['dayofweek'] = alaskaP['STRIKETIME'].dt.dayofweek
alaskaP['week'] = alaskaP['STRIKETIME'].dt.isocalendar().week
# Número de rayos por mes
st.subheader('Number of Lightning Strikes by Month')
fig, ax = plt.subplots()
sns.countplot(x='month', data=alaskaP, ax=ax)
ax.set_title('Number of Lightning Strikes by Month')
ax.set_xlabel('Month')
ax.set_ylabel('Count')
st.pyplot(fig)
# Número de rayos por día
st.subheader('Number of Lightning Strikes by Day')
fig, ax = plt.subplots()
sns.countplot(x='day', data=alaskaP, ax=ax)
ax.set_title('Number of Lightning Strikes by Day')
ax.set_xlabel('Day')
ax.set_ylabel('Count')
st.pyplot(fig)
# Distribución de tipos de rayos en un mapa
st.subheader('Lightning Strikes by Type')
fig, ax = plt.subplots()
alaskaP.plot(column="STROKETYPE", legend=True, ax=ax)
ax.set_title('Lightning Strikes by Type')
st.pyplot(fig)
# Número de rayos por día del año actual
st.subheader('Number of Lightning Strikes by Day in Current Year')
alaskaP['day'] = alaskaP['STRIKETIME'].dt.date
daily_counts = alaskaP['day'].value_counts().sort_index()
daily_counts.index = pd.to_datetime(daily_counts.index)
fig, ax = plt.subplots()
sns.lineplot(x=daily_counts.index, y=daily_counts.values, marker='o', ax=ax)
ax.set_title('Number of Lightning Strikes by Day')
ax.set_xlabel('Date')
ax.set_ylabel('Count')
ax.grid(True)
st.pyplot(fig)
# Número de rayos por hora en el año actual
st.subheader('Number of Lightning Strikes by Hour in Current Year')
current_year = alaskaP['year'].max()
daily_data = alaskaP[alaskaP['year'] == current_year]
hourly_counts = daily_data['hour'].value_counts().sort_index()
fig, ax = plt.subplots()
sns.lineplot(x=hourly_counts.index, y=hourly_counts.values, ax=ax)
ax.set_title('Number of Lightning Strikes by Hour in Current Year')
ax.set_xlabel('Hour of the Day')
ax.set_ylabel('Count')
ax.grid(True)
st.pyplot(fig)
# Número de rayos por día de la semana
st.subheader('Number of Lightning Strikes by Day of the Week')
alaskaP['day_of_week'] = alaskaP['STRIKETIME'].dt.dayofweek
day_of_week_counts = alaskaP['day_of_week'].value_counts().sort_index()
fig, ax = plt.subplots()
sns.barplot(x=day_of_week_counts.index, y=day_of_week_counts.values, ax=ax)
ax.set_title('Number of Lightning Strikes by Day of the Week')
ax.set_xlabel('Day of the Week')
ax.set_ylabel('Count')
ax.set_xticklabels(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'])
ax.grid(True)
st.pyplot(fig)
# Número de rayos por día en los últimos 10 días
st.subheader('Number of Lightning Strikes by Day in Last 10 Days')
last_10_days = daily_counts.tail(10)
fig, ax = plt.subplots()
sns.lineplot(x=last_10_days.index, y=last_10_days.values, marker='o', ax=ax)
ax.set_title('Number of Lightning Strikes by Day in Last 10 Days')
ax.set_xlabel('Date')
ax.set_ylabel('Count')
ax.grid(True)
st.pyplot(fig)
|