{ "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": 12, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2023-12-19 22:46:47,275 - distributed.utils_perf - WARNING - full garbage collections took 23% CPU time recently (threshold: 10%)\n", "2023-12-19 22:46:47,701 - distributed.utils_perf - WARNING - full garbage collections took 23% CPU time recently (threshold: 10%)\n", "2023-12-19 22:46:47,973 - distributed.utils_perf - WARNING - full garbage collections took 23% CPU time recently (threshold: 10%)\n", "2023-12-19 22:46:48,573 - distributed.utils_perf - WARNING - full garbage collections took 23% CPU time recently (threshold: 10%)\n" ] } ], "source": [ "import leafmap\n", "import solara\n", "from fire import *" ] }, { "cell_type": "code", "execution_count": 7, "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": 8, "metadata": {}, "outputs": [], "source": [ "zoom = solara.reactive(14)\n", "center = solara.reactive((34, -116))\n", "\n", "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", " \"fillColor\": \"#ff6666\",\n", " \"fillOpacity\": 0.5,\n", "}" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "class Map(leafmap.Map):\n", " def __init__(self, **kwargs):\n", " super().__init__(**kwargs)\n", " # Add what you want below\n", " # self.add_gdf(jtree, layer_name = \"Joshua Tree NP\")\n", " self.add_gdf(jtree_fires, layer_name = \"All Fires\", style=style)\n", " self.add_gdf(big, layer_name = big.FIRE_NAME.item())\n", " #self.add_raster(\"before.tif\", layer_name = \"before\", colormap=\"viridis\")\n", " #self.add_raster(\"after.tif\", layer_name = \"after\", colormap=\"viridis\")\n", " self.split_map(before_url, after_url, \n", " left_label= \"before fire\", \n", " right_label = \"after fire\")\n", " #self.add_stac_gui()\n", "\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "@solara.component\n", "def Page():\n", " with solara.Column(style={\"min-width\": \"500px\"}):\n", " # solara components support reactive variables\n", " # solara.SliderInt(label=\"Zoom level\", value=zoom, min=1, max=20)\n", " # using 3rd party widget library require wiring up the events manually\n", " # using zoom.value and zoom.set\n", " Map.element( # type: ignore\n", " zoom=zoom.value,\n", " on_zoom=zoom.set,\n", " center=center.value,\n", " on_center=center.set,\n", " scroll_wheel_zoom=True,\n", " toolbar_ctrl=False,\n", " data_ctrl=False,\n", " height=\"780px\",\n", " )\n", " solara.Text(f\"Zoom: {zoom.value}\")\n", " solara.Text(f\"Center: {center.value}\")\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c61f499623084c55a0d68925148fdad2", "version_major": 2, "version_minor": 0 }, "text/html": [ "Cannot show widget. You probably want to rerun the code cell above (Click in the code cell, and press Shift+Enter +)." ], "text/plain": [ "Cannot show ipywidgets in text" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Page()" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6" } }, "nbformat": 4, "nbformat_minor": 2 }