Skip to content

Commit

Permalink
🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
cboettig committed Dec 19, 2023
1 parent 831b99f commit 0689a22
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 297 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ This application accesses boundary polygons from the National Parks Service and

### Code

The required code for analysis is in `fire.py`, with solara visualization in `pages/01_leafmap.py`. (For interactive )
The required code for analysis is in `fire.py`, with solara visualization in `pages/01_leafmap.py`. (For interactive use, see `solar-app.pynb`)
20 changes: 0 additions & 20 deletions pages/00_home.py

This file was deleted.

31 changes: 11 additions & 20 deletions pages/01_leafmap.py → pages/00_leafmap.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,23 @@
import leafmap
import solara
import pystac_client
import planetary_computer
import odc.stac
import geopandas as gpd
import dask.distributed
import matplotlib.pyplot as plt
import rioxarray
from osgeo import gdal
import matplotlib.pyplot as plt

# external script defines polygons, etc
from fire import *

zoom = solara.reactive(14)
center = solara.reactive((34, -116))

nps = gpd.read_file("/vsicurl/https://huggingface.co/datasets/cboettig/biodiversity/resolve/main/data/NPS.gdb")
calfire = gpd.read_file("/vsicurl/https://huggingface.co/datasets/cboettig/biodiversity/resolve/main/data/fire22_1.gdb", layer = "firep22_1")
jtree = nps[nps.PARKNAME == "Joshua Tree"].to_crs(calfire.crs)
jtree_fires = jtree.overlay(calfire, how="intersection")

recent = jtree_fires[jtree_fires.YEAR_ > "2015"]
big = recent[recent.Shape_Area == recent.Shape_Area.max()].to_crs("EPSG:4326")
datetime = big.ALARM_DATE.item() + "/" + big.CONT_DATE.item()
box = big.buffer(0.01).bounds.to_numpy()[0] # Fire bbox + buffer #box = jtree.to_crs("EPSG:4326").bounds.to_numpy()[0] # Park bbox

# location of cached COGs
before_url = "https://huggingface.co/datasets/cboettig/solara-data/resolve/main/before.tif"
after_url = "https://huggingface.co/datasets/cboettig/solara-data/resolve/main/after.tif"


# custom polygon appearance
style = {
"stroke": False,
"fill": True,
"fillColor": "#ff6666",
"fillOpacity": 0.5,
}

class Map(leafmap.Map):
def __init__(self, **kwargs):
Expand Down
29 changes: 29 additions & 0 deletions pages/01_docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import solara


@solara.component
def Page():
with solara.Column(align="center"):
markdown = """
## A Solara Template for Geospatial Applications
### Introduction
**A collection of [Solara](https://github.com/widgetti/solara) web apps for geospatial applications.**
- Web App: <https://cboettig-solara-test.hf.space>
- GitHub Source code: <https://github.com/boettiger-lab/solara-test>
- Docker container: `ghcr.io/boettiger-lab/solara-geospatial:latest`
This application accesses boundary polygons from the National Parks Service
and fire polygon data from CalFire to determine the location of all recorded
fires in Joshua Tree national park. We select the largest area fire since
2015 in the database (currently turns out to be Elk Trail Fire) and access
all Sentinel-2 imagery from the two weeks before and after the fire alarm date.
From this imagery, we compute the Normalized Burn Severity metric (NBS)
around the fire polygon before and after the fire (using cloud-native approach
of `pystac`, `odc.stac`, and dask), and plot this on a leaflet map overlay with
splitmap and fire polygons.
"""

solara.Markdown(markdown)
26 changes: 19 additions & 7 deletions solara-app.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Solara Demo Notebook\n",
"\n",
"This notebook is identical to `fire.py` + `pages/01_leafmap.py`. Running this notebook interactively (e.g. in Jupyter or VSCode) should render the solara page produced by `pages/01_leafmap.py`, and can be used for testing/developing the solara interface."
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -13,16 +22,18 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# generate COGs for the selected polygon.\n",
"# This task is run by GitHub Actions and cached in HuggingFace Datasets, so can be skipped\n",
"run()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -32,6 +43,7 @@
"before_url = \"https://huggingface.co/datasets/cboettig/solara-data/resolve/main/before.tif\"\n",
"after_url = \"https://huggingface.co/datasets/cboettig/solara-data/resolve/main/after.tif\"\n",
"\n",
"# customize the style!\n",
"style = {\n",
" \"stroke\": False,\n",
" \"fill\": True,\n",
Expand All @@ -42,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -64,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -91,13 +103,13 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "40a3f4affe8749f6882c35fe09663017",
"model_id": "2c176da4d4594b4d879b29410747b282",
"version_major": 2,
"version_minor": 0
},
Expand Down
Loading

0 comments on commit 0689a22

Please sign in to comment.