update app.py
Browse files
app.py
CHANGED
@@ -887,7 +887,7 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
|
|
887 |
if index_choice.lower() == 'custom_formula' and not custom_formula:
|
888 |
st.error("Custom formula cannot be empty. Please provide a formula.")
|
889 |
return aggregated_results # Return early to avoid further processing
|
890 |
-
|
891 |
# Initialize progress bar
|
892 |
total_steps = len(locations_df)
|
893 |
progress_bar = st.progress(0)
|
@@ -923,10 +923,31 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
|
|
923 |
# Process each image in the collection
|
924 |
image_list = collection.toList(collection.size())
|
925 |
all_values = [] # To store calculated values for mean calculation
|
|
|
|
|
926 |
|
927 |
for i in range(image_list.size().getInfo()):
|
928 |
image = ee.Image(image_list.get(i))
|
929 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
930 |
# Calculate the index for each period
|
931 |
index_image = calculate_index_for_period(image, roi, index_choice, reducer_choice, custom_formula)
|
932 |
|
@@ -952,7 +973,9 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
|
|
952 |
'Location Name': location_name,
|
953 |
'Latitude': latitude,
|
954 |
'Longitude': longitude,
|
955 |
-
'Mean Value': mean_value
|
|
|
|
|
956 |
})
|
957 |
|
958 |
# Update progress bar
|
@@ -989,10 +1012,31 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
|
|
989 |
# Process each image in the collection
|
990 |
image_list = collection.toList(collection.size())
|
991 |
all_values = [] # To store calculated values for mean calculation
|
|
|
|
|
992 |
|
993 |
for i in range(image_list.size().getInfo()):
|
994 |
image = ee.Image(image_list.get(i))
|
995 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
996 |
# Calculate the index for each period
|
997 |
index_image = calculate_index_for_period(image, roi, index_choice, reducer_choice, custom_formula)
|
998 |
|
@@ -1016,7 +1060,9 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
|
|
1016 |
mean_value = sum(all_values) / len(all_values)
|
1017 |
aggregated_results.append({
|
1018 |
'Location Name': location_name,
|
1019 |
-
'Mean Value': mean_value
|
|
|
|
|
1020 |
})
|
1021 |
|
1022 |
# Update progress bar
|
@@ -1039,8 +1085,8 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
|
|
1039 |
result_df.rename(columns={'latitude': 'Latitude', 'longitude': 'Longitude'}, inplace=True)
|
1040 |
result_df.drop(columns=['name'], inplace=True)
|
1041 |
|
1042 |
-
# Return only the required fields
|
1043 |
-
return result_df[['Location Name', 'Latitude', 'Longitude', 'Mean Value']].to_dict(orient='records')
|
1044 |
|
1045 |
return []
|
1046 |
####################################################
|
|
|
887 |
if index_choice.lower() == 'custom_formula' and not custom_formula:
|
888 |
st.error("Custom formula cannot be empty. Please provide a formula.")
|
889 |
return aggregated_results # Return early to avoid further processing
|
890 |
+
|
891 |
# Initialize progress bar
|
892 |
total_steps = len(locations_df)
|
893 |
progress_bar = st.progress(0)
|
|
|
923 |
# Process each image in the collection
|
924 |
image_list = collection.toList(collection.size())
|
925 |
all_values = [] # To store calculated values for mean calculation
|
926 |
+
start_date = None
|
927 |
+
end_date = None
|
928 |
|
929 |
for i in range(image_list.size().getInfo()):
|
930 |
image = ee.Image(image_list.get(i))
|
931 |
|
932 |
+
# Extract the timestamp based on the aggregation period
|
933 |
+
if aggregation_period.lower() == 'daily':
|
934 |
+
timestamp = image.get('day')
|
935 |
+
elif aggregation_period.lower() == 'weekly':
|
936 |
+
timestamp = image.get('week_start') # Use week start date
|
937 |
+
elif aggregation_period.lower() == 'monthly':
|
938 |
+
timestamp = image.get('month')
|
939 |
+
elif aggregation_period.lower() == 'yearly':
|
940 |
+
timestamp = image.get('year')
|
941 |
+
|
942 |
+
# Format the timestamp as a valid date string
|
943 |
+
date = ee.Date(timestamp).format('YYYY-MM-dd').getInfo()
|
944 |
+
|
945 |
+
# Update start_date and end_date
|
946 |
+
if start_date is None or date < start_date:
|
947 |
+
start_date = date
|
948 |
+
if end_date is None or date > end_date:
|
949 |
+
end_date = date
|
950 |
+
|
951 |
# Calculate the index for each period
|
952 |
index_image = calculate_index_for_period(image, roi, index_choice, reducer_choice, custom_formula)
|
953 |
|
|
|
973 |
'Location Name': location_name,
|
974 |
'Latitude': latitude,
|
975 |
'Longitude': longitude,
|
976 |
+
'Mean Value': mean_value,
|
977 |
+
'Start Date': start_date,
|
978 |
+
'End Date': end_date
|
979 |
})
|
980 |
|
981 |
# Update progress bar
|
|
|
1012 |
# Process each image in the collection
|
1013 |
image_list = collection.toList(collection.size())
|
1014 |
all_values = [] # To store calculated values for mean calculation
|
1015 |
+
start_date = None
|
1016 |
+
end_date = None
|
1017 |
|
1018 |
for i in range(image_list.size().getInfo()):
|
1019 |
image = ee.Image(image_list.get(i))
|
1020 |
|
1021 |
+
# Extract the timestamp based on the aggregation period
|
1022 |
+
if aggregation_period.lower() == 'daily':
|
1023 |
+
timestamp = image.get('day')
|
1024 |
+
elif aggregation_period.lower() == 'weekly':
|
1025 |
+
timestamp = image.get('week_start') # Use week start date
|
1026 |
+
elif aggregation_period.lower() == 'monthly':
|
1027 |
+
timestamp = image.get('month')
|
1028 |
+
elif aggregation_period.lower() == 'yearly':
|
1029 |
+
timestamp = image.get('year')
|
1030 |
+
|
1031 |
+
# Format the timestamp as a valid date string
|
1032 |
+
date = ee.Date(timestamp).format('YYYY-MM-dd').getInfo()
|
1033 |
+
|
1034 |
+
# Update start_date and end_date
|
1035 |
+
if start_date is None or date < start_date:
|
1036 |
+
start_date = date
|
1037 |
+
if end_date is None or date > end_date:
|
1038 |
+
end_date = date
|
1039 |
+
|
1040 |
# Calculate the index for each period
|
1041 |
index_image = calculate_index_for_period(image, roi, index_choice, reducer_choice, custom_formula)
|
1042 |
|
|
|
1060 |
mean_value = sum(all_values) / len(all_values)
|
1061 |
aggregated_results.append({
|
1062 |
'Location Name': location_name,
|
1063 |
+
'Mean Value': mean_value,
|
1064 |
+
'Start Date': start_date,
|
1065 |
+
'End Date': end_date
|
1066 |
})
|
1067 |
|
1068 |
# Update progress bar
|
|
|
1085 |
result_df.rename(columns={'latitude': 'Latitude', 'longitude': 'Longitude'}, inplace=True)
|
1086 |
result_df.drop(columns=['name'], inplace=True)
|
1087 |
|
1088 |
+
# Return only the required fields, including Start Date and End Date
|
1089 |
+
return result_df[['Location Name', 'Latitude', 'Longitude', 'Mean Value', 'Start Date', 'End Date']].to_dict(orient='records')
|
1090 |
|
1091 |
return []
|
1092 |
####################################################
|