Spaces:
Sleeping
Sleeping
File size: 7,727 Bytes
e6b0edb 6581617 f756c68 e6b0edb 2dc4a78 e6b0edb 2dc4a78 e6b0edb f756c68 e6b0edb f756c68 e6b0edb f756c68 e6b0edb f756c68 e6b0edb f756c68 6581617 f756c68 e6b0edb f756c68 e6b0edb f756c68 e6b0edb 84e6e82 e3721b9 e6b0edb 84e6e82 e6b0edb 84e6e82 e6b0edb 2dc4a78 84e6e82 e6b0edb 6581617 e6b0edb e3721b9 e6b0edb 6581617 e6b0edb 2dc4a78 e6b0edb 2dc4a78 3c28c40 2dc4a78 6581617 e6b0edb 2dc4a78 e6b0edb 2dc4a78 e6b0edb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
import ee
import geemap
import solara
class Map(geemap.Map):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.dataset = ee.Image("UMD/hansen/global_forest_change_2023_v1_11")
self.add_forest_loss_gain_data()
self.add_plot_gui()
# self.show_fire_map()
def add_forest_loss_gain_data(self):
self.add_basemap("Esri.WorldImagery")
treeloss = self.dataset.select(["loss"]).selfMask()
treegain = self.dataset.select(["gain"]).selfMask()
self.add_layer(treeloss, {"palette": "red"}, "Tree loss")
self.add_layer(treegain, {"palette": "yellow"}, "Tree gain")
self.add("layer_manager")
def download_data(self):
treecover = self.dataset.select(["treecover2000"])
threshold = 10
treecover_bin = treecover.gte(threshold).selfMask()
countries = ee.FeatureCollection(geemap.examples.get_ee_path("countries"))
style = {"color": "#000000ff", "fillColor": "#00000000"}
self.add_layer(countries.style(**style), {}, "Countries")
geemap.zonal_stats(
treecover_bin,
countries,
"forest_cover.csv",
stat_type="SUM",
denominator=1e6,
scale=1000,
)
def show_fire_map(self):
roi = ee.Geometry.BBox(-121.0034, 36.8488, -117.9052, 39.0490)
start_date = "2020-09-05T15:00:00"
end_date = "2020-09-06T02:00:00"
data = "GOES-17"
scan = "full_disk"
timelapse = geemap.goes_fire_timelapse(
roi, "fire.gif", start_date, end_date, data, scan, framesPerSecond=5
)
# geemap.show_image(timelapse)
class PieChartPlotter:
def __init__(self, map_object):
if map_object is not None:
self.geemap = geemap # Access geemap instance from Map
self.zonal_forest_area_by_country()
def zonal_forest_area_by_country(self):
self.geemap.pie_chart(
"data/forest_cover.csv", names="NAME", values="sum", max_rows=20, height=400
).show()
class BarChartPlotter:
def __init__(self, map_object):
if map_object is not None:
self.geemap = geemap # Access geemap instance from Map
self.zonal_forest_area_by_country()
def zonal_forest_area_by_country(self):
self.geemap.bar_chart(
"data/forest_cover.csv", x="NAME", y="sum", max_rows=20, height=400,
x_label="Country", y_label="Forest area (km2)",
).show()
@solara.component
def Page():
with solara.Column(style={"min-width": "500px"}):
map_instance = Map()
Map.element(
map_object= map_instance,
center=[40, -100],
zoom=4,
height="600px",
)
with solara.Column(align="center"):
markdown = """
## Forest cover gain and loss mapping
### Forest cover mapping
**For this analysis we will be using [Hansen Global Forest Change v1.11 (2000-2023) dataset](https://developers.google.com/earth-engine/datasets/catalog/UMD_hansen_global_forest_change_2023_v1_11) and geemap. First, we will compute the zonal statistics to identify the countries with the largest forest area, and then plot them. Here the base tree cover imagery is taken from 2000**
```python
dataset = ee.Image("UMD/hansen/global_forest_change_2023_v1_11")
treecover = dataset.select(["treecover2000"])
threshold = 10
treecover_bin = treecover.gte(threshold).selfMask()
countries = ee.FeatureCollection(geemap.examples.get_ee_path("countries"))
style = {"color": "#000000ff", "fillColor": "#00000000"}
self.add_layer(countries.style(**style), {}, "Countries")
geemap.zonal_stats(
treecover_bin,
countries,
"forest_cover.csv",
stat_type="SUM",
denominator=1e6,
scale=1000,
)
self.geemap.pie_chart(
"data/forest_cover.csv", names="NAME", values="sum", max_rows=20, height=400
).show()
```
"""
solara.Markdown(markdown)
with solara.Column(style={"min-width": "500px"}):
forest_piechart_image_url = "/static/public/forest_pie_chart.png"
solara.Image(forest_piechart_image_url)
# plotter = PieChartPlotter(map_instance)
with solara.Column(align="center"):
markdown = """
**The above give us the percentage overall but not the actual number. Let's plot a bar chart that shows the numbers too**
```python
self.geemap.bar_chart(
"data/forest_cover.csv", x="NAME", y="sum", max_rows=20, height=400,
x_label="Country", y_label="Forest area (km2)",
).show()
```
"""
solara.Markdown(markdown)
with solara.Column(style={"min-width": "500px"}):
forest_barchart_image_url = "/static/public/forest_bar_chart.png"
solara.Image(forest_barchart_image_url)
# bar_chart_plotter = BarChartPlotter(map_instance)
with solara.Column(align="center"):
markdown = """
### Wildfire mapping
**Deforestation, caused by farming, cutting down trees, building roads and cities, mining, and fires, is turning forests into farmland, grazing areas, and urban spaces. Let's visualize the fire provided by [GOES satellite](https://science.nasa.gov/mission/goes/) network.
We will be using northen clafornia region as our Region of Interest (ROI)**
```python
roi = ee.Geometry.BBox(-121.0034, 36.8488, -117.9052, 39.0490)
start_date = "2020-09-05T15:00:00"
end_date = "2020-09-06T02:00:00"
data = "GOES-17"
scan = "full_disk"
timelapse = geemap.goes_fire_timelapse(
roi, "fire.gif", start_date, end_date, data, scan, framesPerSecond=5
)
geemap.show_image(timelapse)
```
"""
solara.Markdown(markdown)
with solara.Column(align="center", style={"min-width": "500px"}):
forest_fire_image_url = "/static/public/fire.gif"
solara.Image(forest_fire_image_url)
# with solara.Column(align="center"):
# markdown = """
# **Deforestation, caused by farming, cutting down trees, building roads and cities, mining, and fires, is turning forests into farmland, grazing areas, and urban spaces. Let's visualize the fire provided by [GOES satellite](https://science.nasa.gov/mission/goes/) network.**
# ```python
# roi = ee.Geometry.BBox(-121.0034, 36.8488, -117.9052, 39.0490)
# start_date = "2020-09-05T15:00:00"
# end_date = "2020-09-06T02:00:00"
# data = "GOES-17"
# scan = "full_disk"
# timelapse = geemap.goes_fire_timelapse(
# roi, "fire.gif", start_date, end_date, data, scan, framesPerSecond=5
# )
# geemap.show_image(timelapse)
# ```
# """
# solara.Markdown(markdown)
|