UjjwalKGupta commited on
Commit
9f1874e
·
verified ·
1 Parent(s): dd5a2ec

Add Mean Index

Browse files
Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -837,13 +837,15 @@ def compute_index_histogram(file_url: str, index_name: str, start_date: str, end
837
  raise HTTPException(status_code=404, detail="No imagery found for the polygon in given date range.")
838
 
839
  # Use median composite to avoid cloud spikes
840
- mosaic = collection.median()
 
 
841
 
842
  bins = [0, 0.2, 0.4, 0.6, 0.8, 1.0]
843
  histogram, _ = get_histogram(index_name, mosaic.select(index_name), ee_geometry, bins)
844
 
845
  total = histogram.sum()
846
- result = {}
847
  for i in range(len(bins) - 1):
848
  label = f"{bins[i]}-{bins[i+1]}"
849
  pct = (histogram[i] / total * 100) if total > 0 else 0
 
837
  raise HTTPException(status_code=404, detail="No imagery found for the polygon in given date range.")
838
 
839
  # Use median composite to avoid cloud spikes
840
+ #mosaic = collection.median()
841
+ mosaic = collection.qualityMosaic(index_name)
842
+ mean_val = mosaic.reduceRegion(reducer=ee.Reducer.mean(), geometry=ee_geometry, scale=10, maxPixels=1e9).get(index_name).getInfo()
843
 
844
  bins = [0, 0.2, 0.4, 0.6, 0.8, 1.0]
845
  histogram, _ = get_histogram(index_name, mosaic.select(index_name), ee_geometry, bins)
846
 
847
  total = histogram.sum()
848
+ result = {f'mean': mean_val}
849
  for i in range(len(bins) - 1):
850
  label = f"{bins[i]}-{bins[i+1]}"
851
  pct = (histogram[i] / total * 100) if total > 0 else 0