Skip to content

carto_flow.flow_cartogram.displacement

Displacement computation utilities for flow-based cartography.

Functions:

displace_coords_numba

displace_coords_numba(
    coords: ndarray,
    x_coords: ndarray,
    y_coords: ndarray,
    vx: ndarray,
    vy: ndarray,
    dt: float,
    dx: float,
    dy: float,
    use_parallel: bool = True,
) -> np.ndarray

Dispatch to parallel or serial JIT variant based on use_parallel.

max_abs_velocity

max_abs_velocity(vx: ndarray, vy: ndarray) -> float

Return max(max|vx|, max|vy|) over all grid cells in a single pass.

Equivalent to max(np.max(np.abs(vx)), np.max(np.abs(vy))) but avoids allocating the two intermediate abs arrays.

Parameters:

  • vx ((ndarray, shape(sy, sx))) –

    Velocity component arrays.

  • vy ((ndarray, shape(sy, sx))) –

    Velocity component arrays.

Returns:

  • float –

    Maximum absolute velocity in either direction.

max_velocity_magnitude

max_velocity_magnitude(vx: ndarray, vy: ndarray) -> float

Return max(sqrt(vx² + vy²)) over all grid cells in a single pass.

Equivalent to np.nanmax(np.sqrt(vx**2 + vy**2)) but avoids allocating the intermediate arrays, cutting memory bandwidth by ~3x at large grid sizes.

Parameters:

  • vx ((ndarray, shape(sy, sx))) –

    Velocity component arrays.

  • vy ((ndarray, shape(sy, sx))) –

    Velocity component arrays.

Returns:

  • float –

    Maximum velocity magnitude.