YashMK89 commited on
Commit
aec20f4
·
verified ·
1 Parent(s): 5914b3c

update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -252,11 +252,7 @@ def calculate_cloud_percentage(image, cloud_band='QA60'):
252
  return ee.Number(cloudy_pixels).divide(ee.Number(total_pixels)).multiply(100)
253
 
254
  # Preprocessing function
255
- def preprocess_collection(collection, tile_cloud_threshold, pixel_cloud_threshold):
256
- def filter_tile(image):
257
- cloud_percentage = calculate_cloud_percentage(image, cloud_band='QA60')
258
- return image.set('cloud_percentage', cloud_percentage).updateMask(cloud_percentage.lt(tile_cloud_threshold))
259
-
260
  def mask_cloudy_pixels(image):
261
  qa60 = image.select('QA60')
262
  opaque_clouds = qa60.bitwiseAnd(1 << 10)
@@ -265,9 +261,9 @@ def preprocess_collection(collection, tile_cloud_threshold, pixel_cloud_threshol
265
  clear_pixels = cloud_mask.Not()
266
  return image.updateMask(clear_pixels)
267
 
268
- filtered_collection = collection.map(filter_tile)
269
- masked_collection = filtered_collection.map(mask_cloudy_pixels)
270
- return masked_collection
271
 
272
  # Process single geometry
273
  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):
@@ -614,19 +610,11 @@ end_date_str = end_date.strftime('%Y-%m-%d')
614
 
615
  if imagery_base == "Sentinel" and "Sentinel-2" in sub_options[sub_selection]:
616
  st.markdown("<h5>Cloud Filtering</h5>", unsafe_allow_html=True)
617
- tile_cloud_threshold = st.slider(
618
- "Select Maximum Tile-Based Cloud Coverage Threshold (%)",
619
- min_value=0,
620
- max_value=100,
621
- value=10, # Reduced from 20
622
- step=5,
623
- help="Tiles with cloud coverage exceeding this threshold will be excluded."
624
- )
625
  pixel_cloud_threshold = st.slider(
626
  "Select Maximum Pixel-Based Cloud Coverage Threshold (%)",
627
  min_value=0,
628
  max_value=100,
629
- value=5, # Reduced from 10
630
  step=5,
631
  help="Individual pixels with cloud coverage exceeding this threshold will be masked."
632
  )
@@ -810,7 +798,6 @@ if st.button(f"Calculate {custom_formula}"):
810
  custom_formula=custom_formula,
811
  kernel_size=kernel_size,
812
  include_boundary=include_boundary,
813
- tile_cloud_threshold=tile_cloud_threshold if "tile_cloud_threshold" in locals() else 0,
814
  pixel_cloud_threshold=pixel_cloud_threshold if "pixel_cloud_threshold" in locals() else 0,
815
  user_scale=user_scale
816
  )
 
252
  return ee.Number(cloudy_pixels).divide(ee.Number(total_pixels)).multiply(100)
253
 
254
  # Preprocessing function
255
+ def preprocess_collection(collection, pixel_cloud_threshold):
 
 
 
 
256
  def mask_cloudy_pixels(image):
257
  qa60 = image.select('QA60')
258
  opaque_clouds = qa60.bitwiseAnd(1 << 10)
 
261
  clear_pixels = cloud_mask.Not()
262
  return image.updateMask(clear_pixels)
263
 
264
+ if pixel_cloud_threshold > 0:
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):
 
610
 
611
  if imagery_base == "Sentinel" and "Sentinel-2" in sub_options[sub_selection]:
612
  st.markdown("<h5>Cloud Filtering</h5>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
613
  pixel_cloud_threshold = st.slider(
614
  "Select Maximum Pixel-Based Cloud Coverage Threshold (%)",
615
  min_value=0,
616
  max_value=100,
617
+ value=5,
618
  step=5,
619
  help="Individual pixels with cloud coverage exceeding this threshold will be masked."
620
  )
 
798
  custom_formula=custom_formula,
799
  kernel_size=kernel_size,
800
  include_boundary=include_boundary,
 
801
  pixel_cloud_threshold=pixel_cloud_threshold if "pixel_cloud_threshold" in locals() else 0,
802
  user_scale=user_scale
803
  )