distance_localization⚓︎
Distance-based localization implementation.
DistanceLocalization
⚓︎
Bases: LocalizationBase
Distance-based localization strategy for sparse mask projection.
Follows the same init/call pattern as AutoAdaptiveLocalization:
- All configuration is parsed and stored at __init__ time.
- __call__ assembles and returns the sparse localization operator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
dict or list
|
Localization configuration. Must contain:
Plus one of:
- a |
required |
data
|
DataFrame
|
Observed data with time indices as rows and data types as columns. |
None
|
parameters
|
list of str
|
State parameter names used as defaults in |
None
|
ensemble_size
|
int
|
Ensemble size; used by the Furrer-Bengtsson kernel. |
None
|
prior_info
|
dict
|
Per-parameter prior information ( |
None
|
__call__(curr_data=None, curr_time=None, curr_param=None)
⚓︎
Build the sparse localization operator for the current assimilation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
curr_data
|
list of str
|
Data types to include. Defaults to |
None
|
curr_time
|
list
|
Time indices to include. Defaults to |
None
|
curr_param
|
list of str
|
State parameters to update. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
scipy.sparse matrix, shape (n_active_cells, n_obs)
|
Sparse localization operator. |
__init__(info, data=None, parameters=None, ensemble_size=None, prior_info=None)
⚓︎
Initialize the DistanceLocalization instance.
Spatial localization entries — one per (data_type, time, parameter)
combination — are supplied either via an external CSV file or as
comma-separated inline rows embedded in the info dict key.
All info keys map directly to the [dataassim.localization]
table in a TOML config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
info
|
dict or list
|
Localization configuration. Recognised keys: field : list of int, required
Grid dimensions actnum : str, optional
Path to a taper_func : { entries : str, list, or dict, optional Localization entries configuration. Three formats are supported: |
required |
data
|
DataFrame
|
Observed data whose index contains the assimilation time
steps (must match the |
None
|
parameters
|
list of str
|
Ordered list of state parameter names (e.g.
|
None
|
ensemble_size
|
int
|
Ensemble size Ne. Only affects the Furrer-Bengtsson kernel
( |
None
|
prior_info
|
dict
|
Per-parameter grid sizes. Required only when a parameter
appears in |
None
|
Notes
CSV row format
Each entry is a single space-separated line with 11 fields (or 12 if the data-type name contains a space)::
taper x_pos y_pos z_pos radius z_range aniso rotation data_type time param
For two-word data types (e.g. WOPR PRO1) use 12 fields::
taper x_pos y_pos z_pos radius z_range aniso rotation word1 word2 time param
Field descriptions:
- taper — kernel tag:
gc,fb, orregion. - x_pos — observation x-cell index on the grid (0-based), along the
nxaxis. - y_pos — observation y-cell index on the grid (0-based), along the
nyaxis. - z_pos — observation layer index on the grid (0-based).
- radius — kernel half-radius in grid cells. For
gcthe full support spans2 × radiuscells from the center. - z_range —
":"to spread the kernel across all nz layers, or an integer to restrict it to that single layer. - aniso — anisotropy ratio (x-axis scaling factor). Use
1.0for isotropic kernels;2.0compresses the kernel to half-width in the x-direction. - rotation — clockwise rotation of the kernel in degrees.
Use
0.0for axis-aligned kernels. - data_type — observation type name, case-insensitive. Must
match a column in the
dataDataFrame. - time — assimilation time step; must match an index value
of the
dataDataFrame. - param — state parameter name, case-insensitive. Must appear
in the
parameterslist.
Examples:
TOML config using an external CSV file (recommended for many observation types or time steps):
[dataassim.localization]
name = "distance_loc"
field = [1, 20, 20] # [nz, nx, ny]
taper_func = "gc"
"loc_entries.csv" = true # key = filename; value is ignored
Example loc_entries.csv (Gaspari-Cohn, isotropic, all layers):
gc 10 10 0 6 : 1.0 0.0 pressure 400.0 permx
gc 10 10 0 6 : 1.0 0.0 pressure 800.0 permx
gc 5 15 0 4 : 1.0 0.0 wopr pro1 400.0 permx
gc 5 15 0 4 : 2.0 30.0 wopr pro1 800.0 permx
TOML config using the Furrer-Bengtsson kernel with active-cell mask and anisotropic entries in the CSV:
[dataassim.localization]
name = "distance_loc"
field = [2, 30, 40] # two-layer, 30×40 lateral grid
taper_func = "fb"
actnum = "active.npz"
"loc_entries.csv" = true
loc_entries.csv restricting each observation to layer 0 only
(z_range = 0) with anisotropic, rotated kernel:
Python config using the entries key with a list of dicts
(modern preferred approach):
info = {
"field": [1, 20, 20],
"taper_func": "gc",
"entries": [
{
"taper": "gc",
"x": 10, "y": 10, "z": 0,
"radius": 6,
"z_range": ":",
"aniso": 1.0, "rotation": 0.0,
"data_type": "pressure",
"time": 400.0,
"param": "permx",
},
{
"taper": "gc",
"x": 5, "y": 15, "z": 0,
"radius": 4,
"z_range": ":",
"aniso": 1.0, "rotation": 0.0,
"data_type": "wopr pro1",
"time": 400.0,
"param": "permx",
},
]
}
Wildcard expansion in entries (apply one config to all data types):
FurrerBengtssonKernel
⚓︎
Furrer-Bengtsson ensemble-size-aware taper kernel.
build(radius, anisotropy_ratio, rotation_deg, field_shape, ensemble_size=None)
⚓︎
Taper weights around a datum: Furrer-Bengtsson decay over radius cells, adjusted for the ensemble size.
GaspariCohnKernel
⚓︎
Gaspari-Cohn compactly supported smooth taper kernel.
build(radius, anisotropy_ratio, rotation_deg, field_shape, ensemble_size=None)
⚓︎
Taper weights around a datum: smooth Gaspari-Cohn decay over radius cells, stretched by anisotropy_ratio.
LocalizationEntry
⚓︎
Configuration for a single (data_type, time, parameter) localization entry.