Skip to content

Commit d4db4ca

Browse files
committed
updated voila demo with new ipyleaflet support
1 parent d07581f commit d4db4ca

File tree

3 files changed

+68
-32
lines changed

3 files changed

+68
-32
lines changed

examples/voila_demo.ipynb

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
"import numpy as np\n",
7777
"import matplotlib.lines\n",
7878
"import matplotlib.pyplot as plt\n",
79+
"# autoreload\n",
80+
"%load_ext autoreload\n",
81+
"%autoreload 2\n",
7982
"%matplotlib inline"
8083
]
8184
},
@@ -124,6 +127,7 @@
124127
"results = []\n",
125128
"SRwidgets = ipysliderule.widgets()\n",
126129
"points_dropdown = None\n",
130+
"update_button = widgets.Button(description=\"Update Map\")\n",
127131
"run_button = widgets.Button(description=\"Run SlideRule!\")\n",
128132
"run_output = widgets.Output()\n",
129133
"refresh_button = widgets.Button(description=\"Refresh Plot\")\n",
@@ -151,11 +155,49 @@
151155
"outputs": [],
152156
"source": [
153157
"# create ipyleaflet map in specified projection\n",
154-
"m = ipysliderule.leaflet('Global', layer_control=False)\n",
158+
"m = ipysliderule.leaflet(SRwidgets.projection.value)\n",
159+
"# install click handler callback\n",
160+
"m.add_selected_callback(SRwidgets.atl06_click_handler)\n",
155161
"display(m.map)\n",
156162
"display(run_output)"
157163
]
158164
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": null,
168+
"metadata": {
169+
"extensions": {
170+
"jupyter_dashboards": {
171+
"version": 1,
172+
"views": {
173+
"default_view": {
174+
"hidden": true
175+
}
176+
}
177+
}
178+
}
179+
},
180+
"outputs": [],
181+
"source": [
182+
"# update map\n",
183+
"def on_update_clicked(b):\n",
184+
" m.add_layer(\n",
185+
" layers=SRwidgets.layers.value,\n",
186+
" rendering_rule=SRwidgets.rendering_rule\n",
187+
" )\n",
188+
" \n",
189+
"# map widgets\n",
190+
"display(widgets.VBox([\n",
191+
" SRwidgets.projection,\n",
192+
" SRwidgets.layers,\n",
193+
" SRwidgets.raster_functions\n",
194+
"]))\n",
195+
"\n",
196+
"# update button\n",
197+
"update_button.on_click(on_update_clicked)\n",
198+
"display(update_button)"
199+
]
200+
},
159201
{
160202
"cell_type": "code",
161203
"execution_count": null,
@@ -251,14 +293,14 @@
251293
"def on_refresh_clicked(b):\n",
252294
" global atl06_rsps\n",
253295
" with refresh_output:\n",
254-
" if atl06_rsps.shape[0] > 0:\n",
296+
" if atl06_rsps and atl06_rsps.shape[0] > 0:\n",
255297
" max_plot_points = 10000\n",
256298
" if points_dropdown.value == \"100K\":\n",
257299
" max_plot_points = 100000\n",
258300
" elif points_dropdown.value == \"unlimited\":\n",
259301
" max_plot_points = 1000000000\n",
260302
" m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n",
261-
" \n",
303+
"\n",
262304
"# link buttons\n",
263305
"run_button.on_click(on_run_clicked)\n",
264306
"refresh_button.on_click(on_refresh_clicked)"
@@ -316,7 +358,7 @@
316358
" SRwidgets.variable,\n",
317359
" SRwidgets.cmap,\n",
318360
" points_dropdown,\n",
319-
" SRwidgets.reverse\n",
361+
" SRwidgets.reverse,\n",
320362
"]))\n",
321363
"\n",
322364
"# display buttons\n",
@@ -518,6 +560,13 @@
518560
"display(pc_button)\n",
519561
"display(pc_output)"
520562
]
563+
},
564+
{
565+
"cell_type": "code",
566+
"execution_count": null,
567+
"metadata": {},
568+
"outputs": [],
569+
"source": []
521570
}
522571
],
523572
"metadata": {

sliderule/icesat2.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,7 @@ def __get_values(data, dtype, size):
303303
"""
304304

305305
raw = bytes(data)
306-
datatype = {
307-
"INT8": numpy.int8,
308-
"INT16": numpy.int16,
309-
"INT32": numpy.int32,
310-
"INT64": numpy.int64,
311-
"UINT8": numpy.uint8,
312-
"UINT16": numpy.uint16,
313-
"UINT32": numpy.uint32,
314-
"UINT64": numpy.uint64,
315-
"BITFIELD": numpy.byte, # unsupported
316-
"FLOAT": numpy.single,
317-
"DOUBLE": numpy.double,
318-
"TIME8": numpy.byte,
319-
"STRING": numpy.byte
320-
}[sliderule.codedtype2str[dtype]]
306+
datatype = sliderule.basictypes[sliderule.codedtype2str[dtype]]["nptype"]
321307
num_elements = int(size / numpy.dtype(datatype).itemsize)
322308
slicesize = num_elements * numpy.dtype(datatype).itemsize # truncates partial bytes
323309
values = numpy.frombuffer(raw[:slicesize], dtype=datatype, count=num_elements)

sliderule/sliderule.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import time
3737
import logging
3838
from datetime import datetime, timedelta
39+
import numpy
3940

4041
###############################################################################
4142
# GLOBALS
@@ -83,19 +84,19 @@
8384
}
8485

8586
basictypes = {
86-
"INT8": { "fmt": 'b', "size": 1 },
87-
"INT16": { "fmt": 'h', "size": 2 },
88-
"INT32": { "fmt": 'i', "size": 4 },
89-
"INT64": { "fmt": 'q', "size": 8 },
90-
"UINT8": { "fmt": 'B', "size": 1 },
91-
"UINT16": { "fmt": 'H', "size": 2 },
92-
"UINT32": { "fmt": 'I', "size": 4 },
93-
"UINT64": { "fmt": 'Q', "size": 8 },
94-
"BITFIELD": { "fmt": 'x', "size": 0 }, # unsupported
95-
"FLOAT": { "fmt": 'f', "size": 4 },
96-
"DOUBLE": { "fmt": 'd', "size": 8 },
97-
"TIME8": { "fmt": 'Q', "size": 8 },
98-
"STRING": { "fmt": 's', "size": 1 }
87+
"INT8": { "fmt": 'b', "size": 1, "nptype": numpy.int8 },
88+
"INT16": { "fmt": 'h', "size": 2, "nptype": numpy.int16 },
89+
"INT32": { "fmt": 'i', "size": 4, "nptype": numpy.int32 },
90+
"INT64": { "fmt": 'q', "size": 8, "nptype": numpy.int64 },
91+
"UINT8": { "fmt": 'B', "size": 1, "nptype": numpy.uint8 },
92+
"UINT16": { "fmt": 'H', "size": 2, "nptype": numpy.uint16 },
93+
"UINT32": { "fmt": 'I', "size": 4, "nptype": numpy.uint32 },
94+
"UINT64": { "fmt": 'Q', "size": 8, "nptype": numpy.uint64 },
95+
"BITFIELD": { "fmt": 'x', "size": 0, "nptype": numpy.byte }, # unsupported
96+
"FLOAT": { "fmt": 'f', "size": 4, "nptype": numpy.single },
97+
"DOUBLE": { "fmt": 'd', "size": 8, "nptype": numpy.double },
98+
"TIME8": { "fmt": 'Q', "size": 8, "nptype": numpy.byte },
99+
"STRING": { "fmt": 's', "size": 1, "nptype": numpy.byte }
99100
}
100101

101102
codedtype2str = {

0 commit comments

Comments
 (0)