Skip to content

Commit

Permalink
Merge pull request #7 from ProjectPythia/notebook_tweaks
Browse files Browse the repository at this point in the history
Tweak notebooks
  • Loading branch information
brian-rose authored Jul 31, 2023
2 parents 3e5f93c + 53243ad commit 0edb0d1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
56 changes: 30 additions & 26 deletions notebooks/nasa_earthdata_gibs_explorer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"\n",
"Global Imagery Browse Services (GIBS) provides quick access to over 1,000 satellite imagery products, covering every part of the world. Most imagery is updated daily—available within a few hours after satellite observation, and some products span almost 30 years.\n",
"\n",
"Below demos how to use OWSLib, Geoviews, and Panel effectively to create our own GIBS explorer.\n",
"Below demos how to use OWSLib, Geoviews, HoloViews, and Panel effectively to create our own GIBS explorer.\n",
"\n",
"## Prerequisites\n",
"\n",
Expand All @@ -45,7 +45,7 @@
"\n",
"Let’s first import a few packages.\n",
"\n",
"GeoViews is a Python library that facilitates the integration of WMS and other geospatial data sources with your own datasets. It provides a high-level interface for working with geographic data and simplifies the process of creating interactive visualizations.\n",
"HoloViews and GeoViews is a Python library that facilitates the integration of WMS and other geospatial data sources with your own datasets. It provides a high-level interface for working with geographic data and simplifies the process of creating interactive visualizations.\n",
"\n",
"Pandas is a powerful Python library for data manipulation and analysis. It offers versatile data structures, such as Series and DataFrame, for working with structured data. However, here, we will only be using it to generate date time ranges.\n",
"\n",
Expand All @@ -66,11 +66,11 @@
"source": [
"import panel as pn\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"import geoviews as gv\n",
"from owslib.wms import WebMapService\n",
"\n",
"gv.extension(\"bokeh\")\n",
"gv.renderer('bokeh').webgl = False\n",
"hv.extension(\"bokeh\")\n",
"pn.extension(sizing_mode=\"stretch_width\")"
]
},
Expand Down Expand Up @@ -132,7 +132,7 @@
"\n",
"Not only does this provide a unique opportunity to personalize your exploration experience, but it's also a fantastic way to explore all the exciting options available while showcasing the incredible power of Python packages working in harmony!\n",
"\n",
"Try it out interactively [here](https://ahuang11.github.io/nasa-earth-data-gibs-wms-explorer/)!"
"**The rendered output does not have a backend server supporting it, and will not update on change.** Instead, try it out interactively a slightly modified version (with a template) [here](https://ahuang11.github.io/nasa-earth-data-gibs-wms-explorer/)!"
]
},
{
Expand Down Expand Up @@ -178,20 +178,22 @@
" pn.state.onload(self._onload)\n",
" \n",
" def _onload(self):\n",
" # add interactivity\n",
" self.product_select.param.watch(self.update_layers, \"value\")\n",
" self.layer_select.param.watch(self.update_time, \"value\")\n",
" self.refresh_button.on_click(self.update_web_map)\n",
" # add interactivity; we use watch because the function does not return anything\n",
" pn.bind(self.update_layers, self.product_select, watch=True)\n",
" pn.bind(self.update_time, self.layer_select, watch=True)\n",
" pn.bind(self.refresh_layer, self.refresh_button, watch=True)\n",
"\n",
" # create imagery\n",
" coastline_feature = gv.feature.coastline().opts(\n",
" global_extent=True, responsive=True\n",
" base_map = hv.element.tiles.EsriImagery().opts(\n",
" xlim=(XMIN, XMAX), ylim=(YMIN, YMAX), responsive=True\n",
" )\n",
" border_feature = gv.feature.borders()\n",
" self.dynamic_map = gv.DynamicMap(\n",
" self.dynamic_map = hv.DynamicMap(\n",
" self.update_web_map, streams=[self.time_slider.param.value_throttled]\n",
" )\n",
" self.holoviews_pane.object = coastline_feature * border_feature * self.dynamic_map\n",
" self.holoviews_pane.object = base_map * self.dynamic_map\n",
"\n",
" def refresh_layer(self, clicks=None):\n",
" self.time_slider.param.trigger(\"value_throttled\")\n",
"\n",
" def get_layer(self, product=None, product_layer=None):\n",
" product = product or self.product_select.value\n",
Expand All @@ -201,12 +203,11 @@
" layer = f\"{product}_{product_layer or self.layer_select.value}\"\n",
" return layer\n",
"\n",
" def update_layers(self, event):\n",
" product = event.new\n",
" def update_layers(self, product):\n",
" product_layers = self.products_layers[product]\n",
" self.layer_select.options = sorted(product_layers)\n",
"\n",
" def update_time(self, event):\n",
" def update_time(self, product_layer):\n",
" layer = self.get_layer()\n",
" time_positions = self.wms.contents[layer].timepositions\n",
" if time_positions:\n",
Expand All @@ -222,13 +223,13 @@
" )\n",
" if options:\n",
" value = options[0]\n",
" self.time_slider.param.set_param(options=options, value=value)\n",
" return\n",
" # use N/A instead of None to circumvent Panel from crashing\n",
" # when going from time-dependent layer to time-independent layer\n",
" options = [\"N/A\"]\n",
" self.time_slider.options = options\n",
" self.time_slider.param.trigger(\"value_throttled\")\n",
" # value does not trigger; depends on value_throttled\n",
" self.time_slider.param.update(options=options, value=value)\n",
" else:\n",
" # use N/A instead of None to circumvent Panel from crashing\n",
" # when going from time-dependent layer to time-independent layer\n",
" self.time_slider.options = [\"N/A\"]\n",
" self.refresh_layer()\n",
"\n",
" def get_url_template(self, layer, time=None):\n",
" get_map_kwargs = dict(\n",
Expand Down Expand Up @@ -263,7 +264,7 @@
" url_template = self.get_url_template(layer, time)\n",
" layer_meta = self.wms[layer]\n",
" self.image_pane.object = layer_meta.styles.get(\"default\", {}).get(\"legend\")\n",
" layer_imagery = gv.WMTS(url_template).opts(title=layer_meta.title)\n",
" layer_imagery = hv.Tiles(url_template).opts(title=layer_meta.title)\n",
" finally:\n",
" self.holoviews_pane.loading = False\n",
" return layer_imagery\n",
Expand All @@ -277,10 +278,13 @@
" self.refresh_button,\n",
" pn.Spacer(sizing_mode=\"stretch_height\"),\n",
" sizing_mode=\"stretch_both\",\n",
" max_width=300,\n",
" )\n",
" return pn.Row(\n",
" widget_box,\n",
" self.holoviews_pane,\n",
" sizing_mode=\"stretch_both\",\n",
" min_height=500,\n",
" )\n",
"\n",
"\n",
Expand Down Expand Up @@ -453,7 +457,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.11.4"
},
"nbdime-conflicts": {
"local_diff": [
Expand Down
6 changes: 2 additions & 4 deletions notebooks/web_feature_services.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"source": [
"## Imports\n",
"\n",
"Let's start by importing a few packages, including Geopandas:\n",
"Let's start by importing a few packages:\n",
"\n",
"GeoViews is a Python library that simplifies working with geographic data and enables the integration of geographical features to your maps.\n",
"\n",
Expand Down Expand Up @@ -225,9 +225,7 @@
"\n",
"Online WFS viewers provide user-friendly interfaces for accessing and visualizing geospatial data.\n",
"\n",
"By overlaying WFS layers with custom data, users can gain valuable insights and unlock the full potential of geospatial information.\n",
"\n",
"For more examples of how to use WFS, check out the example workflows."
"By overlaying WFS layers with custom data, users can gain valuable insights and unlock the full potential of geospatial information.\n"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions notebooks/web_map_services.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
"\n",
"**At the time of writing, GeoViews only supports overlaying data with tile sources when the map's projection is set to `ccrs.GOOGLE_MERCATOR`.**\n",
"\n",
"Lastly, the global_extent=True option ensures that the map displays the entire world."
"Lastly, the `global_extent=True` option ensures that the map displays the entire world."
]
},
{
Expand Down Expand Up @@ -330,7 +330,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.pane.Image(requests.get(radar_url).content, background=\"white\")"
"pn.pane.Image(requests.get(radar_url).content, styles={\"background\": \"white\"})"
]
},
{
Expand Down
Binary file modified thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0edb0d1

Please sign in to comment.