UjjwalKGupta commited on
Commit
9de841f
·
verified ·
1 Parent(s): 7ad5305

update index histogram to csv

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -898,14 +898,27 @@ def compute_index_histogram(file_url: str, index_name: str, start_date: str, end
898
  histogram, _ = get_histogram(index_name, mosaic.select(index_name), ee_geometry, bins)
899
 
900
  total = histogram.sum()
901
- result = {f'mean': mean_val}
 
 
 
 
 
 
 
 
 
902
  for i in range(len(bins) - 1):
903
  label = f"{bins[i]}-{bins[i+1]}"
904
  pct = (histogram[i] / total * 100) if total > 0 else 0
905
- result[label] = round(pct, 2)
 
906
 
907
- return result
 
908
 
 
 
909
 
910
  # Register endpoints for multiple indices with date range
911
  for idx in ["NDVI", "EVI", "EVI2", "RandomForest", "CI", "GujVDI"]:
 
898
  histogram, _ = get_histogram(index_name, mosaic.select(index_name), ee_geometry, bins)
899
 
900
  total = histogram.sum()
901
+
902
+ # result = {f'mean': mean_val}
903
+ # for i in range(len(bins) - 1):
904
+ # label = f"{bins[i]}-{bins[i+1]}"
905
+ # pct = (histogram[i] / total * 100) if total > 0 else 0
906
+ # result[label] = round(pct, 2)
907
+
908
+
909
+ output_parts = [f'mean, {round(mean_val, 4)}']
910
+
911
  for i in range(len(bins) - 1):
912
  label = f"{bins[i]}-{bins[i+1]}"
913
  pct = (histogram[i] / total * 100) if total > 0 else 0
914
+ # Append each key-value pair string to the list
915
+ output_parts.append(f'{label}, {round(pct, 2)}')
916
 
917
+ # Join all parts into a single comma-separated string
918
+ final_string = ", ".join(output_parts)
919
 
920
+ # Return the string as a plain text response
921
+ return Response(content=final_string, media_type="text/plain")
922
 
923
  # Register endpoints for multiple indices with date range
924
  for idx in ["NDVI", "EVI", "EVI2", "RandomForest", "CI", "GujVDI"]: