update app.py
Browse files
app.py
CHANGED
@@ -53,10 +53,15 @@ with open("sentinel_datasets.json") as f:
|
|
53 |
with open("band_options.json") as f:
|
54 |
band_options = json.load(f)
|
55 |
|
|
|
|
|
|
|
|
|
|
|
56 |
# Display the title and dataset selection
|
57 |
st.title("Sentinel Dataset")
|
58 |
|
59 |
-
# Select dataset category and subcategory
|
60 |
main_selection = st.selectbox("Select Sentinel Dataset Category", list(data.keys()))
|
61 |
|
62 |
if main_selection:
|
@@ -66,19 +71,13 @@ if main_selection:
|
|
66 |
# Earth Engine Index Calculator Section
|
67 |
st.header("Earth Engine Index Calculator")
|
68 |
|
69 |
-
# Choose Index or Custom Formula
|
70 |
index_choice = st.selectbox("Select an Index or Enter Custom Formula", ['NDVI', 'NDWI', 'Average NO₂', 'Custom Formula'])
|
71 |
|
72 |
# Initialize custom_formula variable
|
73 |
custom_formula = ""
|
74 |
|
75 |
-
#
|
76 |
-
if main_selection and sub_selection:
|
77 |
-
available_bands = band_options.get(main_selection, {}).get(sub_selection, [])
|
78 |
-
else:
|
79 |
-
available_bands = []
|
80 |
-
|
81 |
-
# Display corresponding formula based on the index selected (case-insensitive)
|
82 |
if index_choice.lower() == 'ndvi':
|
83 |
st.write("Formula for NDVI: NDVI = (B8 - B4) / (B8 + B4)")
|
84 |
elif index_choice.lower() == 'ndwi':
|
@@ -86,19 +85,25 @@ elif index_choice.lower() == 'ndwi':
|
|
86 |
elif index_choice.lower() == 'average no₂':
|
87 |
st.write("Formula for Average NO₂: Average NO₂ = Mean(NO2 band)")
|
88 |
elif index_choice.lower() == 'custom formula':
|
89 |
-
#
|
90 |
-
|
91 |
-
|
92 |
-
# Show the selected bands in the custom formula input
|
93 |
-
if len(band_selection) > 0:
|
94 |
-
st.write("You selected the following bands:")
|
95 |
-
st.write(band_selection)
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
st.write(f"Custom Formula: {custom_formula}") # Display the custom formula after the user inputs it
|
101 |
-
|
|
|
|
|
102 |
# Function to check if the polygon geometry is valid and convert it to the correct format
|
103 |
def convert_to_ee_geometry(geometry):
|
104 |
# Ensure the polygon geometry is in the right format
|
|
|
53 |
with open("band_options.json") as f:
|
54 |
band_options = json.load(f)
|
55 |
|
56 |
+
# Function to load available bands for the selected dataset and allow user to create custom formula
|
57 |
+
def get_available_bands_for_custom_formula(dataset):
|
58 |
+
# Fetch available bands for the selected dataset
|
59 |
+
return band_data.get(dataset, {}).get('bands', [])
|
60 |
+
|
61 |
# Display the title and dataset selection
|
62 |
st.title("Sentinel Dataset")
|
63 |
|
64 |
+
# Select dataset category and subcategory
|
65 |
main_selection = st.selectbox("Select Sentinel Dataset Category", list(data.keys()))
|
66 |
|
67 |
if main_selection:
|
|
|
71 |
# Earth Engine Index Calculator Section
|
72 |
st.header("Earth Engine Index Calculator")
|
73 |
|
74 |
+
# Choose Index or Custom Formula
|
75 |
index_choice = st.selectbox("Select an Index or Enter Custom Formula", ['NDVI', 'NDWI', 'Average NO₂', 'Custom Formula'])
|
76 |
|
77 |
# Initialize custom_formula variable
|
78 |
custom_formula = ""
|
79 |
|
80 |
+
# Display corresponding formula based on the index selected
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
if index_choice.lower() == 'ndvi':
|
82 |
st.write("Formula for NDVI: NDVI = (B8 - B4) / (B8 + B4)")
|
83 |
elif index_choice.lower() == 'ndwi':
|
|
|
85 |
elif index_choice.lower() == 'average no₂':
|
86 |
st.write("Formula for Average NO₂: Average NO₂ = Mean(NO2 band)")
|
87 |
elif index_choice.lower() == 'custom formula':
|
88 |
+
# Dynamically fetch available bands for the selected dataset
|
89 |
+
available_bands = get_available_bands_for_custom_formula(sub_selection)
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
+
if available_bands:
|
92 |
+
# Allow users to select bands for the custom formula
|
93 |
+
st.write(f"Available bands for {sub_selection}:")
|
94 |
+
selected_bands = st.multiselect("Select Bands", available_bands)
|
95 |
+
|
96 |
+
# Show instructions for the custom formula
|
97 |
+
st.write("Example formula: (B8 - B4) / (B8 + B4)")
|
98 |
+
|
99 |
+
# Let the user input a custom formula using selected bands
|
100 |
+
custom_formula = st.text_area("Enter Custom Formula", value="")
|
101 |
+
|
102 |
+
# Display the formula that the user entered
|
103 |
st.write(f"Custom Formula: {custom_formula}") # Display the custom formula after the user inputs it
|
104 |
+
else:
|
105 |
+
st.warning(f"No available bands found for the selected dataset ({sub_selection}). Please ensure the dataset contains bands.")
|
106 |
+
|
107 |
# Function to check if the polygon geometry is valid and convert it to the correct format
|
108 |
def convert_to_ee_geometry(geometry):
|
109 |
# Ensure the polygon geometry is in the right format
|