YashMK89 commited on
Commit
49adef7
·
verified ·
1 Parent(s): 2d8931b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -265,6 +265,7 @@ def preprocess_collection(collection, pixel_cloud_threshold):
265
  return collection.map(mask_cloudy_pixels)
266
  return collection
267
 
 
268
  # Process single geometry
269
  def process_single_geometry(row, start_date_str, end_date_str, dataset_id, selected_bands, reducer_choice, shape_type, aggregation_period, custom_formula, original_lat_col, original_lon_col, kernel_size=None, include_boundary=None, user_scale=None, pixel_cloud_threshold=0):
270
  if shape_type.lower() == "point":
@@ -290,20 +291,18 @@ def process_single_geometry(row, start_date_str, end_date_str, dataset_id, selec
290
  roi = roi.buffer(-30).bounds()
291
  except ValueError:
292
  return None
293
-
294
  # Filter collection by date and area first
295
- # Apply spatial filtering
296
  collection = ee.ImageCollection(dataset_id) \
297
  .filterDate(ee.Date(start_date_str), ee.Date(end_date_str)) \
298
  .filterBounds(roi)
299
-
300
  # Apply cloud filtering if applicable
301
  if pixel_cloud_threshold > 0:
302
  collection = preprocess_collection(collection, pixel_cloud_threshold)
303
  st.write(f"After cloud masking: {collection.size().getInfo()} images")
304
 
305
- st.write(f"After initial filtering: {collection.size().getInfo()} images")
306
-
307
  if aggregation_period.lower() == 'custom (start date to end date)':
308
  collection = aggregate_data_custom(collection)
309
  elif aggregation_period.lower() == 'daily':
@@ -314,7 +313,8 @@ def process_single_geometry(row, start_date_str, end_date_str, dataset_id, selec
314
  collection = aggregate_data_monthly(collection, start_date_str, end_date_str)
315
  elif aggregation_period.lower() == 'yearly':
316
  collection = aggregate_data_yearly(collection)
317
-
 
318
  image_list = collection.toList(collection.size())
319
  processed_weeks = set()
320
  aggregated_results = []
@@ -345,7 +345,7 @@ def process_single_geometry(row, start_date_str, end_date_str, dataset_id, selec
345
  timestamp = image.get('year')
346
  period_label = 'Year'
347
  date = ee.Date(timestamp).format('YYYY').getInfo()
348
-
349
  index_image = calculate_custom_formula(image, roi, selected_bands, custom_formula, reducer_choice, dataset_id, user_scale=user_scale)
350
  try:
351
  index_value = index_image.reduceRegion(
@@ -379,7 +379,7 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
379
  progress_text = st.empty()
380
  start_time = time.time()
381
 
382
- # Fetch the original collection size
383
  raw_collection = ee.ImageCollection(dataset_id) \
384
  .filterDate(ee.Date(start_date_str), ee.Date(end_date_str))
385
  st.write(f"Original Collection Size: {raw_collection.size().getInfo()}")
 
265
  return collection.map(mask_cloudy_pixels)
266
  return collection
267
 
268
+ # Process single geometry
269
  # Process single geometry
270
  def process_single_geometry(row, start_date_str, end_date_str, dataset_id, selected_bands, reducer_choice, shape_type, aggregation_period, custom_formula, original_lat_col, original_lon_col, kernel_size=None, include_boundary=None, user_scale=None, pixel_cloud_threshold=0):
271
  if shape_type.lower() == "point":
 
291
  roi = roi.buffer(-30).bounds()
292
  except ValueError:
293
  return None
294
+
295
  # Filter collection by date and area first
 
296
  collection = ee.ImageCollection(dataset_id) \
297
  .filterDate(ee.Date(start_date_str), ee.Date(end_date_str)) \
298
  .filterBounds(roi)
299
+
300
  # Apply cloud filtering if applicable
301
  if pixel_cloud_threshold > 0:
302
  collection = preprocess_collection(collection, pixel_cloud_threshold)
303
  st.write(f"After cloud masking: {collection.size().getInfo()} images")
304
 
305
+ # Apply temporal aggregation
 
306
  if aggregation_period.lower() == 'custom (start date to end date)':
307
  collection = aggregate_data_custom(collection)
308
  elif aggregation_period.lower() == 'daily':
 
313
  collection = aggregate_data_monthly(collection, start_date_str, end_date_str)
314
  elif aggregation_period.lower() == 'yearly':
315
  collection = aggregate_data_yearly(collection)
316
+
317
+ # Process the filtered collection
318
  image_list = collection.toList(collection.size())
319
  processed_weeks = set()
320
  aggregated_results = []
 
345
  timestamp = image.get('year')
346
  period_label = 'Year'
347
  date = ee.Date(timestamp).format('YYYY').getInfo()
348
+
349
  index_image = calculate_custom_formula(image, roi, selected_bands, custom_formula, reducer_choice, dataset_id, user_scale=user_scale)
350
  try:
351
  index_value = index_image.reduceRegion(
 
379
  progress_text = st.empty()
380
  start_time = time.time()
381
 
382
+ # Log the original collection size for debugging
383
  raw_collection = ee.ImageCollection(dataset_id) \
384
  .filterDate(ee.Date(start_date_str), ee.Date(end_date_str))
385
  st.write(f"Original Collection Size: {raw_collection.size().getInfo()}")