File size: 5,152 Bytes
0b6e435
 
0689a22
 
 
 
 
 
 
 
 
0b6e435
 
58bb813
0b6e435
6000270
 
 
 
 
 
 
 
 
 
 
 
0b6e435
 
 
6000270
0b6e435
 
 
 
58bb813
0b6e435
 
 
0689a22
 
0b6e435
 
 
 
 
58bb813
0b6e435
 
 
 
 
 
 
 
 
0689a22
0b6e435
 
 
 
 
 
 
 
 
 
58bb813
0b6e435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58bb813
0b6e435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58bb813
0b6e435
 
 
 
 
58bb813
0b6e435
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "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 (<i>Click in the code cell, and press Shift+Enter <kbd>⇧</kbd>+<kbd>↩</kbd></i>)."
      ],
      "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
}