Spaces:
Configuration error
Configuration error
Delete visualization.py
Browse files- visualization.py +0 -105
visualization.py
DELETED
@@ -1,105 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import folium
|
3 |
-
from folium.plugins import Draw, Fullscreen, MeasureControl
|
4 |
-
import plotly.express as px
|
5 |
-
import plotly.graph_objects as go
|
6 |
-
import base64
|
7 |
-
import pandas as pd
|
8 |
-
import geemap.foliumap as geemap
|
9 |
-
|
10 |
-
def create_map(center_lat, center_lon, zoom=13):
|
11 |
-
"""Create a folium map centered at the specified coordinates"""
|
12 |
-
m = geemap.Map()
|
13 |
-
m.set_center(center_lon, center_lat, zoom)
|
14 |
-
m.add_basemap('HYBRID')
|
15 |
-
return m
|
16 |
-
|
17 |
-
def add_index_layer(m, image, index_name, vis_params, layer_name):
|
18 |
-
"""Add an index layer to the map"""
|
19 |
-
if image is not None:
|
20 |
-
m.add_layer(image.select(index_name), vis_params, layer_name)
|
21 |
-
return m
|
22 |
-
|
23 |
-
def get_map_download_link(m, filename="map.html"):
|
24 |
-
"""Generate a download link for the map"""
|
25 |
-
m.to_html(filename)
|
26 |
-
with open(filename, 'rb') as f:
|
27 |
-
html_data = f.read()
|
28 |
-
|
29 |
-
b64 = base64.b64encode(html_data).decode()
|
30 |
-
href = f'<a href="data:text/html;base64,{b64}" download="{filename}">Download Map</a>'
|
31 |
-
return href
|
32 |
-
|
33 |
-
def create_comparison_chart(comparison_df, indices):
|
34 |
-
"""Create a bar chart comparing indices across farms"""
|
35 |
-
if len(comparison_df) > 1: # If more than one farm is selected
|
36 |
-
fig = go.Figure()
|
37 |
-
|
38 |
-
for index_name in indices:
|
39 |
-
if index_name in comparison_df.columns:
|
40 |
-
fig.add_trace(go.Bar(
|
41 |
-
x=comparison_df['مزرعه'],
|
42 |
-
y=comparison_df[index_name],
|
43 |
-
name=index_name
|
44 |
-
))
|
45 |
-
|
46 |
-
fig.update_layout(
|
47 |
-
title="Farm Index Comparison",
|
48 |
-
xaxis_title="Farm",
|
49 |
-
yaxis_title="Index Value",
|
50 |
-
barmode='group'
|
51 |
-
)
|
52 |
-
|
53 |
-
return fig
|
54 |
-
return None
|
55 |
-
|
56 |
-
def create_time_series_chart(time_series_df, index_name, farm_id):
|
57 |
-
"""Create a line chart showing index values over time"""
|
58 |
-
if time_series_df is not None and not time_series_df.empty:
|
59 |
-
fig = px.line(time_series_df, x='Date', y=index_name,
|
60 |
-
title=f"{index_name} Time Series for Farm {farm_id}")
|
61 |
-
fig.update_layout(xaxis_title="Date", yaxis_title=index_name)
|
62 |
-
return fig
|
63 |
-
return None
|
64 |
-
|
65 |
-
def display_color_legend(selected_index):
|
66 |
-
"""Display a color legend for the selected index"""
|
67 |
-
st.subheader("Color Legend")
|
68 |
-
|
69 |
-
if selected_index in ['NDVI', 'EVI']:
|
70 |
-
st.markdown("""
|
71 |
-
- <span style='color:red'>Red</span>: Poor condition (0.0-0.2)
|
72 |
-
- <span style='color:yellow'>Yellow</span>: Moderate condition (0.2-0.5)
|
73 |
-
- <span style='color:green'>Green</span>: Good condition (0.5-0.8)
|
74 |
-
""", unsafe_allow_html=True)
|
75 |
-
elif selected_index == 'NDMI':
|
76 |
-
st.markdown("""
|
77 |
-
- <span style='color:red'>Red</span>: Dry (0.0-0.2)
|
78 |
-
- <span style='color:yellow'>Yellow</span>: Moderate moisture (0.2-0.5)
|
79 |
-
- <span style='color:blue'>Blue</span>: High moisture (0.5-0.8)
|
80 |
-
""", unsafe_allow_html=True)
|
81 |
-
elif selected_index in ['LAI', 'Biomass']:
|
82 |
-
st.markdown("""
|
83 |
-
- <span style='color:white; background-color:black'>White</span>: Low value (0-1)
|
84 |
-
- <span style='color:lightgreen'>Light green</span>: Moderate value (1-3)
|
85 |
-
- <span style='color:darkgreen'>Dark green</span>: High value (3-5)
|
86 |
-
""", unsafe_allow_html=True)
|
87 |
-
elif selected_index == 'MSI':
|
88 |
-
st.markdown("""
|
89 |
-
- <span style='color:blue'>Blue</span>: Low stress (0-0.6)
|
90 |
-
- <span style='color:yellow'>Yellow</span>: Moderate stress (0.6-1.2)
|
91 |
-
- <span style='color:red'>Red</span>: High stress (1.2-2.0)
|
92 |
-
""", unsafe_allow_html=True)
|
93 |
-
elif selected_index == 'Chlorophyll':
|
94 |
-
st.markdown("""
|
95 |
-
- <span style='color:white; background-color:black'>White</span>: Low chlorophyll (0-1)
|
96 |
-
- <span style='color:yellow'>Yellow</span>: Moderate chlorophyll (1-3)
|
97 |
-
- <span style='color:green'>Green</span>: High chlorophyll (3-5)
|
98 |
-
""", unsafe_allow_html=True)
|
99 |
-
|
100 |
-
def get_download_link(df, filename, link_text):
|
101 |
-
"""Generate a download link for a dataframe"""
|
102 |
-
csv = df.to_csv(index=False)
|
103 |
-
b64 = base64.b64encode(csv.encode()).decode()
|
104 |
-
href = f'<a href="data:file/csv;base64,{b64}" download="{filename}">{link_text}</a>'
|
105 |
-
return href
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|