Skip to content
Open
5 changes: 3 additions & 2 deletions docs/source/getting_started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ needed:
- Additional ``polygonize`` return types and the ray-traced
``gpu_rtx`` functions (rtxpy also needs cupy).
* - ``examples``
- datashader
- Used by some of the example notebooks.
- matplotlib, geopandas, shapely
- Used by the example notebooks for rendering and vector
rasterization. datashader is no longer required.
* - ``doc``, ``tests``
- sphinx, pytest, ...
- Building this documentation and running the test suite.
Expand Down
286 changes: 91 additions & 195 deletions docs/source/user_guide/classification.ipynb

Large diffs are not rendered by default.

92 changes: 69 additions & 23 deletions docs/source/user_guide/fire.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"from datashader.transfer_functions import shade, stack, Images\n",
"\n",
"from xrspatial.fire import (\n",
" dnbr, rdnbr, burn_severity_class,\n",
" fireline_intensity, flame_length,\n",
" rate_of_spread, kbdi,\n",
")"
")\n"
]
},
{
Expand All @@ -60,8 +59,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": null,
"outputs": [],
"source": [
"H, W = 200, 200\n",
Expand Down Expand Up @@ -89,13 +88,18 @@
"pre_nbr_agg = make_da(pre_nbr, 'pre_nbr')\n",
"post_nbr_agg = make_da(post_nbr, 'post_nbr')\n",
"\n",
"pre_img = shade(pre_nbr_agg, cmap=['brown', 'yellow', 'green'], how='linear')\n",
"pre_img.name = 'Pre-fire NBR'\n",
"post_img = shade(post_nbr_agg, cmap=['brown', 'yellow', 'green'], how='linear')\n",
"post_img.name = 'Post-fire NBR'\n",
"imgs = Images(pre_img, post_img)\n",
"imgs.num_cols = 2\n",
"imgs"
"from matplotlib.colors import LinearSegmentedColormap\n",
"nbr_cmap = LinearSegmentedColormap.from_list('nbr', ['brown', 'yellow', 'green'], N=256)\n",
"\n",
"fig, axes = plt.subplots(1, 2, figsize=(12, 5))\n",
"im0 = axes[0].imshow(pre_nbr_agg, cmap=nbr_cmap)\n",
"axes[0].set_title('Pre-fire NBR')\n",
"fig.colorbar(im0, ax=axes[0])\n",
"im1 = axes[1].imshow(post_nbr_agg, cmap=nbr_cmap)\n",
"axes[1].set_title('Post-fire NBR')\n",
"fig.colorbar(im1, ax=axes[1])\n",
"plt.tight_layout()\n",
"plt.show()\n"
]
},
{
Expand All @@ -116,7 +120,12 @@
"dnbr_agg = dnbr(pre_nbr_agg, post_nbr_agg)\n",
"\n",
"print(f\"dNBR range: {float(dnbr_agg.min()):.3f} to {float(dnbr_agg.max()):.3f}\")\n",
"shade(dnbr_agg, cmap=['green', 'lightyellow', 'orange', 'red', 'darkred'], how='linear')"
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['green', 'lightyellow', 'orange', 'red', 'darkred'], N=256)\n",
"plt.imshow(dnbr_agg, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
Expand All @@ -138,7 +147,12 @@
"\n",
"print(f\"RdNBR range: {float(np.nanmin(rdnbr_agg.data)):.3f} to \"\n",
" f\"{float(np.nanmax(rdnbr_agg.data)):.3f}\")\n",
"shade(rdnbr_agg, cmap=['green', 'lightyellow', 'orange', 'red', 'darkred'], how='linear')"
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['green', 'lightyellow', 'orange', 'red', 'darkred'], N=256)\n",
"plt.imshow(rdnbr_agg, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -170,22 +184,39 @@
"\n",
"severity_float = severity.astype(np.float32)\n",
"severity_float.values = np.where(severity_float.values == 0, np.nan, severity_float.values)\n",
"shade(severity_float,\n",
" cmap=['darkgreen', 'green', 'lightgreen', 'yellow', 'orange', 'red', 'darkred'],\n",
" how='linear')"
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['darkgreen', 'green', 'lightgreen', 'yellow', 'orange', 'red', 'darkred'], N=256)\n",
"plt.imshow(severity_float, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": "### Fireline Intensity\n\nByram's fireline intensity: `I = H * w * R` where *H* is heat content (kJ/kg), *w* is fuel consumed (kg/m²), and *R* is spread rate (m/s). Output is kW/m. Fires below ~350 kW/m can be attacked by hand crews; above ~4,000 kW/m they typically need indirect attack or aerial resources.\n\n`spread_rate_units` defaults to `'m/min'` so the output of `rate_of_spread` (below) can be passed straight in. The synthetic `spread` array here is already in m/s, so we pass `spread_rate_units='m/s'`."
"source": "### Fireline Intensity\n\nByram's fireline intensity: `I = H * w * R` where *H* is heat content (kJ/kg), *w* is fuel consumed (kg/m\u00b2), and *R* is spread rate (m/s). Output is kW/m. Fires below ~350 kW/m can be attacked by hand crews; above ~4,000 kW/m they typically need indirect attack or aerial resources.\n\n`spread_rate_units` defaults to `'m/min'` so the output of `rate_of_spread` (below) can be passed straight in. The synthetic `spread` array here is already in m/s, so we pass `spread_rate_units='m/s'`."
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": "fuel = make_da((veg * 3.0 + rng.uniform(0, 0.5, (H, W))).astype(np.float32), 'fuel')\nspread = make_da((0.02 + 0.03 * rng.uniform(0, 1, (H, W))).astype(np.float32), 'spread')\n\nintensity_agg = fireline_intensity(fuel, spread, heat_content=18000,\n spread_rate_units='m/s')\n\nprint(f\"Intensity range: {float(intensity_agg.min()):.1f} to {float(intensity_agg.max()):.1f} kW/m\")\nshade(intensity_agg, cmap=['lightyellow', 'orange', 'red', 'darkred'], how='linear')"
"source": [
"fuel = make_da((veg * 3.0 + rng.uniform(0, 0.5, (H, W))).astype(np.float32), 'fuel')\n",
"spread = make_da((0.02 + 0.03 * rng.uniform(0, 1, (H, W))).astype(np.float32), 'spread')\n",
"\n",
"intensity_agg = fireline_intensity(fuel, spread, heat_content=18000,\n",
" spread_rate_units='m/s')\n",
"\n",
"print(f\"Intensity range: {float(intensity_agg.min()):.1f} to {float(intensity_agg.max()):.1f} kW/m\")\n",
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['lightyellow', 'orange', 'red', 'darkred'], N=256)\n",
"plt.imshow(intensity_agg, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
"cell_type": "markdown",
Expand All @@ -205,7 +236,12 @@
"fl_agg = flame_length(intensity_agg)\n",
"\n",
"print(f\"Flame length range: {float(fl_agg.min()):.2f} to {float(fl_agg.max()):.2f} m\")\n",
"shade(fl_agg, cmap=['lightyellow', 'orange', 'red'], how='linear')"
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['lightyellow', 'orange', 'red'], N=256)\n",
"plt.imshow(fl_agg, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
Expand All @@ -232,7 +268,12 @@
"ros_agg = rate_of_spread(slope_agg, wind_agg, moisture_agg, fuel_model=1)\n",
"\n",
"print(f\"Rate of spread: {float(ros_agg.min()):.2f} to {float(ros_agg.max()):.2f} m/min\")\n",
"shade(ros_agg, cmap=['lightyellow', 'orange', 'red', 'darkred'], how='linear')"
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['lightyellow', 'orange', 'red', 'darkred'], N=256)\n",
"plt.imshow(ros_agg, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
Expand All @@ -250,7 +291,7 @@
"source": [
"for fm, name in [(1, 'Short grass'), (3, 'Tall grass'), (4, 'Chaparral'), (8, 'Timber litter')]:\n",
" r = rate_of_spread(slope_agg, wind_agg, moisture_agg, fuel_model=fm)\n",
" print(f\" Model {fm:2d} ({name:15s}): {float(r.min()):8.2f} to {float(r.max()):8.2f} m/min\")"
" print(f\" Model {fm:2d} ({name:15s}): {float(r.min()):8.2f} to {float(r.max()):8.2f} m/min\")\n"
]
},
{
Expand Down Expand Up @@ -292,7 +333,12 @@
"print(f\"Day 31: {history[31]:.1f} (post-rain)\")\n",
"print(f\"Day 36: {history[-1]:.1f} (5 days after rain)\")\n",
"\n",
"shade(current, cmap=['green', 'yellow', 'orange', 'red'], how='linear')"
"plt.figure(figsize=(8, 5))\n",
"from matplotlib.colors import LinearSegmentedColormap\n",
"_cmap = LinearSegmentedColormap.from_list('c', ['green', 'yellow', 'orange', 'red'], N=256)\n",
"plt.imshow(current, cmap=_cmap)\n",
"plt.colorbar()\n",
"plt.show()\n"
]
},
{
Expand Down Expand Up @@ -322,4 +368,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
258 changes: 82 additions & 176 deletions docs/source/user_guide/focal.ipynb

Large diffs are not rendered by default.

Loading
Loading