diff --git a/demo/voila_demo.ipynb b/demo/voila_demo.ipynb index ca35d82..7aed5a9 100644 --- a/demo/voila_demo.ipynb +++ b/demo/voila_demo.ipynb @@ -241,14 +241,14 @@ " text = ' '.join(tokens)\n", " print(f'{text} \\r', end=\"\")\n", " granule_count += 1\n", - " \n", + "\n", "# build and transmit requests to SlideRule\n", "def runSlideRule():\n", " global url_textbox, atl06_parms, granule_count\n", - " \n", + "\n", " # reset granule count\n", " granule_count = 0\n", - " \n", + "\n", " # set the url for the sliderule service\n", " icesat2.init(url_textbox.value, loglevel=logging.ERROR, max_resources=1000)\n", "\n", @@ -282,7 +282,7 @@ " # for each region of interest\n", " for poly in m.regions:\n", " # add polygon from map to sliderule parameters\n", - " atl06_parms[\"poly\"] = poly \n", + " atl06_parms[\"poly\"] = poly\n", " # make the request to the SlideRule (ATL06-SR) endpoint\n", " # and pass it the request parameters to request ATL06 Data\n", " elevations.append(icesat2.atl06p(atl06_parms, callbacks={'eventrec': demo_logeventrec, 'exceptrec': demo_exceptrec}))\n", @@ -309,7 +309,13 @@ " if max_plot_points > atl06_rsps.shape[0]:\n", " max_plot_points = atl06_rsps.shape[0]\n", " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", - " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", + " fields = m.default_atl06_fields()\n", + " atl06_rsps.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value,\n", + " cmap=SRwidgets.colormap, max_plot_points=max_plot_points, tooltip=True,\n", + " colorbar=True, fields=fields)\n", + " # install handlers and callbacks\n", + " atl06_rsps.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n", + " m.add_region_callback(atl06_rsps.leaflet.handle_region)\n", "\n", "# refresh action\n", "def on_refresh_clicked(b):\n", @@ -324,7 +330,13 @@ " if max_plot_points > atl06_rsps.shape[0]:\n", " max_plot_points = atl06_rsps.shape[0]\n", " print(f'Plotting {max_plot_points} of {atl06_rsps.shape[0]} elevations. This may take 10-60+ seconds for larger point datasets.')\n", - " m.GeoData(atl06_rsps, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap, max_plot_points=max_plot_points)\n", + " fields = m.default_atl06_fields()\n", + " atl06_rsps.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value,\n", + " cmap=SRwidgets.colormap, max_plot_points=max_plot_points, tooltip=True,\n", + " colorbar=True, fields=fields)\n", + " # install handlers and callbacks\n", + " atl06_rsps.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n", + " m.add_region_callback(atl06_rsps.leaflet.handle_region)\n", "\n", "# show code action\n", "def on_show_code06_clicked(b):\n", @@ -337,7 +349,7 @@ " atl06_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl06_json)\n", " print('parms = ', atl06_json, sep='')\n", " print('gdf = icesat2.atl06p(parms)')\n", - " \n", + "\n", "# link buttons\n", "run_button.on_click(on_run_clicked)\n", "refresh_button.on_click(on_refresh_clicked)\n", @@ -480,7 +492,7 @@ "# ATL03 Subsetter\n", "def runATL03Subsetter():\n", " global url_textbox, atl03_parms\n", - " \n", + "\n", " # set the url for the sliderule service\n", " if url_textbox.value == 'local':\n", " url = 'host.docker.internal'\n", @@ -505,10 +517,10 @@ " \"yapc\": {\"score\": 0}, # all photons\n", " \"ats\": SRwidgets.spread.value,\n", " \"cnt\": SRwidgets.count.value,\n", - " \n", + "\n", " # region of interest\n", " \"poly\": m.regions[0],\n", - " \n", + "\n", " # track selection\n", " \"rgt\": int(SRwidgets.rgt.value),\n", " \"cycle\": int(SRwidgets.cycle.value),\n", @@ -517,7 +529,7 @@ "\n", " # make call to sliderule\n", " rsps = icesat2.atl03sp(atl03_parms)\n", - " \n", + "\n", " # return geodataframe\n", " return rsps\n", "\n", @@ -526,7 +538,7 @@ " global atl03_rsps, atl06_rsps, elev_dropdown\n", " with pc_output:\n", " pc_output.clear_output(True)\n", - " \n", + "\n", " # Run ATL03 Subsetter\n", " print(f'SlideRule processing request... initiated\\r', end=\"\")\n", " perf_start = time.perf_counter()\n", @@ -540,18 +552,25 @@ " fig.set_facecolor('white')\n", " fig.canvas.header_visible = False\n", " ax.set_title(\"Photon Cloud\")\n", - " ax.set_xlabel('UTC')\n", " ax.set_ylabel('height (m)')\n", - " SRwidgets.plot(atl06_rsps, ax=ax, kind='scatter',\n", - " atl03=atl03_rsps, cmap=SRwidgets.colormap,\n", + " # start at the first segment\n", + " x_offset = atl03_rsps['segment_dist'].min()\n", + " # plot ATL03 and ATL06 data\n", + " atl03_rsps.icesat2.plot(ax=ax, kind='scatter',\n", + " data_type='atl03', cmap=SRwidgets.colormap,\n", " classification=SRwidgets.plot_classification.value,\n", - " segments=(elev_dropdown.value == 'enabled'),\n", - " legend=True, legend_frameon=True)\n", + " x_offset=x_offset, legend=True, legend_frameon=True,\n", + " **SRwidgets.plot_kwargs)\n", + " if (elev_dropdown.value == 'enabled'):\n", + " atl06_rsps.icesat2.plot(ax=ax, kind='scatter',\n", + " data_type='atl06', x_offset=x_offset,\n", + " legend=True, legend_frameon=True,\n", + " **SRwidgets.plot_kwargs)\n", " # draw and show plot\n", " plt.show()\n", " plt.draw()\n", - " \n", - "# create button to display geodataframe \n", + "\n", + "# create button to display geodataframe\n", "pc_button.on_click(on_pc_clicked)\n", "\n", "# click handler for individual photons\n", @@ -576,7 +595,7 @@ " atl03_json = re.sub(r'\\b(true|false)', lambda m: m.group(1).title(), atl03_json)\n", " print('parms = ', atl03_json, sep='')\n", " print('gdf = icesat2.atl03sp(parms)')\n", - " \n", + "\n", "# install click handler callback\n", "show_code03_button.on_click(on_show_code03_clicked)" ] @@ -619,13 +638,6 @@ "display.display(pc_output)\n", "display.display(show_code03_button, show_code03_output)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -662,7 +674,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.10.13" }, "toc-showtags": false }, diff --git a/examples/api_widgets_demo.ipynb b/examples/api_widgets_demo.ipynb index e8b4b26..c6e35a9 100644 --- a/examples/api_widgets_demo.ipynb +++ b/examples/api_widgets_demo.ipynb @@ -4,7 +4,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## IPython Widgets Example\n", + "## SlideRule ATL06 Computation: Interactive Tutorial\n", + "### IPython Widgets Example\n", "\n", "### Purpose\n", "Demonstrate common uses of the `ipysliderule` module" @@ -84,25 +85,7 @@ "source": [ "# display widgets for setting SlideRule parameters\n", "SRwidgets = ipysliderule.widgets()\n", - "widgets.VBox([\n", - " SRwidgets.classification,\n", - " SRwidgets.surface_type,\n", - " SRwidgets.confidence,\n", - " SRwidgets.quality,\n", - " SRwidgets.land_class,\n", - " SRwidgets.yapc_knn,\n", - " SRwidgets.yapc_win_h,\n", - " SRwidgets.yapc_win_x,\n", - " SRwidgets.yapc_min_ph,\n", - " SRwidgets.yapc_weight,\n", - " SRwidgets.length,\n", - " SRwidgets.step,\n", - " SRwidgets.iteration,\n", - " SRwidgets.spread,\n", - " SRwidgets.count,\n", - " SRwidgets.window,\n", - " SRwidgets.sigma,\n", - "])" + "widgets.VBox(SRwidgets.atl06())" ] }, { @@ -190,8 +173,6 @@ "source": [ "# create ipyleaflet map in specified projection\n", "m = ipysliderule.leaflet(SRwidgets.projection.value)\n", - "# install click handler callback\n", - "m.add_selected_callback(SRwidgets.atl06_click_handler)\n", "m.map" ] }, @@ -240,7 +221,7 @@ "# for each region of interest\n", "for poly in m.regions:\n", " # add polygon from map to sliderule parameters\n", - " parms[\"poly\"] = poly \n", + " parms[\"poly\"] = poly\n", " # make the request to the SlideRule (ATL06-SR) endpoint\n", " # and pass it the request parameters to request ATL06 Data\n", " elevations.append(icesat2.atl06p(parms))\n", @@ -306,8 +287,11 @@ "%matplotlib inline\n", "# ATL06-SR fields for hover tooltip\n", "fields = m.default_atl06_fields()\n", - "m.GeoData(gdf, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n", - " max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)" + "gdf.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n", + " max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)\n", + "# install handlers and callbacks\n", + "gdf.leaflet.add_selected_callback(SRwidgets.atl06_click_handler)\n", + "m.add_region_callback(gdf.leaflet.handle_region)" ] }, { @@ -348,8 +332,8 @@ "source": [ "%matplotlib widget\n", "# default is to skip cycles with significant off-pointing\n", - "SRwidgets.plot(gdf, kind=SRwidgets.plot_kind.value, cycle_start=3,\n", - " legend=True, legend_frameon=False)" + "gdf.icesat2.plot(kind=SRwidgets.plot_kind.value, cycle_start=3,\n", + " legend=True, legend_frameon=False, **SRwidgets.plot_kwargs)" ] }, { @@ -495,7 +479,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.0" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/examples/atl03_widgets_demo.ipynb b/examples/atl03_widgets_demo.ipynb index d0a2e9f..9b2d7ec 100644 --- a/examples/atl03_widgets_demo.ipynb +++ b/examples/atl03_widgets_demo.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# SlideRule ATL03 Subsetting: Interactive Widget\n", + "# SlideRule ATL03 Subsetting: Interactive Tutorial\n", "\n", "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", "\n", @@ -93,19 +93,7 @@ "# display widgets for setting SlideRule parameters\n", "SRwidgets = ipysliderule.widgets()\n", "SRwidgets.set_atl03_defaults()\n", - "widgets.VBox([\n", - " SRwidgets.start_date,\n", - " SRwidgets.end_date,\n", - " SRwidgets.classification,\n", - " SRwidgets.surface_type,\n", - " SRwidgets.confidence,\n", - " SRwidgets.quality,\n", - " SRwidgets.land_class,\n", - " SRwidgets.yapc_knn,\n", - " SRwidgets.yapc_win_h,\n", - " SRwidgets.yapc_win_x,\n", - " SRwidgets.yapc_min_ph,\n", - "])" + "widgets.VBox(SRwidgets.atl03())" ] }, { @@ -193,8 +181,6 @@ "source": [ "# create ipyleaflet map in specified projection\n", "m = ipysliderule.leaflet(SRwidgets.projection.value)\n", - "# install click handler callback\n", - "m.add_selected_callback(SRwidgets.atl03_click_handler)\n", "m.map" ] }, @@ -274,11 +260,11 @@ "# for each region of interest\n", "for poly in m.regions:\n", " # add polygon from map to sliderule parameters\n", - " parms[\"poly\"] = poly \n", + " parms[\"poly\"] = poly\n", " # make the request to the SlideRule (ATL03-SR) endpoint\n", " # and pass it the request parameters to request ATL03 Data\n", " elevations.append(icesat2.atl03sp(parms, resources=granules_list))\n", - " \n", + "\n", "gdf = geopandas.pd.concat(elevations)" ] }, @@ -341,8 +327,11 @@ "%matplotlib inline\n", "# ATL03 fields for hover tooltip\n", "fields = m.default_atl03_fields()\n", - "m.GeoData(gdf, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n", - " max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)" + "gdf.leaflet.GeoData(m.map, column_name=SRwidgets.variable.value, cmap=SRwidgets.colormap,\n", + " max_plot_points=10000, tooltip=True, colorbar=True, fields=fields)\n", + "# install handlers and callbacks\n", + "gdf.leaflet.add_selected_callback(SRwidgets.atl03_click_handler)\n", + "m.add_region_callback(gdf.leaflet.handle_region)" ] }, { @@ -378,10 +367,10 @@ "outputs": [], "source": [ "%matplotlib widget\n", - "SRwidgets.plot(atl03=gdf, kind='scatter', title='Photon Cloud',\n", + "gdf.icesat2.plot(data_type='atl03', kind='scatter', title='Photon Cloud',\n", " cmap=SRwidgets.colormap, legend=True, legend_frameon=True,\n", - " classification=SRwidgets.plot_classification.value, \n", - " segments=False)" + " classification=SRwidgets.plot_classification.value,\n", + " segments=False, **SRwidgets.plot_kwargs)" ] }, { @@ -525,7 +514,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.10.13" } }, "nbformat": 4,