Shubham2004
commited on
Commit
•
79e3418
1
Parent(s):
56cb210
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,53 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import h5py
|
3 |
-
import numpy as np
|
4 |
-
import pandas as pd
|
5 |
-
import plotly.express as px
|
6 |
-
import os
|
7 |
-
|
8 |
-
filename = r'
|
9 |
-
|
10 |
-
@st.cache_data
|
11 |
-
def load_h5_data(filename):
|
12 |
-
if not os.path.isfile(filename):
|
13 |
-
raise FileNotFoundError(f"File not found: {filename}")
|
14 |
-
|
15 |
-
with h5py.File(filename, 'r') as h5:
|
16 |
-
soil_moisture = h5['Analysis_Data/sm_surface_analysis'][:]
|
17 |
-
lat = h5['cell_lat'][:]
|
18 |
-
lon = h5['cell_lon'][:]
|
19 |
-
return lat, lon, soil_moisture
|
20 |
-
|
21 |
-
try:
|
22 |
-
lat, lon, soil_moisture = load_h5_data(filename)
|
23 |
-
|
24 |
-
df = pd.DataFrame({
|
25 |
-
'Latitude': lat.flatten(),
|
26 |
-
'Longitude': lon.flatten(),
|
27 |
-
'Soil Moisture': soil_moisture.flatten()
|
28 |
-
})
|
29 |
-
|
30 |
-
st.title("Soil Moisture Data Dashboard")
|
31 |
-
st.write("This dashboard displays soil moisture levels based on latitude and longitude.")
|
32 |
-
|
33 |
-
min_lat, max_lat = st.slider("Select Latitude Range", float(df['Latitude'].min()), float(df['Latitude'].max()), (float(df['Latitude'].min()), float(df['Latitude'].max())))
|
34 |
-
min_lon, max_lon = st.slider("Select Longitude Range", float(df['Longitude'].min()), float(df['Longitude'].max()), (float(df['Longitude'].min()), float(df['Longitude'].max())))
|
35 |
-
|
36 |
-
filtered_data = df[(df['Latitude'] >= min_lat) & (df['Latitude'] <= max_lat) & (df['Longitude'] >= min_lon) & (df['Longitude'] <= max_lon)]
|
37 |
-
|
38 |
-
st.write(f"Displaying data for Latitude between {min_lat} and {max_lat} and Longitude between {min_lon} and {max_lon}")
|
39 |
-
st.dataframe(filtered_data)
|
40 |
-
|
41 |
-
if not filtered_data.empty:
|
42 |
-
fig = px.scatter_mapbox(filtered_data, lat='Latitude', lon='Longitude', color='Soil Moisture',
|
43 |
-
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=3)
|
44 |
-
fig.update_layout(mapbox_style="open-street-map")
|
45 |
-
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
|
46 |
-
st.plotly_chart(fig)
|
47 |
-
else:
|
48 |
-
st.write("No data available in the selected range.")
|
49 |
-
|
50 |
-
except FileNotFoundError as e:
|
51 |
-
st.error(str(e))
|
52 |
-
except Exception as e:
|
53 |
-
st.error(f"An error occurred: {str(e)}")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import h5py
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
import plotly.express as px
|
6 |
+
import os
|
7 |
+
|
8 |
+
filename = r'Reduced_SMAP_L4_SM_aup.h5'
|
9 |
+
|
10 |
+
@st.cache_data
|
11 |
+
def load_h5_data(filename):
|
12 |
+
if not os.path.isfile(filename):
|
13 |
+
raise FileNotFoundError(f"File not found: {filename}")
|
14 |
+
|
15 |
+
with h5py.File(filename, 'r') as h5:
|
16 |
+
soil_moisture = h5['Analysis_Data/sm_surface_analysis'][:]
|
17 |
+
lat = h5['cell_lat'][:]
|
18 |
+
lon = h5['cell_lon'][:]
|
19 |
+
return lat, lon, soil_moisture
|
20 |
+
|
21 |
+
try:
|
22 |
+
lat, lon, soil_moisture = load_h5_data(filename)
|
23 |
+
|
24 |
+
df = pd.DataFrame({
|
25 |
+
'Latitude': lat.flatten(),
|
26 |
+
'Longitude': lon.flatten(),
|
27 |
+
'Soil Moisture': soil_moisture.flatten()
|
28 |
+
})
|
29 |
+
|
30 |
+
st.title("Soil Moisture Data Dashboard")
|
31 |
+
st.write("This dashboard displays soil moisture levels based on latitude and longitude.")
|
32 |
+
|
33 |
+
min_lat, max_lat = st.slider("Select Latitude Range", float(df['Latitude'].min()), float(df['Latitude'].max()), (float(df['Latitude'].min()), float(df['Latitude'].max())))
|
34 |
+
min_lon, max_lon = st.slider("Select Longitude Range", float(df['Longitude'].min()), float(df['Longitude'].max()), (float(df['Longitude'].min()), float(df['Longitude'].max())))
|
35 |
+
|
36 |
+
filtered_data = df[(df['Latitude'] >= min_lat) & (df['Latitude'] <= max_lat) & (df['Longitude'] >= min_lon) & (df['Longitude'] <= max_lon)]
|
37 |
+
|
38 |
+
st.write(f"Displaying data for Latitude between {min_lat} and {max_lat} and Longitude between {min_lon} and {max_lon}")
|
39 |
+
st.dataframe(filtered_data)
|
40 |
+
|
41 |
+
if not filtered_data.empty:
|
42 |
+
fig = px.scatter_mapbox(filtered_data, lat='Latitude', lon='Longitude', color='Soil Moisture',
|
43 |
+
color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=3)
|
44 |
+
fig.update_layout(mapbox_style="open-street-map")
|
45 |
+
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
|
46 |
+
st.plotly_chart(fig)
|
47 |
+
else:
|
48 |
+
st.write("No data available in the selected range.")
|
49 |
+
|
50 |
+
except FileNotFoundError as e:
|
51 |
+
st.error(str(e))
|
52 |
+
except Exception as e:
|
53 |
+
st.error(f"An error occurred: {str(e)}")
|