Spaces:
Running
Running
area-based calculation?
Browse files
app.py
CHANGED
|
@@ -68,7 +68,7 @@ manageable = "https://data.source.coop/cboettig/carbon/cogs/manageable_c_total_2
|
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
-
m = leafmap.Map(center=[35, -100], zoom=
|
| 72 |
|
| 73 |
## Map controls sidebar
|
| 74 |
with st.sidebar:
|
|
@@ -104,14 +104,22 @@ polygon = st_data["last_active_drawing"]
|
|
| 104 |
# Here we actually compute the total carbon in the requested polygon
|
| 105 |
if polygon is not None:
|
| 106 |
gdf = read_polygon(polygon)
|
| 107 |
-
x = extract_geom(gdf, cog)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
st.divider()
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
+
m = leafmap.Map(center=[35, -100], zoom=3)
|
| 72 |
|
| 73 |
## Map controls sidebar
|
| 74 |
with st.sidebar:
|
|
|
|
| 104 |
# Here we actually compute the total carbon in the requested polygon
|
| 105 |
if polygon is not None:
|
| 106 |
gdf = read_polygon(polygon)
|
| 107 |
+
x = extract_geom(gdf, cog).fillna(0)
|
| 108 |
+
count = x.count()
|
| 109 |
+
area = round(float(area_hectares(gdf)))
|
| 110 |
+
carbon_total = round(float(x.mean()) * area) # no, mean does not include zeros
|
| 111 |
+
col1, col2, col3 = st.columns(3)
|
| 112 |
+
col1.metric(label=f"{selection}", value=f"{carbon_total:,} {units}")
|
| 113 |
+
col2.metric(label=f"Area", value=f"{area:,} Hectares")
|
| 114 |
+
col3.metric(label=f"pixels", value=f"{count:,}")
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# pixel sums instead of means
|
| 118 |
+
# value = round(float(x.sum()))
|
| 119 |
+
# if(selection in ["Vulnerable Carbon (2018)",
|
| 120 |
+
# "Manageable Carbon (2018)",
|
| 121 |
+
# "Irrecoverable Carbon (2018)"]):
|
| 122 |
+
# value = value * 9 # 300m pixels, each pixel is 9 hectres
|
| 123 |
|
| 124 |
|
| 125 |
st.divider()
|