Replace datashader with matplotlib in user guide notebooks#1002
Merged
brendancol merged 15 commits intomasterfrom Mar 12, 2026
Merged
Replace datashader with matplotlib in user guide notebooks#1002brendancol merged 15 commits intomasterfrom
brendancol merged 15 commits intomasterfrom
Conversation
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)
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1001.
datashader.Canvas.points/lines/polygons→xrspatial.rasterize()or direct DataArray constructiondatashader.shade/stack→matplotlib.pyplot.imshowwith alpha compositingdynspreadcalls removed; line widths and scatter sizes handle visibility insteaddatashader.transfer_functions.Images→plt.subplotsgrids6_Remote_Sensingneeds the satellite data download firstTest plan
jupyter nbconvert --execute(xarray-spatial-everything env)6_Remote_Sensingparses without errors (%timemagic is valid Jupyter syntax)