Config round-trips — geopatcher.config¶
Every axis, stencil and patcher exposes get_config(). Nested components
serialise as {"class": ..., "config": ...} envelopes whose "class" is
the component's public path — "spatial.window.Hann",
"temporal.aggregation.Mean", "SpatialPatcher" (a user-defined axis
records its module.qualname). from_config(axis_envelope(obj)) rebuilds
obj, unless its type is forbid_in_yaml (closures, polygons,
backend-native anchors), whose config is a debug summary from_config
refuses.
import json
from geopatcher import spatial
from geopatcher.config import axis_envelope, from_config
window = spatial.window.Tukey(alpha=0.25)
saved = json.dumps(axis_envelope(window)) # '{"class": "spatial.window.Tukey", ...}'
assert from_config(json.loads(saved)).get_config() == window.get_config()
geopatcher.config.axis_envelope(obj)
¶
Wrap one component as {"class": <config_name>, "config": <get_config()>}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
An axis, stencil or patcher instance exposing |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The class-name + config envelope used by every nested config. |
Source code in packages/geotoolz-patcher/src/geopatcher/_src/_serialize.py
geopatcher.config.from_config(envelope)
¶
Rebuild an axis, stencil or patcher from its axis_envelope.
Nested envelopes (the axes inside a patcher, the stencil inside a stencil axis, the per-source aggregators of a matched patcher) are rebuilt recursively. The class is looked up by name among the loaded geopatcher component classes and their subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
envelope
|
Mapping[str, Any]
|
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
A new instance equivalent to the one the envelope was taken from. |
Raises:
| Type | Description |
|---|---|
TypeError
|
if the envelope is malformed or names an unknown or ambiguous class. |
RuntimeError
|
if the class is marked |
Examples:
>>> geom = spatial.geometry.Rectangular(size=(64, 64), boundary="pad")
>>> from_config(axis_envelope(geom)).get_config() == geom.get_config()
True
>>> stencil = TimeStencil("-9h", "3h", "1h", closed="both")
>>> from_config(json.loads(json.dumps(axis_envelope(stencil)))) == stencil
True
>>> from_config({"class": "spatial.window.Custom", "config": {}})
Traceback (most recent call last):
RuntimeError: from_config cannot rebuild spatial.window.Custom: ...
Source code in packages/geotoolz-patcher/src/geopatcher/_src/_serialize.py
geopatcher.config.config_name(cls)
¶
The name an envelope records for cls.
geopatcher's own classes are named by their public path, relative to
the package ("spatial.window.Hann", "temporal.aggregation.Mean",
"SpatialPatcher"); any other class — a user-defined axis — by its
module.qualname.
Examples:
Source code in packages/geotoolz-patcher/src/geopatcher/_src/_serialize.py
geopatcher.config.config_from_fields(obj, *, exclude=())
¶
Serialise a dataclass axis into its get_config dict.
Walks the dataclass's init fields in declaration order (private
init=False accumulator state is skipped automatically) and coerces
each value with jsonable_scalar; tuples, lists and arrays are
rebuilt as lists and mappings as dicts, with every element coerced
recursively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
A dataclass instance. |
required |
exclude
|
tuple[str, ...]
|
Field names to omit (e.g. fields needing custom handling). |
()
|
Returns:
| Type | Description |
|---|---|
``{field_name
|
coerced_value}`` in field declaration order. |