cboettig commited on
Commit
15ec4c3
·
1 Parent(s): 39f1ea8

tweak text

Browse files
Files changed (1) hide show
  1. app.py +22 -24
app.py CHANGED
@@ -25,8 +25,13 @@ import ibis.selectors as s
25
  st.set_page_config(layout="wide", page_title="Leafmap Explorer", page_icon="⚡")
26
 
27
  '''
28
- # Leafmap explorer
29
 
 
 
 
 
 
30
  '''
31
 
32
 
@@ -35,28 +40,23 @@ irrecoverable = "https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_t
35
  vulnerable = "https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif"
36
 
37
  m = leafmap.Map(center=[35, -100], zoom=5)
38
- m.add_cog_layer(deforest, palette="reds", name="deforested", transparent_bg=True, opacity = 0.8, zoom_to_layer=False)
 
 
39
  # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif", palette="reds", name="irrecoverable carbon", transparent_bg=True, opacity = 0.8)
40
  # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif", palette="purples", name="vulnerable carbon", transparent_bg=True, opacity = 0.8)
41
-
42
 
43
 
44
  # +
45
- code_ex = '''
46
- m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif",
47
- palette="greens",
48
- name="irreplacable carbon",
49
- transparent_bg=True,
50
- zoom_to_layer=False,
51
- opacity = 0.8)
52
- '''
53
 
54
 
55
- polygon_ex = '''
56
- {"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-123.011169,40.728527],[-123.011169,40.798217],[-122.956924,40.798217],[-122.956924,40.728527],[-123.011169,40.728527]]]}}
57
  '''
58
 
59
- polygon_ex ='{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-125.81543,48.312428],[-125.81543,52.935397],[-113.818359,52.935397],[-113.818359,48.312428],[-125.81543,48.312428]]]}}'
60
 
61
 
62
  # +
@@ -69,10 +69,6 @@ with st.sidebar:
69
  '''
70
  ### Polygon selector
71
 
72
- Use the map tools to draw a polygon (e.g. box area) anywhere on the map.
73
- Click inside the box when you are done to show the coordinates.
74
- Please paste those coordinates (or any geojson of your choosing) here
75
- to see summary statistics on the map.
76
  '''
77
 
78
  polygon = st.text_area(
@@ -81,10 +77,10 @@ with st.sidebar:
81
  height = 400)
82
 
83
 
84
- "### Execute arbitrary python code:"
85
-
86
  code = st.text_area(
87
- label = "Python code",
88
  value = code_ex,
89
  height = 400)
90
 
@@ -99,14 +95,16 @@ x = (rioxarray.
99
  rio.clip(geo.geometry.values, geo.crs, from_disk=True).
100
  sum()
101
  )
102
-
103
 
104
 
105
  # +
106
 
107
- "## Tons of carbon lost, 2002-2022"
 
 
108
 
109
- st.write(float(x))
110
  # -
111
 
112
  eval(compile(code, "<string>", "exec"))
 
25
  st.set_page_config(layout="wide", page_title="Leafmap Explorer", page_icon="⚡")
26
 
27
  '''
28
+ # Demo Carbon Calculator
29
 
30
+
31
+ Use the map tools to draw a polygon (pentagon tool), bounding box (square tool) or other shape anywhere on the map.
32
+ Click inside the box when you are done to show the coordinates.
33
+ Please copy-paste those coordinates (or any geojson of your choosing) into the polygon selector.
34
+ Map will zoom in on selected area and display the tons of carbon lost between 2002 - 2022 below.
35
  '''
36
 
37
 
 
40
  vulnerable = "https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif"
41
 
42
  m = leafmap.Map(center=[35, -100], zoom=5)
43
+ m.add_cog_layer("https://data.source.coop/vizzuality/lg-land-carbon-data/deforest_carbon_100m_cog.tif", palette="reds", name="deforested", transparent_bg=True, opacity = 0.8, zoom_to_layer=False)
44
+
45
+ # m.add_cog_layer(deforest, palette="reds", name="deforested", transparent_bg=True, opacity = 0.8, zoom_to_layer=False)
46
  # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif", palette="reds", name="irrecoverable carbon", transparent_bg=True, opacity = 0.8)
47
  # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif", palette="purples", name="vulnerable carbon", transparent_bg=True, opacity = 0.8)
48
+ # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif", palette="greens", name="irreplacable carbon", transparent_bg=True, zoom_to_layer=False, opacity = 0.8)
49
 
50
 
51
  # +
52
+ polygon_ex ='{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-124.628906,34.741612],[-124.628906,42.423457],[-117.246094,42.423457],[-117.246094,34.741612],[-124.628906,34.741612]]]}}'
 
 
 
 
 
 
 
53
 
54
 
55
+ code_ex = '''
56
+ m.add_gdf(geo, layer_name="selection")
57
  '''
58
 
59
+
60
 
61
 
62
  # +
 
69
  '''
70
  ### Polygon selector
71
 
 
 
 
 
72
  '''
73
 
74
  polygon = st.text_area(
 
77
  height = 400)
78
 
79
 
80
+ "### python code for map layer:"
81
+ "adjust options or add additional layers using leafmap"
82
  code = st.text_area(
83
+ label = "code:",
84
  value = code_ex,
85
  height = 400)
86
 
 
95
  rio.clip(geo.geometry.values, geo.crs, from_disk=True).
96
  sum()
97
  )
98
+ value = float(x)
99
 
100
 
101
  # +
102
 
103
+ "### Tons of carbon lost:"
104
+
105
+ st.write(f'{value:,}')
106
 
107
+ st.divider()
108
  # -
109
 
110
  eval(compile(code, "<string>", "exec"))