xrspatial.diffusion.diffuse#
- xrspatial.diffusion.diffuse(agg, diffusivity=1.0, steps=1, dt=None, boundary='nan', name='diffuse')[source]#
Run forward-Euler diffusion on a 2D scalar field.
Solves
du/dt = alpha * laplacian(u)using an explicit 5-point stencil for steps time steps.- Parameters:
agg (xarray.DataArray) – 2D raster representing the initial scalar field (temperature, concentration, etc.).
diffusivity (float or xarray.DataArray) – Thermal/mass diffusivity. A scalar applies uniformly; a DataArray of the same shape allows spatially varying diffusivity.
steps (int, default 1) – Number of time steps to run. Capped at 100,000 to prevent a single call from pinning a CPU indefinitely.
dt (float or None) – Time step size. When
Nonethe largest stable step is chosen automatically:dt = 0.25 * dx**2 / max(alpha).boundary (str, default
'nan') – Edge handling:'nan','nearest','reflect', or'wrap'.name (str, default
'diffuse') – Name for the output DataArray.
- Returns:
Scalar field after steps diffusion steps.
- Return type:
xarray.DataArray