update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import ee
|
|
4 |
import os
|
5 |
import pandas as pd
|
6 |
import geopandas as gpd
|
7 |
-
from datetime import datetime
|
8 |
import leafmap.foliumap as leafmap
|
9 |
import time
|
10 |
import re
|
@@ -108,16 +108,6 @@ end_date = st.date_input("End Date", value=pd.to_datetime('2020-12-31'))
|
|
108 |
start_date_str = start_date.strftime('%Y-%m-%d')
|
109 |
end_date_str = end_date.strftime('%Y-%m-%d')
|
110 |
|
111 |
-
# Frequency selection
|
112 |
-
frequency = st.selectbox("Select Frequency for Date Incrementation",
|
113 |
-
["Daily", "Weekly", "Monthly", "Yearly", "Custom Number of Days"])
|
114 |
-
|
115 |
-
# Custom days input if "Custom Number of Days" is selected
|
116 |
-
if frequency == "Custom Number of Days":
|
117 |
-
custom_days = st.number_input("Enter number of days", min_value=1, value=1)
|
118 |
-
else:
|
119 |
-
custom_days = None # Default to None when custom days aren't required
|
120 |
-
|
121 |
# Initialize session state for storing results if not already done
|
122 |
if 'results' not in st.session_state:
|
123 |
st.session_state.results = []
|
@@ -183,7 +173,7 @@ def calculate_custom_formula(image, geometry, formula):
|
|
183 |
)
|
184 |
return result.get('Custom Index')
|
185 |
|
186 |
-
# Process each point
|
187 |
if file_upload:
|
188 |
locations_df = None # Initialize locations_df to None
|
189 |
polygons_df = None # Initialize polygons_df to None
|
@@ -234,13 +224,7 @@ if file_upload:
|
|
234 |
# Store the map in session_state
|
235 |
st.session_state.map_data = m
|
236 |
|
237 |
-
|
238 |
-
# Loop through the selected frequency and increment the date
|
239 |
-
while start_date <= end_date:
|
240 |
-
start_date_str = start_date.strftime('%Y-%m-%d')
|
241 |
-
|
242 |
-
# Store results with dates for aggregation
|
243 |
-
results_with_dates = []
|
244 |
for idx, row in locations_df.iterrows():
|
245 |
latitude = row['latitude']
|
246 |
longitude = row['longitude']
|
@@ -281,28 +265,16 @@ if file_upload:
|
|
281 |
result = calculate_custom_formula(image, roi, custom_formula)
|
282 |
|
283 |
if result is not None:
|
|
|
284 |
calculated_value = result.getInfo() # Get the numeric value
|
285 |
|
286 |
-
#
|
287 |
st.session_state.results.append({
|
288 |
'Location Name': location_name,
|
289 |
'Latitude': latitude,
|
290 |
'Longitude': longitude,
|
291 |
-
'Date': date,
|
292 |
'Calculated Value': calculated_value
|
293 |
})
|
294 |
-
|
295 |
-
# Increment the current date based on the selected frequency
|
296 |
-
if frequency == "Daily":
|
297 |
-
current_date += timedelta(days=1)
|
298 |
-
elif frequency == "Weekly":
|
299 |
-
current_date += timedelta(weeks=1)
|
300 |
-
elif frequency == "Monthly":
|
301 |
-
current_date += timedelta(days=30) # Approximation
|
302 |
-
elif frequency == "Yearly":
|
303 |
-
current_date += timedelta(days=365) # Approximation
|
304 |
-
elif frequency == "Custom Number of Days" and custom_days is not None:
|
305 |
-
current_date += timedelta(days=custom_days)
|
306 |
|
307 |
# After processing, show the results
|
308 |
if st.session_state.results:
|
|
|
4 |
import os
|
5 |
import pandas as pd
|
6 |
import geopandas as gpd
|
7 |
+
from datetime import datetime
|
8 |
import leafmap.foliumap as leafmap
|
9 |
import time
|
10 |
import re
|
|
|
108 |
start_date_str = start_date.strftime('%Y-%m-%d')
|
109 |
end_date_str = end_date.strftime('%Y-%m-%d')
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
# Initialize session state for storing results if not already done
|
112 |
if 'results' not in st.session_state:
|
113 |
st.session_state.results = []
|
|
|
173 |
)
|
174 |
return result.get('Custom Index')
|
175 |
|
176 |
+
# Process each point
|
177 |
if file_upload:
|
178 |
locations_df = None # Initialize locations_df to None
|
179 |
polygons_df = None # Initialize polygons_df to None
|
|
|
224 |
# Store the map in session_state
|
225 |
st.session_state.map_data = m
|
226 |
|
227 |
+
# Process each point for index calculation
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
for idx, row in locations_df.iterrows():
|
229 |
latitude = row['latitude']
|
230 |
longitude = row['longitude']
|
|
|
265 |
result = calculate_custom_formula(image, roi, custom_formula)
|
266 |
|
267 |
if result is not None:
|
268 |
+
# Only store the numeric value (not the dictionary structure)
|
269 |
calculated_value = result.getInfo() # Get the numeric value
|
270 |
|
271 |
+
# Store the result in session state
|
272 |
st.session_state.results.append({
|
273 |
'Location Name': location_name,
|
274 |
'Latitude': latitude,
|
275 |
'Longitude': longitude,
|
|
|
276 |
'Calculated Value': calculated_value
|
277 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
|
279 |
# After processing, show the results
|
280 |
if st.session_state.results:
|