Aurora adapter Python API¶
This backend-specific reference is generated from the sibling geoxplain-aurora-adapter checkout used to build the site. These APIs target Microsoft Aurora; they are separate from the model-agnostic GeoXplain Python API. The package's root exports these target, compute, result, overlay, and listener APIs.
Targets¶
geoxplain_aurora_adapter.schema.spec.Target
¶
Namespace for TargetSpec factory methods.
Usage::
import geoxplain_aurora_adapter as ax
# Single grid point
target = ax.Target.point(var="q", level=850, lat=46.2, lon=8.8,
timestamp="2024-03-20T00:00:00Z")
# Box of default size (2.0° lat × 3.0° lon) centered at (lat, lon)
target = ax.Target.box(var="q", level=850, lat=46.25, lon=8.75,
timestamp="2024-03-20T00:00:00Z")
# Box of custom size
target = ax.Target.box(var="q", level=850, lat=46.25, lon=8.75,
size=(1.5, 2.5),
timestamp="2024-03-20T00:00:00Z")
geoxplain_aurora_adapter.schema.spec.TargetSpec
dataclass
¶
TargetSpec(
var: str,
level: Optional[int],
mode: str,
timestamp: str,
lat: Optional[float] = None,
lon: Optional[float] = None,
size: Optional[tuple[float, float]] = None,
)
Fully-resolved specification of the XIA attribution target.
Fields
var: Variable name in the model output (e.g. "q", "t", "zwd").
level: Pressure level in hPa (e.g. 850). None for surface-only vars.
mode: Spatial selection mode: "point" or "box".
timestamp: ISO-8601 string for the second (t1) input timestep, e.g.
"2024-03-20T00:00:00Z". This is what you pass when
constructing a target, and it is preserved unchanged as the
frame's displayed timestamp (frame.target.timestamp ==
frame.timestamp == t1). The explained prediction is the
6 h-ahead step t2 = t1 + lead, recorded in the frame's
lead_hours metadata rather than by shifting the timestamp.
lat/lon: Point coordinates (mode="point") or box center
(mode="box"). Longitudes accepted in either
-180..180 or 0..360 convention.
size: Box full extent in degrees (dlat, dlon) (mode="box"
only). The actual bounds are
[lat-dlat/2, lat+dlat/2] × [lon-dlon/2, lon+dlon/2].
point
classmethod
¶
Single-grid-point target.
box
classmethod
¶
box(
*,
var: str,
level: Optional[int],
lat: float,
lon: float,
timestamp: str,
size: tuple[float, float] = DEFAULT_BOX_SIZE,
) -> "TargetSpec"
Box-mean target centered at (lat, lon) with extent size.
box_bounds
¶
Return (south, north, west, east) for mode="box".
as_widget_dict
¶
Return the target in the model-agnostic GeoXplain viewer format.
Compute methods¶
geoxplain_aurora_adapter.api.methods.run_saliency
¶
run_saliency(
target: TargetSpec,
input: list[str],
*,
remote: Optional[str] = None,
checkpoint_path: Optional[str] = None,
timeframes: int = 1,
step_hours: int = 6,
levels: Optional[int | list[int]] = None,
**options,
) -> XiaResult
Compute vanilla gradient saliency attribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
TargetSpec
|
|
required |
input
|
list[str]
|
|
required |
remote
|
Optional[str]
|
|
None
|
checkpoint_path
|
Optional[str]
|
|
None
|
timeframes
|
int
|
|
1
|
step_hours
|
int
|
|
6
|
levels
|
Optional[int | list[int]]
|
|
None
|
**options
|
|
{}
|
Returns:
| Type | Description |
|---|---|
XiaResult
|
One frame, or a multi-frame bundle when |
geoxplain_aurora_adapter.api.methods.run_ig
¶
run_ig(
target: TargetSpec,
input: list[str],
*,
remote: Optional[str] = None,
checkpoint_path: Optional[str] = None,
timeframes: int = 1,
step_hours: int = 6,
n_steps: int = 32,
baseline_sigma_deg: float = 2.5,
levels: Optional[int | list[int]] = None,
**options,
) -> XiaResult
Compute Integrated Gradients attribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
TargetSpec
|
|
required |
input
|
list[str]
|
|
required |
remote
|
Optional[str]
|
|
None
|
checkpoint_path
|
Optional[str]
|
|
None
|
timeframes
|
int
|
|
1
|
step_hours
|
int
|
|
6
|
n_steps
|
int
|
|
32
|
baseline_sigma_deg
|
float
|
|
2.5
|
levels
|
Optional[int | list[int]]
|
|
None
|
Returns:
| Type | Description |
|---|---|
XiaResult
|
One frame, or a multi-frame bundle when |
geoxplain_aurora_adapter.api.methods.run_rise
¶
run_rise(
target: TargetSpec,
input: list[str],
*,
remote: Optional[str] = None,
checkpoint_path: Optional[str] = None,
timeframes: int = 1,
step_hours: int = 6,
n_masks: int = 1200,
cells_h: int = 400,
cells_w: int = 800,
seed: int = 42,
baseline_sigma_deg: float = 2.5,
**options,
) -> XiaResult
Compute RISE (Randomized Input Sampling for Explanation) attribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
TargetSpec
|
|
required |
input
|
list[str]
|
|
required |
remote
|
Optional[str]
|
|
None
|
checkpoint_path
|
Optional[str]
|
|
None
|
timeframes
|
int
|
|
1
|
step_hours
|
int
|
|
6
|
n_masks
|
int
|
|
1200
|
cells_h
|
int
|
|
400
|
seed
|
int
|
|
42
|
baseline_sigma_deg
|
float
|
|
2.5
|
Returns:
| Type | Description |
|---|---|
XiaResult
|
One frame, or a multi-frame bundle when |
geoxplain_aurora_adapter.api.methods.run_vit_cx
¶
run_vit_cx(
target: TargetSpec,
input: list[str],
*,
remote: Optional[str] = None,
checkpoint_path: Optional[str] = None,
timeframes: int = 1,
step_hours: int = 6,
hook_stage: int = 1,
n_clusters: int = 4096,
smooth_sigma: float | tuple | None = 0,
baseline_sigma_deg: float = 2.5,
**options,
) -> XiaResult
Compute ViT-CX (cluster-based causal attribution) attribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
TargetSpec
|
|
required |
input
|
list[str]
|
|
required |
remote
|
Optional[str]
|
|
None
|
checkpoint_path
|
Optional[str]
|
|
None
|
timeframes
|
int
|
|
1
|
step_hours
|
int
|
|
6
|
hook_stage
|
int
|
|
1
|
n_clusters
|
int
|
|
4096
|
smooth_sigma
|
float | tuple | None
|
|
0
|
baseline_sigma_deg
|
float
|
|
2.5
|
Returns:
| Type | Description |
|---|---|
XiaResult
|
One frame, or a multi-frame bundle when |
geoxplain_aurora_adapter.api.methods.run_rollout
¶
run_rollout(
target: TargetSpec,
input: list[str],
*,
method: str = "saliency",
timeframes: int,
remote: Optional[str] = None,
checkpoint_path: Optional[str] = None,
n_steps: int = 32,
baseline_sigma_deg: float = 2.5,
timeout_s: float = 1800.0,
poll_interval_s: float = 2.0,
poll_max_s: float = 30.0,
) -> XiaResult
Compute autoregressive rollout XIA in fixed six-hour Aurora frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
TargetSpec
|
Scalar output target for the first frame. |
required |
input
|
list[str]
|
Input variable names to attribute. |
required |
method
|
str
|
|
'saliency'
|
timeframes
|
int
|
Required positive number of autoregressive frames. |
required |
remote
|
Optional[str]
|
Listener URL, or |
None
|
checkpoint_path
|
Optional[str]
|
Override the default checkpoint in local mode only. |
None
|
n_steps
|
int
|
Integrated Gradients options, ignored for Saliency. |
32
|
baseline_sigma_deg
|
int
|
Integrated Gradients options, ignored for Saliency. |
32
|
timeout_s
|
float
|
Remote-client timeout and polling controls. |
1800.0
|
poll_interval_s
|
float
|
Remote-client timeout and polling controls. |
1800.0
|
poll_max_s
|
float
|
Remote-client timeout and polling controls. |
1800.0
|
Returns:
| Type | Description |
|---|---|
XiaResult
|
One bundle containing all rollout frames. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
NotImplementedError
|
If rollout is requested with RISE or ViT-CX. |
Weather overlays¶
geoxplain_aurora_adapter.api.methods.pull_overlay
¶
pull_overlay(
variable: str,
dates: str | list[str] | tuple[str, ...] | None = None,
*,
level: Optional[int] = None,
remote: Optional[str] = None,
name: Optional[str] = None,
unit: Optional[str] = None,
colormap: Optional[str] = None,
visible: bool = True,
overlay_time: str = "input",
step_hours: int = 6,
timeout_s: float = 1800.0,
poll_interval_s: float = 2.0,
poll_max_s: float = 30.0,
) -> OverlayResult
Pull ERA5 fields as timestamped viewer overlays.
dates accepts ISO timestamps, dates, ranges, or None to reuse the
XIA frame timestamps recorded this session. The displayed frame keeps its
requested timestamp (Aurora's most-recent input step t1), so overlay_time
chooses the field time relative to it: "input" (0 h, the default — the
frame's own time t1), "prior" (-6 h, the earlier input step t0), or
"predicted" (+6 h, the forecast valid time t2). It also sets a
time_label annotation on the result for the non-default choices
("prior" → "Aurora input step t0", "predicted" → "Forecast
valid time t2"), which the viewer shows next to the offset. Remote calls
use the listener at remote; local calls read from the configured
dataset.
Attribution results¶
geoxplain_aurora_adapter.schema.result.XiaFrame
dataclass
¶
XiaFrame(
target: TargetSpec,
timestamp: str,
attributions: dict[str, dict[str, ndarray]],
diverging: bool,
meta: dict = dict(),
)
A single time step of an :class:XiaResult bundle.
Attributes:
| Name | Type | Description |
|---|---|---|
target |
TargetSpec
|
The scalar that was explained (what variable, where, when). |
timestamp |
str
|
ISO-8601 string of the requested time — Aurora's most-recent input
step t1 — which is what the viewer displays and equals
|
attributions |
dict[str, dict[str, ndarray]]
|
|
diverging |
bool
|
Whether the attribution maps contain significant negative values. Auto-detected from the sign distribution; controls whether the visualization widget uses a diverging colormap. |
meta |
dict
|
Optional per-frame diagnostic metadata: |
as_widget_dict
¶
Return this frame's target as a geoxplain-compatible dict.
The visualization side's importer calls as_widget_dict() on each
frame (not on frame.target) to place the target point/box. When
an in-memory :class:XiaResult is handed straight to the widget — the
live/remote path, with no .xia.npz round-trip — the frame object is
this class, so it must expose the method itself; otherwise the target
is silently dropped. Delegates to :meth:TargetSpec.as_widget_dict.
geoxplain_aurora_adapter.schema.result.XiaResult
dataclass
¶
XiaResult(
method: str,
frames: list[XiaFrame],
layer_labels: dict[str, str] = dict(),
meta: dict = dict(),
method_label: str = "",
)
Self-describing XIA attribution bundle (one method, one or more frames).
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
XIA method id: |
method_label |
str
|
Human-readable method name for display, e.g. |
frames |
list[XiaFrame]
|
One :class: |
layer_labels |
dict[str, str]
|
Optional |
meta |
dict
|
Bundle-level diagnostic metadata: |
single
classmethod
¶
single(
method: str,
target: TargetSpec,
timestamp: str,
attributions: dict[str, dict[str, ndarray]],
diverging: bool,
meta: dict | None = None,
*,
layer_labels: dict[str, str] | None = None,
frame_meta: dict | None = None,
method_label: str = "",
) -> "XiaResult"
Build a one-frame bundle.
meta becomes the bundle-level metadata; frame_meta (if given)
is attached to the single frame. For the common case where there is
only one frame, passing diagnostics via meta is fine.
save
¶
Save to a .xia.npz archive.
If path does not end with ".xia.npz", the suffix is appended
automatically.
load
classmethod
¶
Load from a .xia.npz archive (format_version == 2).
to_msgpack
¶
Serialize to msgpack bytes for HTTP transport.
Arrays are embedded as raw float32 LE bytes + shape info. The
result is designed to be deserialised by XiaResult.from_msgpack.
from_msgpack
classmethod
¶
Deserialize from msgpack bytes produced by XiaResult.to_msgpack.
Overlay results¶
geoxplain_aurora_adapter.schema.overlay.OverlayFrame
dataclass
¶
One timestamped raw weather-field overlay frame.
geoxplain_aurora_adapter.schema.overlay.OverlayResult
dataclass
¶
OverlayResult(
variable: str,
level: Optional[int],
frames: list[OverlayFrame],
label: str,
unit: str = "",
colormap: str = "viridis",
visible: bool = True,
overlay_offset_hours: int = 0,
time_label: Optional[str] = None,
lat: Optional[ndarray] = None,
lon: Optional[ndarray] = None,
meta: dict = dict(),
)
Self-contained weather-field overlay bundle.
frames are raw ERA5/Aurora-grid arrays. The visualization package applies
its existing preprocessing pipeline when the overlay is added to a widget.
from_msgpack
classmethod
¶
Deserialize bytes produced by :meth:to_msgpack.
Listener¶
geoxplain_aurora_adapter.api.listener.listen_for_request
¶
listen_for_request(
port: int = 8765,
host: str = "127.0.0.1",
persistent: bool = False,
prewarm: bool = False,
memory_retention: Optional[str] = None,
result_retention: Optional[str] = None,
**sbatch_kwargs,
) -> None
Start the geoxplain_aurora_adapter HTTP listener server.
Mode is auto-detected:
+------------------+------------------+---------------------------------+ | GPU visible? | sbatch on PATH? | Resolved mode | +==================+==================+=================================+ | yes | yes | sbatch-oneshot (or sbatch-persistent if persistent) | | no | yes | sbatch-oneshot (or sbatch-persistent if persistent) | | yes | no | gpu-listener | | no | no | Error | +------------------+------------------+---------------------------------+
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
port
|
int
|
|
8765
|
host
|
str
|
|
'127.0.0.1'
|
persistent
|
bool
|
|
False
|
prewarm
|
bool
|
|
False
|
memory_retention
|
Optional[str]
|
|
None
|
result_retention
|
Optional[str]
|
|
None
|
**sbatch_kwargs
|
|
{}
|