solara-geemap / pages /00_home.py
iamsuman's picture
show fire maps
2dc4a78
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)