Spaces:
Sleeping
Sleeping
Upload New Text Document (4).txt
Browse files- New Text Document (4).txt +87 -0
New Text Document (4).txt
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def app():
|
2 |
+
st.title("Google Earth Engine Maps and Graphs")
|
3 |
+
dataset_info, _ = data_gee()
|
4 |
+
available_datasets = dataset_info['id'].tolist()
|
5 |
+
|
6 |
+
selected_dataset = st.selectbox(
|
7 |
+
"Select Dataset",
|
8 |
+
['AAFC/ACI','NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG',"MODIS/006/MOD44B"]
|
9 |
+
)
|
10 |
+
|
11 |
+
map_html = create_folium_map(selected_dataset)
|
12 |
+
st.components.v1.html(map_html, height=600, width=800)
|
13 |
+
uploaded_file_nighttime = st.file_uploader("Upload a KML file or other supported format", key='nighttime_file')
|
14 |
+
location_name_nighttime = st.text_input("Enter a location (e.g., Karachi, London)", key='nighttime_location')
|
15 |
+
start_date_nighttime = st.date_input("Start date", value=pd.to_datetime('2021-01-01'), key='nighttime_start_date')
|
16 |
+
end_date_nighttime = st.date_input("End date", value=pd.to_datetime('2021-12-31'), key='nighttime_end_date')
|
17 |
+
|
18 |
+
if uploaded_file_nighttime:
|
19 |
+
try:
|
20 |
+
gdf = uploaded_file_to_gdf(uploaded_file_nighttime)
|
21 |
+
st.session_state["roi"] = geemap.gdf_to_ee(gdf, geodesic=False)
|
22 |
+
st.write("ROI added to session state.")
|
23 |
+
|
24 |
+
coordinates = gdf.geometry.centroid.iloc[0].coords[0]
|
25 |
+
folium_map = create_folium_map_with_data('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG', gdf)
|
26 |
+
st.components.v1.html(folium_map._repr_html_(), height=600, width=800)
|
27 |
+
|
28 |
+
if start_date_nighttime and end_date_nighttime:
|
29 |
+
fig = create_nighttime_lights_time_series(coordinates, start_date_nighttime.isoformat(), end_date_nighttime.isoformat())
|
30 |
+
plot_nighttime_lights_with_controls(fig)
|
31 |
+
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
st.error(f"Error processing the file: {e}")
|
35 |
+
st.error("Please upload another file and try again.")
|
36 |
+
else:
|
37 |
+
if location_name_nighttime:
|
38 |
+
try:
|
39 |
+
coordinates = get_coordinates(location_name_nighttime)
|
40 |
+
|
41 |
+
if start_date_nighttime and end_date_nighttime:
|
42 |
+
fig = create_nighttime_lights_time_series(coordinates, start_date_nighttime.isoformat(), end_date_nighttime.isoformat())
|
43 |
+
st.plotly_chart(fig)
|
44 |
+
|
45 |
+
except Exception as e:
|
46 |
+
st.error(f"Error processing location data: {e}")
|
47 |
+
|
48 |
+
# NDVI Time Series
|
49 |
+
st.title('NDVI Time Series')
|
50 |
+
uploaded_file_ndvi = st.file_uploader("Upload a KML file or other supported format", key='ndvi_file')
|
51 |
+
location_name_ndvi = st.text_input("Enter a location for NDVI (e.g., Karachi, London)", key='ndvi_location')
|
52 |
+
start_date_ndvi = st.date_input("Start date for NDVI", value=pd.to_datetime('2021-01-01'), key='ndvi_start_date')
|
53 |
+
end_date_ndvi = st.date_input("End date for NDVI", value=pd.to_datetime('2021-12-31'), key='ndvi_end_date')
|
54 |
+
|
55 |
+
if uploaded_file_ndvi:
|
56 |
+
try:
|
57 |
+
gdf = uploaded_file_to_gdf(uploaded_file_ndvi)
|
58 |
+
st.session_state["roi"] = geemap.gdf_to_ee(gdf, geodesic=False)
|
59 |
+
st.write("ROI added to session state.")
|
60 |
+
|
61 |
+
coordinates = gdf.geometry.centroid.iloc[0].coords[0]
|
62 |
+
folium_map = create_folium_map_with_data('MODIS/006/MOD44B', gdf)
|
63 |
+
st.components.v1.html(folium_map._repr_html_(), height=600, width=800)
|
64 |
+
|
65 |
+
if start_date_ndvi and end_date_ndvi:
|
66 |
+
fig = create_modis_time_series(coordinates, start_date_ndvi.isoformat(), end_date_ndvi.isoformat())
|
67 |
+
plot_modis_with_controls(fig)
|
68 |
+
except Exception as e:
|
69 |
+
st.error(f"Error processing the file: {e}")
|
70 |
+
st.error("Please upload another file and try again.")
|
71 |
+
else:
|
72 |
+
if location_name_ndvi:
|
73 |
+
try:
|
74 |
+
coordinates = get_coordinates(location_name_ndvi)
|
75 |
+
|
76 |
+
if start_date_ndvi and end_date_ndvi:
|
77 |
+
fig =create_modis_time_series(coordinates, start_date_ndvi.isoformat(), end_date_ndvi.isoformat())
|
78 |
+
st.plotly_chart(fig)
|
79 |
+
|
80 |
+
except Exception as e:
|
81 |
+
st.error(f"Error processing location data: {e}")
|
82 |
+
|
83 |
+
|
84 |
+
if __name__ == "__main__":
|
85 |
+
app()
|
86 |
+
|
87 |
+
|