Skip to content

Refactor user guide notebooks 10-31 to standard structure#1003

Merged
brendancol merged 42 commits intomasterfrom
refactor/user-guide-10-31
Mar 13, 2026
Merged

Refactor user guide notebooks 10-31 to standard structure#1003
brendancol merged 42 commits intomasterfrom
refactor/user-guide-10-31

Conversation

@brendancol
Copy link
Contributor

Summary

  • Rewrote 22 user guide notebooks (10_Mahalanobis_Distance through 31_Viewshed) to follow a consistent cell layout: title, "What you'll build" preview, standardized imports, synthetic data, worked examples, alert boxes, and references
  • Fixed matplotlib rendering (removed matplotlib.use('Agg') overrides and plt.show() calls that broke inline output in Jupyter)
  • Fixed rasterize scanline fill off-by-one: added half-pixel offset so integer positions hit pixel centers instead of edges
  • Fixed rotated sigma ellipses in Mahalanobis notebook (eigenvalue ordering from np.linalg.eigh)
  • Fixed coordinate mismatch in Hydrology notebook where scatter markers used pixel indices instead of DataArray coordinate space

Test plan

  • Run each notebook with jupyter nbconvert --execute (all 22 pass on this branch)
  • Spot-check plot outputs for correctness (preview images saved in images/)
  • Verify rasterize.py change doesn't break existing tests

Restructure 14_Dasymetric_Mapping.ipynb to match the standard user
guide format. Add coverage for pycnophylactic interpolation and
validate_disaggregation. Replace raw ax.imshow with DataArray.plot.imshow,
add legends and colorbars, include alert boxes, and close with a
four-method comparison panel.
Restructure to standard cell layout. Replace ax.imshow with
DataArray.plot.imshow, add colorbars, fix colorblind-unsafe
green/red pair, add GIS alert boxes, generate preview image.
Restructure to standard cell layout. Replace raw imshow with
DataArray.plot.imshow, add colorbars and legends, include GIS
alert boxes, generate preview image.
Restructure to standard cell layout. Replace raw imshow with
DataArray.plot.imshow, add colorbars and legends, include GIS
alert boxes for HAND thresholds and CN limitations, generate
preview image.
Restructure to standard cell layout. Replace raw imshow with
DataArray.plot.imshow, fix red/green colormap, add legends and
colorbars, include GIS alert boxes, generate preview image.
Restructure to standard cell layout. Replace raw imshow with
DataArray.plot.imshow, add colorbars and legends, include GIS
alert boxes, generate preview image.
Restructure to match the standard user guide template: title with
module name, preview image, nav links, hillshade overlays using
xr.DataArray.plot.imshow, Patch legends, GIS alert boxes for radius
units and slope units, and a References section. Data generation
switched from hand-rolled Gaussians to generate_terrain for
consistency with other notebooks.
Restructure 20_Water_Indices.ipynb to match the standard user guide
format: title/subtitle, preview image, standard imports, single data
generation cell, individual analysis sections with legends and GIS
alert boxes, and a references section. Replace raw ax.imshow calls
with xr.DataArray.plot.imshow, add a more interesting synthetic scene
with a lake and river channel, and include a water mask overlay section.
Restructure to standard cell layout. Replace raw imshow with
DataArray.plot.imshow, add colorbars and legends, include GIS
alert boxes, generate preview image.
Restructure the notebook to match the standard user guide format:
generate_terrain with hillshade overlays, plot.imshow throughout,
GIS alert boxes for edge handling and kernel sizing, circular vs
square kernel comparison with legend, and a preview image.
Restructure to match the standard user guide template: title with
subtitle, "What you'll build" preview, consolidated data generation,
hillshade overlays, plot.imshow throughout, GIS alert boxes for edge
effects and sigma_range selection, cross-section plot with colorblind-
safe palette, and references section.
Restructure the notebook into the established cell sequence: title with
subtitle, what-you'll-build overview with preview image and nav links,
imports, data section, then individual analysis sections each with markdown
intro, code, and optional alerts.

