Skip to content

Replace datashader with matplotlib in user guide notebooks#1002

Merged
brendancol merged 15 commits intomasterfrom
issue-1001
Mar 12, 2026
Merged

Replace datashader with matplotlib in user guide notebooks#1002
brendancol merged 15 commits intomasterfrom
issue-1001

Conversation

@brendancol
Copy link
Contributor

@brendancol brendancol commented Mar 11, 2026

Summary

Closes #1001.

  • Swap datashader rendering for matplotlib in all 12 user guide notebooks
  • datashader.Canvas.points/lines/polygonsxrspatial.rasterize() or direct DataArray construction
  • datashader.shade/stackmatplotlib.pyplot.imshow with alpha compositing
  • dynspread calls removed; line widths and scatter sizes handle visibility instead
  • datashader.transfer_functions.Imagesplt.subplots grids
  • 11 of 12 notebooks run clean; 6_Remote_Sensing needs the satellite data download first

Test plan

  • Executed all 11 self-contained notebooks with jupyter nbconvert --execute (xarray-spatial-everything env)
  • Confirmed 6_Remote_Sensing parses without errors (%time magic is valid Jupyter syntax)
  • Visually compare rendered plots against previous datashader output

Remove datashader as the rendering backend from all 12 affected user
guide notebooks. Each datashader call is replaced with the appropriate
matplotlib or xrspatial equivalent:

- shade/stack -> plt.imshow overlays with alpha compositing
- dynspread -> ax.scatter for points, ax.plot for lines
- Canvas.points/line -> manual DataArray creation or shapely + rasterize
- set_background -> ax.set_facecolor
- datashader.colors.Elevation -> matplotlib 'terrain' cmap
- Images side-by-side -> plt.subplots grid

Notebooks converted: 1_Surface, 2_Proximity, 3_Zonal, 4_Focal,
5_Classification, 6_Remote_Sensing, 7_Pathfinding, 8_Emerging_Hotspots,
11_Hydrology, 12_Flood_Analysis, 13_Fire_Analysis, 30_Zonal_Crosstab.
- Add numeric column to GeoDataFrame in 2_Proximity and 7_Pathfinding
  so rasterize() has a value to burn
- Use like= keyword for template DataArray instead of positional arg
- Fix 6_Remote_Sensing cell source format (string → list of strings)
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 11, 2026
Use ListedColormap with explicit colors instead of gradient colormaps
(Reds, Greens, cool) for binary mask overlays. When all unmasked values
are identical, gradient cmaps normalize vmin=vmax and render as white.
zfactor=1 produces curvature values in [-0.05, 0.06], far below the
thresholds of 0.5 and 1.0 used for the overlay masks. Bump to
zfactor=100 which gives values in [-4.6, 6.1], matching the documented
range for hilly terrain.
- Remove separate terrain generation for curvature; reuse the initial
  terrain throughout the notebook
- Replace numpy .data assignment with xarray .where() for slope,
  curvature, and aspect filtering
- Adjust curvature thresholds to match the default terrain's value range
- Mask on viewshed == -1 (not visible) instead of NaN, which is what
  the function actually returns for blocked cells
- Lower observer_elev from 100 to 5 so roughly 30% of terrain is
  occluded, making the viewshed result visually obvious
- Use ListedColormap for viewshed overlay consistency
- Add composite avalanche risk map combining slope, aspect, and curvature
- Fix curvature colors from red/green to orange/blue for colorblind users
- Add legends to all overlay plots (slope, curvature, aspect)
- Reframe aspect-slope map section as a cartographic bonus
- Split viewshed examples into separate 31_Viewshed notebook
- Move preview image to images/ directory
…1001)

Captures the conventions from the 1_Surface.ipynb work: cell structure,
xarray.plot usage, colorblind-safe palettes, legends, humanizer pass,
and file organization.
…1001)

- Rewrite 2_Proximity with xarray.plot, legends, colorblind-safe colormaps,
  humanized markdown, and coverage-planning narrative
- Fix rasterize NaN bug (fillna before astype int) in line proximity
- Use twilight cyclic colormap for direction, tab10 for allocation zones
- Add distance assumptions warning as alert-warning box
- Add direction preview image
- Update command: require 1-3 GIS alert boxes per notebook, eye-candy
  preview image with generation instructions
Rewrote 3_Zonal with xr.DataArray.plot.imshow, legends, colorblind-safe
palettes, and side-by-side crop visualization. Moved alert boxes in both
2_Proximity and 3_Zonal to sit next to the section they apply to instead
of clustering at the top. Updated user-guide-notebook command to match.
Rebuild 4_Focal.ipynb to match established notebook structure: proper
cell sequence, xr.DataArray.plot.imshow everywhere, legends on overlays,
colorblind-safe palettes, GIS alert boxes, and new sections for mean
smoothing and focal_stats. Switch hotspots base layer to gray hillshade
so overlay colors pop. Add focal_hotspots_preview.png.

Update What you'll build cells in 2_Proximity, 3_Zonal, and 4_Focal to
use ordered lists summarizing each step. Update user-guide-notebook
command to specify the ordered-list format.
…#1001)

Rebuild 5_Classification.ipynb: equal interval, quantile, natural breaks
with side-by-side comparison, custom reclassify with named elevation
bands, and connected-component regions. Add preview image.

Update notebook command to specify title format:
"Xarray-Spatial {module}: {tools covered}" with a real-world subtitle.
Apply the new format to all five notebooks (1_Surface through
5_Classification). Convert all What you'll build cells to ordered lists.
Strip ArcGIS links from Hydrology, Surface, Corridor, Proximity,
Viewshed, and Cost Distance notebooks. Refactor Emerging Hotspots
and Cost Distance notebooks to match established structure.
Remote Sensing: self-contained with synthetic spectral bands from
terrain elevation. Covers true color, NDVI, SAVI, ARVI, EVI, NBR,
and NDMI.

Pathfinding: redesigned with a 20x20 open grid so connectivity
differences are immediately visible. 8-conn gives a clean diagonal,
4-conn gives a staircase, friction-weighted curves around expensive
cells.
@brendancol brendancol merged commit 1f36ee5 into master Mar 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace datashader rendering with matplotlib in user guide notebooks

1 participant