jordancaraballo commited on
Commit
f3bfd1e
·
1 Parent(s): d09c41a

Adding files from previous app, no images

Browse files
Home.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import streamlit as st
3
+ import rioxarray as rxr
4
+ # import cartopy.crs as ccrs
5
+
6
+ import matplotlib.pyplot as plt
7
+ import streamlit.components.v1 as components
8
+
9
+ from PIL import Image
10
+ from matplotlib.animation import FuncAnimation
11
+ # from huggingface_hub import hf_hub_download
12
+ # from streamlit_extras.badges import badge
13
+
14
+ st.set_page_config(
15
+ page_title="Home",
16
+ page_icon="🔥",
17
+ )
18
+
19
+ st.write("# FiRE-HNL Beta Dashboard")
20
+
21
+ st.sidebar.success("Select a page above.")
22
+
23
+ st.markdown(
24
+ f"""
25
+ This space was created to test several operational products
26
+ developed for Alaska fire occurrence modeling efforts.
27
+ Select a page from the sidebar to test some of the example
28
+ workflows developed as part of this research.
29
+
30
+ ## Objectives
31
+ Visualization and download of Alaska fire data. This dashboard
32
+ was tested during the 2023 fire season, and is being improved
33
+ for the 2024 fire season. Updates to the maps are done at 6 AM
34
+ local Alaska time.
35
+
36
+ ## Health Status
37
+ - WRF: Normal
38
+ - Lightning: Normal
39
+ - Ignition: In Development
40
+
41
+ ## Study Area
42
+ """
43
+ )
44
+
45
+ # set study area image in the dashboard
46
+ img = Image.open('images/study_area.jpeg')
47
+ st.image('https://files.blogs.illinois.edu/files/6367/265408/76088.jpg')#img)
48
+
49
+ st.markdown(
50
+ """
51
+ Figure 1. Study area.
52
+ """
53
+ )
54
+
55
+ st.markdown(
56
+ """
57
+ ## Feedback
58
+ We are seeking daily feedback on forecast potential. Feel free
59
+ to reach out directly if you have any feedback or if you have
60
+ additional features that would be useful to improve the information
61
+ provided here.
62
+
63
+ Curator Email: jacaraba@umd.edu
64
+ """
65
+ )
graveyard/old_home.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import streamlit as st
3
+ import rioxarray as rxr
4
+ import cartopy.crs as ccrs
5
+
6
+ import matplotlib.pyplot as plt
7
+ import streamlit.components.v1 as components
8
+
9
+ from matplotlib.animation import FuncAnimation
10
+ from huggingface_hub import hf_hub_download
11
+
12
+ st.set_page_config(
13
+ page_title="Home",
14
+ page_icon="👋",
15
+ )
16
+
17
+ st.write("# FiRE-HNL Beta Dashboard")
18
+
19
+ st.sidebar.success("Select a page above.")
20
+
21
+ st.markdown(
22
+ """
23
+ This space was created to test several operational products
24
+ developed for Alaska fire occurrence modeling efforts.
25
+ Select a page from the sidebar to test some of the example
26
+ workflows developed as part of this research.
27
+
28
+ ## Objectives
29
+ Visualization and download of Alaska lightning data.
30
+
31
+ ## Want to learn more?
32
+ - Feel free to contact us for additional details, jacaraba@umd.edu
33
+ """
34
+ )
35
+
36
+ """
37
+ # define dataset url
38
+ DATASET_URL = 'jordancaraballo/alaska-wildfire-occurrence'
39
+ EPSG = 3338
40
+
41
+ # Grab the dataset from Hugging Face
42
+ cgl_filename = hf_hub_download(
43
+ repo_id=DATASET_URL,
44
+ filename='alaskan-tundra-lightning-forecast_latest.tif',
45
+ repo_type="dataset")
46
+
47
+ # Open the filename from the forecast
48
+ cgl_ds = rxr.open_rasterio(cgl_filename)
49
+
50
+ # Rename bands with timestamps
51
+ cgl_ds['band'] = cgl_ds.attrs['DATES'].replace("'", "").strip('][').split(', ')
52
+
53
+ # Generate visualization
54
+ fig = plt.figure()
55
+ ax = plt.axes(projection=ccrs.epsg(EPSG))
56
+ ax.coastlines()
57
+
58
+ # Generate merge with cartipy
59
+ mesh = cgl_ds.isel(band=0).plot.pcolormesh(
60
+ ax=ax, transform=ccrs.epsg(EPSG),
61
+ animated=True, cmap='rainbow', vmin=0, vmax=1)
62
+
63
+
64
+ # Define update function
65
+ def update_mesh(t):
66
+ ax.set_title("time = %s" % t)
67
+ mesh.set_array(cgl_ds.sel(band=t).values.ravel())
68
+ return mesh,
69
+
70
+
71
+ # Generate animation function
72
+ animation = FuncAnimation(
73
+ fig, update_mesh, frames=cgl_ds.band.values, interval=600)
74
+ animation_js = animation.to_jshtml()
75
+ """
76
+
77
+ # Adding autoplay
78
+ #click_on_play = \
79
+ # """document.querySelector('.anim-buttons button[title="Play"]').click();"""
80
+
81
+ """
82
+ # Search for the creation of the animation within the jshtml file
83
+ pattern = re.compile(r"(setTimeout.*?;)(.*?})", re.MULTILINE | re.DOTALL)
84
+
85
+ # Insert the JS line right below that
86
+ animation_js = pattern.sub(rf"\1 \n {click_on_play} \2", animation_js)
87
+
88
+ # Plot text and animation on streamlit page
89
+ st.title("Alpha Version - Alaskan Tundra 10-day Lightning Forecast")
90
+ st.markdown(
91
+ "Cloud to ground lightning 10-day lightning forecast for the Alaskan " +
92
+ "tundra. This is still work in progress and under development.")
93
+
94
+ components.html(animation_js, height=1000)
95
+
96
+ """
packages.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gdal-bin
2
+ libgdal-dev
pages/1_⚡_Alaska_Lightning.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import leafmap.foliumap as leafmap
4
+ from glob import glob
5
+ from pathlib import Path
6
+ from datetime import date, timedelta
7
+ from huggingface_hub import hf_hub_download, snapshot_download
8
+
9
+ st.set_page_config(layout="wide")
10
+
11
+ markdown = """
12
+ FiRE-HNL Beta Dashboard
13
+ Validation of lightning probability maps during fire season 2024.
14
+ """
15
+
16
+ st.sidebar.title("About")
17
+ st.sidebar.info(markdown)
18
+ logo = "https://i.imgur.com/UbOXYAU.png"
19
+ st.sidebar.image(logo)
20
+
21
+ st.title(f"Lightning Forecast: {date.today()} to {timedelta(days=10) + date.today()}")
22
+
23
+ dataset_path = snapshot_download(
24
+ repo_id="loboda-umd/fire-hnl-lightning-2016",
25
+ #subfolder="2016-06-01_2016-06-11",
26
+ repo_type="dataset",
27
+ #filename='d02_2016-06-01_00-00-00_0-warp-lightning-clipped.tif'
28
+ #allow_patterns=["*.tif"]
29
+ )
30
+ print(dataset_path)
31
+
32
+ # define layers dict
33
+ options = sorted(glob(os.path.join(dataset_path, '*/*.tif')))
34
+
35
+ col1, col2 = st.columns([4, 1])
36
+
37
+ def format_filename(filename):
38
+ return f'{Path(filename).stem}'.split('_')[1]
39
+
40
+ # options = layers_dict #list(leafmap.basemaps.keys())
41
+ # print(options)
42
+ index = 0 #options.index("OpenTopoMap")
43
+
44
+ with col2:
45
+ current_forecast_date = st.selectbox("Current Forecast Window:", options, index, format_func=format_filename)
46
+ previous_forecast_date = st.selectbox("Previous Forecast Window:", options, index, format_func=format_filename)
47
+ legacy_forecast_date = st.selectbox("Legacy Examples:", options, index)
48
+ print(current_forecast_date)
49
+
50
+ m = leafmap.Map(
51
+ locate_control=True, latlon_control=True,
52
+ draw_export=True, minimap_control=True,
53
+ center=[30, -40],
54
+ zoom=13
55
+
56
+ )
57
+ m.add_basemap("OpenTopoMap")
58
+
59
+ with col1:
60
+
61
+ m.add_raster(
62
+ current_forecast_date,
63
+ bands=[1],
64
+ vmin=0,
65
+ vmax=100,
66
+ colormap='jet',
67
+ layer_name=Path(current_forecast_date).stem
68
+ )
69
+
70
+ # folium does not support this
71
+ # m.add_time_slider(layers_dict, time_interval=1)
72
+ m.to_streamlit(height=700)
pages/2_🌍_Alaska_WRF.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import leafmap.foliumap as leafmap
3
+ from glob import glob
4
+ from pathlib import Path
5
+
6
+ st.set_page_config(layout="wide")
7
+
8
+ markdown = """
9
+ FiRE-HNL Beta Dashboard
10
+ <https://github.com/opengeos/streamlit-map-template>
11
+ """
12
+
13
+ st.sidebar.title("About")
14
+ st.sidebar.info(markdown)
15
+ logo = "https://i.imgur.com/UbOXYAU.png"
16
+ st.sidebar.image(logo)
17
+
18
+
19
+ st.title("Interactive Lightning Forecast (10 days)")
20
+
21
+ # define layers dict
22
+ layers_dict = glob('/Users/jacaraba/Desktop/FiRE-HNL/all_rf_v3_2012-2022_oversampled_2/test-window/*-clipped.tif')
23
+
24
+ col1, col2 = st.columns([4, 1])
25
+ options = layers_dict#list(leafmap.basemaps.keys())
26
+ #print(options)
27
+ index = 0 #options.index("OpenTopoMap")
28
+
29
+ with col2:
30
+ current_forecast_date = st.selectbox("Current Forecast Window:", options, index)
31
+ previous_forecast_date = st.selectbox("Previous Forecast Window:", options, index)
32
+ wrf_variable = st.selectbox("WRF Variable:", options, index)
33
+
34
+ m = leafmap.Map(
35
+ locate_control=True, latlon_control=True,
36
+ draw_export=True, minimap_control=True,
37
+ center=[30, -40],
38
+ zoom=13
39
+
40
+ )
41
+ m.add_basemap("OpenTopoMap")
42
+
43
+ with col1:
44
+
45
+ m.add_raster(
46
+ current_forecast_date,
47
+ bands=[1],
48
+ vmin=0,
49
+ vmax=100,
50
+ colormap='jet',
51
+ layer_name=Path(current_forecast_date).stem
52
+ )
53
+
54
+ # folium does not support this
55
+ # m.add_time_slider(layers_dict, time_interval=1)
56
+ m.to_streamlit(height=700)
pages/3_🔥_Alaska_Ignition.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import folium
2
+ import streamlit as st
3
+ from folium.plugins import Draw
4
+ #from streamlit_folium import st_folium
5
+
6
+ #st.set_page_config(
7
+ # page_title="streamlit-folium documentation: Draw Support",
8
+ # page_icon=":pencil:",
9
+ # layout="wide",
10
+ #)
11
+
12
+ """
13
+ # streamlit-folium: Draw Support
14
+ Draw something below to see the return value back to Streamlit!
15
+ """
16
+
17
+ #with st.echo(code_location="below"):
18
+
19
+ # m = folium.Map(location=[39.949610, -75.150282], zoom_start=5)
20
+ # Draw(export=True).add_to(m)
21
+
22
+ # c1, c2 = st.columns(2)
23
+ # with c1:
24
+ # output = st_folium(m, width=700, height=500)
25
+
26
+ # with c2:
27
+ # st.write(output)
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --find-links=https://girder.github.io/large_image_wheels GDAL
2
+ geopandas
3
+ leafmap
4
+ owslib
5
+ streamlit
6
+ rioxarray
7
+ streamlit-extras
8
+ psutil
9
+ localtileserver
10
+ cartopy
11
+ geopandas
12
+ huggingface_hub