YashMK89 commited on
Commit
51cc5d7
·
verified ·
1 Parent(s): 3597c83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -43
app.py CHANGED
@@ -242,18 +242,18 @@ def calculate_cloud_percentage(image, cloud_band='QA60'):
242
  geometry=image.geometry(),
243
  scale=60, # QA60 resolution is 60 meters
244
  maxPixels=1e13
245
- ).get(cloud_band).getInfo()
246
  cloudy_pixels = cloud_mask.reduceRegion(
247
  reducer=ee.Reducer.sum(),
248
  geometry=image.geometry(),
249
  scale=60, # QA60 resolution is 60 meters
250
  maxPixels=1e13
251
- ).get(cloud_band).getInfo()
252
 
253
  # Calculate cloud percentage
254
  if total_pixels == 0:
255
  return 0 # Avoid division by zero
256
- return ee.Number(cloudy_pixels).divide(ee.Number(total_pixels)).multiply(100).getInfo()
257
 
258
  # Preprocessing function with cloud filtering
259
  def preprocess_collection(collection, cloud_threshold):
@@ -449,7 +449,6 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
449
  'Start Date': 'first',
450
  'End Date': 'first',
451
  'Calculated Value': 'mean'
452
- # 'Date Range': 'first' # Include Date Range in aggregation
453
  }
454
  if shape_type.lower() == 'point':
455
  agg_dict[original_lat_col] = 'first'
@@ -746,45 +745,6 @@ if file_upload is not None:
746
  st.write("Map of Uploaded Polygons:")
747
  m.to_streamlit()
748
 
749
- # if st.button(f"Calculate {custom_formula}"):
750
- # if not locations_df.empty:
751
- # with st.spinner("Processing Data..."):
752
- # try:
753
- # results, processing_time = process_aggregation(
754
- # locations_df,
755
- # start_date_str,
756
- # end_date_str,
757
- # dataset_id,
758
- # selected_bands,
759
- # reducer_choice,
760
- # shape_type,
761
- # aggregation_period,
762
- # original_lat_col,
763
- # original_lon_col,
764
- # custom_formula,
765
- # kernel_size,
766
- # include_boundary
767
- # )
768
- # if results:
769
- # result_df = pd.DataFrame(results)
770
- # st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
771
- # st.dataframe(result_df)
772
- # filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
773
- # st.download_button(
774
- # label="Download results as CSV",
775
- # data=result_df.to_csv(index=False).encode('utf-8'),
776
- # file_name=filename,
777
- # mime='text/csv'
778
- # )
779
- # st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
780
- # else:
781
- # st.warning("No results were generated. Check your inputs or formula.")
782
- # st.info(f"Total processing time: {processing_time:.2f} seconds.")
783
- # except Exception as e:
784
- # st.error(f"An error occurred during processing: {str(e)}")
785
- # else:
786
- # st.warning("Please upload a valid file to proceed.")
787
-
788
  if st.button(f"Calculate {custom_formula}"):
789
  if not locations_df.empty:
790
  with st.spinner("Processing Data..."):
 
242
  geometry=image.geometry(),
243
  scale=60, # QA60 resolution is 60 meters
244
  maxPixels=1e13
245
+ ).get(cloud_band)
246
  cloudy_pixels = cloud_mask.reduceRegion(
247
  reducer=ee.Reducer.sum(),
248
  geometry=image.geometry(),
249
  scale=60, # QA60 resolution is 60 meters
250
  maxPixels=1e13
251
+ ).get(cloud_band)
252
 
253
  # Calculate cloud percentage
254
  if total_pixels == 0:
255
  return 0 # Avoid division by zero
256
+ return ee.Number(cloudy_pixels).divide(ee.Number(total_pixels)).multiply(100)
257
 
258
  # Preprocessing function with cloud filtering
259
  def preprocess_collection(collection, cloud_threshold):
 
449
  'Start Date': 'first',
450
  'End Date': 'first',
451
  'Calculated Value': 'mean'
 
452
  }
453
  if shape_type.lower() == 'point':
454
  agg_dict[original_lat_col] = 'first'
 
745
  st.write("Map of Uploaded Polygons:")
746
  m.to_streamlit()
747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  if st.button(f"Calculate {custom_formula}"):
749
  if not locations_df.empty:
750
  with st.spinner("Processing Data..."):