update app.oy
Browse files
app.py
CHANGED
@@ -65,9 +65,6 @@ st.header("Earth Engine Index Calculator")
|
|
65 |
# Choose Index or Custom Formula (case-insensitive)
|
66 |
index_choice = st.selectbox("Select an Index or Enter Custom Formula", ['NDVI', 'NDWI', 'Average NO₂', 'Custom Formula'])
|
67 |
|
68 |
-
# Select the statistical operation (mean, max, min, sum, median)
|
69 |
-
operation_choice = st.selectbox("Select Statistical Operation", ['mean', 'max', 'min', 'sum', 'median'])
|
70 |
-
|
71 |
# Initialize custom_formula variable
|
72 |
custom_formula = ""
|
73 |
|
@@ -82,29 +79,6 @@ elif index_choice.lower() == 'custom formula':
|
|
82 |
custom_formula = st.text_input("Enter Custom Formula (e.g., 'B5 - B4 / B5 + B4')")
|
83 |
st.write(f"Custom Formula: {custom_formula}") # Display the custom formula after the user inputs it
|
84 |
|
85 |
-
# Function to perform a specified statistical operation
|
86 |
-
def calculate_statistic(image, geometry, operation='mean', scale=30):
|
87 |
-
if operation == 'mean':
|
88 |
-
reducer = ee.Reducer.mean()
|
89 |
-
elif operation == 'max':
|
90 |
-
reducer = ee.Reducer.max()
|
91 |
-
elif operation == 'min':
|
92 |
-
reducer = ee.Reducer.min()
|
93 |
-
elif operation == 'sum':
|
94 |
-
reducer = ee.Reducer.sum()
|
95 |
-
elif operation == 'median':
|
96 |
-
reducer = ee.Reducer.median()
|
97 |
-
else:
|
98 |
-
raise ValueError("Invalid operation. Choose from 'mean', 'max', 'min', 'sum', or 'median'.")
|
99 |
-
|
100 |
-
result = image.reduceRegion(
|
101 |
-
reducer=reducer,
|
102 |
-
geometry=geometry,
|
103 |
-
scale=scale
|
104 |
-
)
|
105 |
-
|
106 |
-
return result
|
107 |
-
|
108 |
# Function to check if the polygon geometry is valid and convert it to the correct format
|
109 |
def convert_to_ee_geometry(geometry):
|
110 |
# Ensure the polygon geometry is in the right format
|
@@ -178,28 +152,39 @@ if parameters_changed():
|
|
178 |
'end_date_str': end_date_str
|
179 |
}
|
180 |
|
181 |
-
# Function to
|
182 |
-
def calculate_ndvi(image, geometry
|
183 |
ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI')
|
184 |
-
result =
|
|
|
|
|
|
|
|
|
185 |
return result.get('NDVI')
|
186 |
|
187 |
-
|
188 |
-
def calculate_ndwi(image, geometry, operation='mean'):
|
189 |
ndwi = image.normalizedDifference(['B3', 'B8']).rename('NDWI')
|
190 |
-
result =
|
|
|
|
|
|
|
|
|
191 |
return result.get('NDWI')
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
|
|
|
|
198 |
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
|
|
|
|
203 |
return result.get('Custom Index')
|
204 |
|
205 |
# Check if the file uploaded is different from the previous file uploaded
|
|
|
65 |
# Choose Index or Custom Formula (case-insensitive)
|
66 |
index_choice = st.selectbox("Select an Index or Enter Custom Formula", ['NDVI', 'NDWI', 'Average NO₂', 'Custom Formula'])
|
67 |
|
|
|
|
|
|
|
68 |
# Initialize custom_formula variable
|
69 |
custom_formula = ""
|
70 |
|
|
|
79 |
custom_formula = st.text_input("Enter Custom Formula (e.g., 'B5 - B4 / B5 + B4')")
|
80 |
st.write(f"Custom Formula: {custom_formula}") # Display the custom formula after the user inputs it
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
# Function to check if the polygon geometry is valid and convert it to the correct format
|
83 |
def convert_to_ee_geometry(geometry):
|
84 |
# Ensure the polygon geometry is in the right format
|
|
|
152 |
'end_date_str': end_date_str
|
153 |
}
|
154 |
|
155 |
+
# Function to perform index calculations
|
156 |
+
def calculate_ndvi(image, geometry):
|
157 |
ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI')
|
158 |
+
result = ndvi.reduceRegion(
|
159 |
+
reducer=ee.Reducer.mean(),
|
160 |
+
geometry=geometry,
|
161 |
+
scale=30
|
162 |
+
)
|
163 |
return result.get('NDVI')
|
164 |
|
165 |
+
def calculate_ndwi(image, geometry):
|
|
|
166 |
ndwi = image.normalizedDifference(['B3', 'B8']).rename('NDWI')
|
167 |
+
result = ndwi.reduceRegion(
|
168 |
+
reducer=ee.Reducer.mean(),
|
169 |
+
geometry=geometry,
|
170 |
+
scale=30
|
171 |
+
)
|
172 |
return result.get('NDWI')
|
173 |
|
174 |
+
def calculate_avg_no2_sentinel5p(image, geometry):
|
175 |
+
no2 = image.select('NO2').reduceRegion(
|
176 |
+
reducer=ee.Reducer.mean(),
|
177 |
+
geometry=geometry,
|
178 |
+
scale=1000
|
179 |
+
).get('NO2')
|
180 |
+
return no2
|
181 |
|
182 |
+
def calculate_custom_formula(image, geometry, formula):
|
183 |
+
result = image.expression(formula).rename('Custom Index').reduceRegion(
|
184 |
+
reducer=ee.Reducer.mean(),
|
185 |
+
geometry=geometry,
|
186 |
+
scale=30
|
187 |
+
)
|
188 |
return result.get('Custom Index')
|
189 |
|
190 |
# Check if the file uploaded is different from the previous file uploaded
|