Replace all raw ax.imshow calls with xr.DataArray.plot.imshow. Add legends
to overlay plots, swap magma for inferno on variance maps, and add GIS alert
boxes covering variance interpretation and ordinary vs universal kriging.
Generate a preview image saved to images/kriging_preview.png.
Restructure to standard cell layout with title/subtitle, what-you'll-build,
and section pattern. Replace ax.imshow with DataArray.plot.imshow, add
source markers and legends, switch to inferno colormap, add GIS alert
boxes for threshold units and corridor-vs-pathfinding, add references.
Restructure to standard cell layout. Replace ax.imshow with
DataArray.plot.imshow, use coolwarm for difference maps, add
colorbar labels, include parameter sensitivity and GPU alert
boxes, add references.
Restructure to standard cell layout. Replace bare .plot() with
DataArray.plot.imshow, add colorbar labels, include resolution
alert box, add references.
Restructure to standard cell layout. Replace ax.imshow with
DataArray.plot.imshow, add colorbars and legends, include gray
levels alert box, add references.
Restructure to standard cell layout. Replace ax.imshow with
DataArray.plot.imshow, add hillshade overlays, remove accessor
demo, add references.
Restructure to standard cell layout. Replace ax.imshow with
DataArray.plot.imshow, fix cell ordering, add routing model
comparison alert box, add references.
plt.show() triggers a UserWarning on non-interactive backends
(nbconvert, papermill). Jupyter's inline backend renders figures
automatically without it.
Remove matplotlib.use('Agg') which blocks inline rendering in Jupyter.
Add %matplotlib inline magic to all notebooks. Fix savefig paths and
add pathlib.Path('images').mkdir() guards. Fix broken try/except in
notebook 19. Re-execute all notebooks to generate plot outputs.
Ellipse width is rotated by angle, so it needs to match the major
eigenvalue. Reversed eigvals order so the major axis aligns with the
major eigenvector direction.
Red X markers for original hand-placed points, blue dots for snapped
positions on channels. Updated preview image to match.
Increase marker size to s=200, use yellow stars for snapped points and
red X's for originals with black edges for contrast against the
watershed colors.
scatter() was using raw row/col indices while plot.imshow() uses
DataArray x/y coordinates. Convert indices to data coords so the
markers land on the correct raster cells.
Dilate flow paths to 3px width, use neon colormap on dark background
with muted hillshade for high-contrast path visibility.
Add half-pixel offset to scanline edge extraction so integer
positions correspond to pixel centers instead of edges. Re-execute
notebooks 10, 23-31 to capture updated outputs.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 12, 2026
Drop terrain colormap drape from basemap (hillshade only), use white
backgrounds for flow accumulation plots, raise overlay alpha so data
layers read clearly against a single neutral base.
Remove terrain colormap drape, use hillshade-only basemap, raise
overlay alpha, and use cleaner sequential colormaps for depth/HAND/
travel time so data reads clearly against the neutral gray base.
contours() returned raw array indices, which produced misaligned
contour lines when plotted on xarray imshow axes that use the
DataArray's coordinate values.  Transform output coordinates from
array indices to the DataArray's y/x coordinate space via np.interp.
Update tests, contour_explorer, and user guide notebook accordingly.
…outputs

Switch 24_Sky_View_Factor from hand-crafted sinusoidal terrain to
generate_terrain with ridged noise and domain warping. Add overlay
blend composite panel showing hillshade + SVF together. Clear outputs
from all user guide notebooks.
Zero-weight pixels (water, parks) were absorbing leftover population
during the overflow pass. Set class-0 density cap to 0 by default and
restrict overflow distribution to habitable pixels only. Expose
class_breaks and density_caps parameters on the public disaggregate API.
@brendancol brendancol merged commit d3d826d into master Mar 13, 2026
10 of 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.

1 participant