Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 023329c

Browse files
authored
Merge pull request #134 from ICESat2-SlideRule/tyler
refactor: changes leaflet and transect plots to accessors
2 parents 323d333 + 8408b68 commit 023329c

File tree

3 files changed

+65
-80
lines changed

3 files changed

+65
-80
lines changed

demo/voila_demo.ipynb

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@
241241
" text = ' '.join(tokens)\n",
242242
" print(f'{text} \\r', end=\"\")\n",
243243
" granule_count += 1\n",
244-
" \n",
244+
"\n",
245245
"# build and transmit requests to SlideRule\n",
246246
"def runSlideRule():\n",
247247
" global url_textbox, atl06_parms, granule_count\n",
248-
" \n",
248+
"\n",
249249
" # reset granule count\n",
250250
" granule_count = 0\n",
251-
" \n",
251+
"\n",
252252
" # set the url for the sliderule service\n",
253253
" icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n",
254254
"\n",
@@ -282,7 +282,7 @@
282282
" # for each region of interest\n",
283283
" for poly in m.regions:\n",
284284
" # add polygon from map to sliderule parameters\n",
285-
" atl06_parms[\"poly\"] = poly \n",
285+
" atl06_parms[\"poly\"] = poly\n",
286286
" # make the request to the SlideRule (ATL06-SR) endpoint\n",
287287
" # and pass it the request parameters to request ATL06 Data\n",
288288
" elevations.append(icesat2.atl06p(atl06_parms, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n",
@@ -309,7 +309,13 @@
309309
" if max_plot_points > atl06_rsps.shape[0]:\n",
310310
" max_plot_points = atl06_rsps.shape[0]\n",
311311
" print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n",
312-
" m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n",
312+
" fields = m.default_atl06_fields()\n",
313+
" atl06_rsps.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value,\n",
314+
" cmap=SRwidgets.colormap, max_plot_points=max_plot_points, tooltip=True,\n",
315+
" colorbar=True, fields=fields)\n",
316+
" # install handlers and callbacks\n",
317+
" atl06_rsps.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n",
318+
" m.add_region_callback(atl06_rsps.leaflet.handle_region)\n",
313319
"\n",
314320
"# refresh action\n",
315321
"def on_refresh_clicked(b):\n",
@@ -324,7 +330,13 @@
324330
" if max_plot_points > atl06_rsps.shape[0]:\n",
325331
" max_plot_points = atl06_rsps.shape[0]\n",
326332
" print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n",
327-
" m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n",
333+
" fields = m.default_atl06_fields()\n",
334+
" atl06_rsps.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value,\n",
335+
" cmap=SRwidgets.colormap, max_plot_points=max_plot_points, tooltip=True,\n",
336+
" colorbar=True, fields=fields)\n",
337+
" # install handlers and callbacks\n",
338+
" atl06_rsps.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n",
339+
" m.add_region_callback(atl06_rsps.leaflet.handle_region)\n",
328340
"\n",
329341
"# show code action\n",
330342
"def on_show_code06_clicked(b):\n",
@@ -337,7 +349,7 @@
337349
" atl06_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl06_json)\n",
338350
" print('parms = ', atl06_json, sep='')\n",
339351
" print('gdf = icesat2.atl06p(parms)')\n",
340-
" \n",
352+
"\n",
341353
"# link buttons\n",
342354
"run_button.on_click(on_run_clicked)\n",
343355
"refresh_button.on_click(on_refresh_clicked)\n",
@@ -480,7 +492,7 @@
480492
"# ATL03 Subsetter\n",
481493
"def runATL03Subsetter():\n",
482494
" global url_textbox, atl03_parms\n",
483-
" \n",
495+
"\n",
484496
" # set the url for the sliderule service\n",
485497
" if url_textbox.value == 'local':\n",
486498
" url = 'host.docker.internal'\n",
@@ -505,10 +517,10 @@
505517
" \"yapc\": {\"score\": 0}, # all photons\n",
506518
" \"ats\": SRwidgets.spread.value,\n",
507519
" \"cnt\": SRwidgets.count.value,\n",
508-
" \n",
520+
"\n",
509521
" # region of interest\n",
510522
" \"poly\": m.regions[0],\n",
511-
" \n",
523+
"\n",
512524
" # track selection\n",
513525
" \"rgt\": int(SRwidgets.rgt.value),\n",
514526
" \"cycle\": int(SRwidgets.cycle.value),\n",
@@ -517,7 +529,7 @@
517529
"\n",
518530
" # make call to sliderule\n",
519531
" rsps = icesat2.atl03sp(atl03_parms)\n",
520-
" \n",
532+
"\n",
521533
" # return geodataframe\n",
522534
" return rsps\n",
523535
"\n",
@@ -526,7 +538,7 @@
526538
" global atl03_rsps, atl06_rsps, elev_dropdown\n",
527539
" with pc_output:\n",
528540
" pc_output.clear_output(True)\n",
529-
" \n",
541+
"\n",
530542
" # Run ATL03 Subsetter\n",
531543
" print(f'SlideRule processing request... initiated\\r', end=\"\")\n",
532544
" perf_start = time.perf_counter()\n",
@@ -540,18 +552,25 @@
540552
" fig.set_facecolor('white')\n",
541553
" fig.canvas.header_visible = False\n",
542554
" ax.set_title(\"Photon Cloud\")\n",
543-
" ax.set_xlabel('UTC')\n",
544555
" ax.set_ylabel('height (m)')\n",
545-
" SRwidgets.plot(atl06_rsps, ax=ax, kind='scatter',\n",
546-
" atl03=atl03_rsps, cmap=SRwidgets.colormap,\n",
556+
" # start at the first segment\n",
557+
" x_offset = atl03_rsps['segment_dist'].min()\n",
558+
" # plot ATL03 and ATL06 data\n",
559+
" atl03_rsps.icesat2.plot(ax=ax, kind='scatter',\n",
560+
" data_type='atl03', cmap=SRwidgets.colormap,\n",
547561
" classification=SRwidgets.plot_classification.value,\n",
548-
" segments=(elev_dropdown.value == 'enabled'),\n",
549-
" legend=True, legend_frameon=True)\n",
562+
" x_offset=x_offset, legend=True, legend_frameon=True,\n",
563+
" **SRwidgets.plot_kwargs)\n",
564+
" if (elev_dropdown.value == 'enabled'):\n",
565+
" atl06_rsps.icesat2.plot(ax=ax, kind='scatter',\n",
566+
" data_type='atl06', x_offset=x_offset,\n",
567+
" legend=True, legend_frameon=True,\n",
568+
" **SRwidgets.plot_kwargs)\n",
550569
" # draw and show plot\n",
551570
" plt.show()\n",
552571
" plt.draw()\n",
553-
" \n",
554-
"# create button to display geodataframe \n",
572+
"\n",
573+
"# create button to display geodataframe\n",
555574
"pc_button.on_click(on_pc_clicked)\n",
556575
"\n",
557576
"# click handler for individual photons\n",
@@ -576,7 +595,7 @@
576595
" atl03_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl03_json)\n",
577596
" print('parms = ', atl03_json, sep='')\n",
578597
" print('gdf = icesat2.atl03sp(parms)')\n",
579-
" \n",
598+
"\n",
580599
"# install click handler callback\n",
581600
"show_code03_button.on_click(on_show_code03_clicked)"
582601
]
@@ -619,13 +638,6 @@
619638
"display.display(pc_output)\n",
620639
"display.display(show_code03_button, show_code03_output)"
621640
]
622-
},
623-
{
624-
"cell_type": "code",
625-
"execution_count": null,
626-
"metadata": {},
627-
"outputs": [],
628-
"source": []
629641
}
630642
],
631643
"metadata": {
@@ -662,7 +674,7 @@
662674
"name": "python",
663675
"nbconvert_exporter": "python",
664676
"pygments_lexer": "ipython3",
665-
"version": "3.11.5"
677+
"version": "3.10.13"
666678
},
667679
"toc-showtags": false
668680
},

