UjjwalKGupta
commited on
Commit
•
c00bfce
1
Parent(s):
fa24862
Add histogram in legend
Browse files
app.py
CHANGED
@@ -541,17 +541,19 @@ if "result" in st.session_state:
|
|
541 |
raise ValueError(f"Unknown satellite: {satellite}")
|
542 |
|
543 |
if veg_index=='NDVI':
|
544 |
-
bins=[0, 0.1, 0.2, 0.3, 0.4, 0.5]
|
545 |
histogram, bin_edges = get_histogram(mosaic.select(veg_index), ee_geometry, bins)
|
546 |
print(histogram, bin_edges, bins)
|
|
|
|
|
547 |
m.add_legend(title="NDVI Class/Value",
|
548 |
-
legend_dict={'<0:Waterbody': '#0000FF',
|
549 |
-
'0-0.1: Open': '#FF0000',
|
550 |
-
'0.1-0.2: Highly Degraded':'#FFFF00',
|
551 |
-
'0.2-0.3: Degraded': '#FFA500',
|
552 |
-
'0.3-0.4: Moderately Degraded': '#00FE00',
|
553 |
-
'0.4-0.5: Dense': '#00A400',
|
554 |
-
'>0.5: Very Dense': '#006D00',
|
555 |
},
|
556 |
position='bottomright')
|
557 |
vis_params = {'min': -0.1,
|
|
|
541 |
raise ValueError(f"Unknown satellite: {satellite}")
|
542 |
|
543 |
if veg_index=='NDVI':
|
544 |
+
bins=[-1, 0, 0.1, 0.2, 0.3, 0.4, 0.5, 1]
|
545 |
histogram, bin_edges = get_histogram(mosaic.select(veg_index), ee_geometry, bins)
|
546 |
print(histogram, bin_edges, bins)
|
547 |
+
total_pix = np.sum(histogram)
|
548 |
+
formatted_histogram = [f"{h/total_pix:.2f}" for h in histogram]
|
549 |
m.add_legend(title="NDVI Class/Value",
|
550 |
+
legend_dict={f'<0:Waterbody {formatted_histogram[0]:.2f}%': '#0000FF',
|
551 |
+
f'0-0.1: Open {formatted_histogram[1]:.2f}%': '#FF0000',
|
552 |
+
f'0.1-0.2: Highly Degraded {formatted_histogram[2]:.2f}%':'#FFFF00',
|
553 |
+
f'0.2-0.3: Degraded {formatted_histogram[3]:.2f}%': '#FFA500',
|
554 |
+
f'0.3-0.4: Moderately Degraded {formatted_histogram[4]:.2f}%': '#00FE00',
|
555 |
+
f'0.4-0.5: Dense {formatted_histogram[5]:.2f}%': '#00A400',
|
556 |
+
f'>0.5: Very Dense {formatted_histogram[6]:.2f}%': '#006D00',
|
557 |
},
|
558 |
position='bottomright')
|
559 |
vis_params = {'min': -0.1,
|