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