examples/api_widgets_demo.ipynb

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## IPython Widgets Example\n",
7+
"## SlideRule ATL06 Computation: Interactive Tutorial\n",
8+
"### IPython Widgets Example\n",
89
"\n",
910
"### Purpose\n",
1011
"Demonstrate common uses of the `ipysliderule` module"
@@ -84,25 +85,7 @@
8485
"source": [
8586
"# display widgets for setting SlideRule parameters\n",
8687
"SRwidgets = ipysliderule.widgets()\n",
87-
"widgets.VBox([\n",
88-
" SRwidgets.classification,\n",
89-
" SRwidgets.surface_type,\n",
90-
" SRwidgets.confidence,\n",
91-
" SRwidgets.quality,\n",
92-
" SRwidgets.land_class,\n",
93-
" SRwidgets.yapc_knn,\n",
94-
" SRwidgets.yapc_win_h,\n",
95-
" SRwidgets.yapc_win_x,\n",
96-
" SRwidgets.yapc_min_ph,\n",
97-
" SRwidgets.yapc_weight,\n",
98-
" SRwidgets.length,\n",
99-
" SRwidgets.step,\n",
100-
" SRwidgets.iteration,\n",
101-
" SRwidgets.spread,\n",
102-
" SRwidgets.count,\n",
103-
" SRwidgets.window,\n",
104-
" SRwidgets.sigma,\n",
105-
"])"
88+
"widgets.VBox(SRwidgets.atl06())"
10689
]
10790
},
10891
{
@@ -190,8 +173,6 @@
190173
"source": [
191174
"# create ipyleaflet map in specified projection\n",
192175
"m = ipysliderule.leaflet(SRwidgets.projection.value)\n",
193-
"# install click handler callback\n",
194-
"m.add_selected_callback(SRwidgets.atl06_click_handler)\n",
195176
"m.map"
196177
]
197178
},
@@ -240,7 +221,7 @@
240221
"# for each region of interest\n",
241222
"for poly in m.regions:\n",
242223
" # add polygon from map to sliderule parameters\n",
243-
" parms[\"poly\"] = poly \n",
224+
" parms[\"poly\"] = poly\n",
244225
" # make the request to the SlideRule (ATL06-SR) endpoint\n",
245226
" # and pass it the request parameters to request ATL06 Data\n",
246227
" elevations.append(icesat2.atl06p(parms))\n",
@@ -306,8 +287,11 @@
306287
"%matplotlib inline\n",
307288
"# ATL06-SR fields for hover tooltip\n",
308289
"fields = m.default_atl06_fields()\n",
309-
"m.GeoData(gdf, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n",
310-
" max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)"
290+
"gdf.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n",
291+
" max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)\n",
292+
"# install handlers and callbacks\n",
293+
"gdf.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n",
294+
"m.add_region_callback(gdf.leaflet.handle_region)"
311295
]
312296
},
313297
{
@@ -348,8 +332,8 @@
348332
"source": [
349333
"%matplotlib widget\n",
350334
"# default is to skip cycles with significant off-pointing\n",
351-
"SRwidgets.plot(gdf, kind=SRwidgets.plot_kind.value, cycle_start=3,\n",
352-
" legend=True, legend_frameon=False)"
335+
"gdf.icesat2.plot(kind=SRwidgets.plot_kind.value, cycle_start=3,\n",
336+
" legend=True, legend_frameon=False, **SRwidgets.plot_kwargs)"
353337
]
354338
},
355339
{
@@ -495,7 +479,7 @@
495479
"name": "python",
496480
"nbconvert_exporter": "python",
497481
"pygments_lexer": "ipython3",
498-
"version": "3.12.0"
482+
"version": "3.10.13"
499483
}
500484
},
501485
"nbformat": 4,

