Skip to content

InferenceResult

The object returned by GeoBayesianNetwork.infer().

Holds per-pixel probability distributions for one or more query nodes. The spatial metadata (crs, transform) mirrors the reference grid used during inference.

Class reference

InferenceResult dataclass

Holds per-pixel probability distributions for one or more query nodes.

Attributes

probabilities: Mapping from query node name to a (H, W, n_states) float32 array. NaN where any input was NoData. state_names: Mapping from query node name to its ordered list of state labels. crs: CRS of the output grid as an EPSG string or WKT. transform: Affine pixel-to-world transform of the output grid.

probabilities instance-attribute

probabilities

state_names instance-attribute

state_names

crs instance-attribute

crs

transform instance-attribute

transform

entropy

entropy(node)

Shannon entropy (bits) for node, shape (H, W).

to_geotiff

to_geotiff(output_dir)

Write one multi-band GeoTIFF per query node.

Band layout (1-indexed): Bands 1…N — P(state_i | evidence) for each state i Band N+1 — Shannon entropy

Band descriptions contain the state label or "entropy".

to_xarray

to_xarray()

Return an xarray Dataset with spatial coordinates.

Each query node becomes a DataArray with dimensions (state, y, x). Entropy is added as a separate variable {node}_entropy with dimensions (y, x).

show_map

show_map(output_dir='.', filename='map.html', overlay_opacity=0.65, open_browser=True, extra_layers=None, show_probability_bands=True, show_category=True, show_entropy=True)

Generate and optionally open an interactive Leaflet map.

Parameters

output_dir: Directory to write the HTML file into. filename: Output filename (default map.html). overlay_opacity: Opacity of probability overlays (0–1). open_browser: If True (default), open the map in the default browser. extra_layers: Additional named (H, W) arrays to include as overlays (e.g. {"Slope angle (°)": slope_deg}). show_probability_bands: If False, omit the individual P(state) layers (default True). show_category: If False, omit the argmax category layer (default True).

Returns

Path Path to the written HTML file.

Band layout in GeoTIFF output

When calling to_geotiff(output_dir), one multi-band GeoTIFF is written per query node:

Band Content
1 … N P(state_i | evidence) for each state i
N + 1 Shannon entropy (bits)

Band descriptions in the file metadata contain the state label or "entropy".

Example

result = bn.infer(query=["avalanche_risk"])

# Inspect probabilities
probs = result.probabilities["avalanche_risk"]  # (H, W, 3)
print(probs.shape)  # (80, 240, 3) for an 80×240 grid with 3 states

# Entropy map
ent = result.entropy("avalanche_risk")  # (H, W)

# Export
result.to_geotiff("output/")   # writes avalanche_risk.tif
ds = result.to_xarray()        # xarray Dataset with (state, y, x) dims
result.show_map()              # opens browser