examples/atl03_widgets_demo.ipynb

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"# SlideRule ATL03 Subsetting: Interactive Widget\n",
7+
"# SlideRule ATL03 Subsetting: Interactive Tutorial\n",
88
"\n",
99
"SlideRule is an on-demand science data processing service that runs in on Amazon Web Services and responds to REST API calls to process and return science results. SlideRule was designed to enable researchers and other data systems to have low-latency access to custom-generated, high-level, analysis-ready data products using processing parameters supplied at the time of the request. \n",
1010
"\n",
@@ -93,19 +93,7 @@
9393
"# display widgets for setting SlideRule parameters\n",
9494
"SRwidgets = ipysliderule.widgets()\n",
9595
"SRwidgets.set_atl03_defaults()\n",
96-
"widgets.VBox([\n",
97-
" SRwidgets.start_date,\n",
98-
" SRwidgets.end_date,\n",
99-
" SRwidgets.classification,\n",
100-
" SRwidgets.surface_type,\n",
101-
" SRwidgets.confidence,\n",
102-
" SRwidgets.quality,\n",
103-
" SRwidgets.land_class,\n",
104-
" SRwidgets.yapc_knn,\n",
105-
" SRwidgets.yapc_win_h,\n",
106-
" SRwidgets.yapc_win_x,\n",
107-
" SRwidgets.yapc_min_ph,\n",
108-
"])"
96+
"widgets.VBox(SRwidgets.atl03())"
10997
]
11098
},
11199
{
@@ -193,8 +181,6 @@
193181
"source": [
194182
"# create ipyleaflet map in specified projection\n",
195183
"m = ipysliderule.leaflet(SRwidgets.projection.value)\n",
196-
"# install click handler callback\n",
197-
"m.add_selected_callback(SRwidgets.atl03_click_handler)\n",
198184
"m.map"
199185
]
200186
},
@@ -274,11 +260,11 @@
274260
"# for each region of interest\n",
275261
"for poly in m.regions:\n",
276262
" # add polygon from map to sliderule parameters\n",
277-
" parms[\"poly\"] = poly \n",
263+
" parms[\"poly\"] = poly\n",
278264
" # make the request to the SlideRule (ATL03-SR) endpoint\n",
279265
" # and pass it the request parameters to request ATL03 Data\n",
280266
" elevations.append(icesat2.atl03sp(parms, resources=granules_list))\n",
281-
" \n",
267+
"\n",
282268
"gdf = geopandas.pd.concat(elevations)"
283269
]
284270
},
@@ -341,8 +327,11 @@
341327
"%matplotlib inline\n",
342328
"# ATL03 fields for hover tooltip\n",
343329
"fields = m.default_atl03_fields()\n",
344-
"m.GeoData(gdf, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n",
345-
" max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)"
330+
"gdf.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n",
331+
" max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)\n",
332+
"# install handlers and callbacks\n",
333+
"gdf.leaflet.add_selected_callback(SRwidgets.atl03_click_handler)\n",
334+
"m.add_region_callback(gdf.leaflet.handle_region)"
346335
]
347336
},
348337
{
@@ -378,10 +367,10 @@
378367
"outputs": [],
379368
"source": [
380369
"%matplotlib widget\n",
381-
"SRwidgets.plot(atl03=gdf, kind='scatter', title='Photon Cloud',\n",
370+
"gdf.icesat2.plot(data_type='atl03', kind='scatter', title='Photon Cloud',\n",
382371
" cmap=SRwidgets.colormap, legend=True, legend_frameon=True,\n",
383-
" classification=SRwidgets.plot_classification.value, \n",
384-
" segments=False)"
372+
" classification=SRwidgets.plot_classification.value,\n",
373+
" segments=False, **SRwidgets.plot_kwargs)"
385374
]
386375
},
387376
{
@@ -525,7 +514,7 @@
525514
"name": "python",
526515
"nbconvert_exporter": "python",
527516
"pygments_lexer": "ipython3",
528-
"version": "3.11.3"
517+
"version": "3.10.13"
529518
}
530519
},
531520
"nbformat": 4,

0 commit comments

Comments
 (0)