pycif.plugins.transforms.basic.regrid — API reference#
Configuration reference: regrid plugin
- pycif.plugins.transforms.basic.regrid.adjoint.adjoint(transf, inout_datastore, controlvect, obsvect, mapper, ddi, ddf, mode, runsubdir, workdir, onlyinit=False, save_debug=False, **kwargs)[source]#
Adjoint horizontal re-gridding: transpose the weight matrix.
Reloads the same interpolation weights as the forward pass and applies the transposed operation: each output cell’s
adj_outvalue is distributed back to the input cells weighted by the same coefficients used in the forward.- Parameters:
transf (Plugin) – regrid instance.
inout_datastore (dict) – mutable datastore.
controlvect – unused.
obsvect – unused.
mapper (dict) – transform mapper.
ddi (datetime) – sub-simulation start date.
ddf (datetime) – sub-simulation end date.
mode (str) –
'adj'.runsubdir (str) – unused.
workdir (str) – unused.
onlyinit (bool) – if
Trueand non-sparse, return immediately.save_debug (bool) – passed to
do_regridding_adj().**kwargs – unused.
- pycif.plugins.transforms.basic.regrid.adjoint.do_regridding_adj(data, nlat_in, nlon_in, nlat_out, nlon_out, weights, min_weight=1e-10, is_sparse_in=False, is_sparse_out=False, save_debug=False, transf=None)[source]#
Apply the transposed regridding weights to adjoint sensitivity data.
For gridded data, scatters output sensitivities back to input cells via
np.add.at. For sparse output, distributes the observation sensitivity to each contributing input cell weighted by the regridding coefficients.- Parameters:
data – the output-domain sensitivity (xarray DataArray for gridded, DataFrame for sparse).
nlat_in (int) – input domain dimensions.
nlon_in (int) – input domain dimensions.
nlat_out (int) – output domain dimensions.
nlon_out (int) – output domain dimensions.
weights (dict) – regridding weight dict with keys
'i','j','wgt', and optionally'filtered'.min_weight (float) – minimum weight threshold; lower weights are zeroed.
is_sparse_in (bool) –
Trueif the input is observation-indexed.is_sparse_out (bool) –
Trueif the output is observation-indexed.save_debug (bool) – unused (kept for API consistency).
transf (Plugin) – unused (kept for API consistency).
- Returns:
adjoint sensitivity on the input domain.
- Return type:
xarray.DataArray or pd.DataFrame
- Raises:
Exception – if
is_sparse_in = Trueandis_sparse_out = False(not yet implemented).
- pycif.plugins.transforms.basic.regrid.forward.forward(transf, inout_datastore, controlvect, obsvect, mapper, ddi, ddf, mode, runsubdir, workdir, onlyinit=False, save_debug=False, **kwargs)[source]#
Reprojects data from the input domain to the output domain.
Computes or reloads interpolation weights (from the
dir_wgtdirectory when available) and applies them to the'spec'(and'incr'in TL mode) arrays. Handles four data configurations:Array → Array (gridded field to gridded field)
Sparse → Array (obs-indexed data scattered onto a grid)
Array → Sparse (gridded field sampled at obs locations)
Sparse → Sparse (obs-indexed to obs-indexed)
- Parameters:
transf (Plugin) – regrid instance (carries
method,min_weight,dir_wgt,dir_regrid).inout_datastore (dict) – mutable datastore.
controlvect – unused.
obsvect – unused.
mapper (dict) – transform mapper (carries domain objects and
sparse_data/sampledflags).ddi (datetime) – sub-simulation start date.
ddf (datetime) – sub-simulation end date.
mode (str) –
'fwd'or'tl'.runsubdir (str) – unused.
workdir (str) – unused.
onlyinit (bool) – if
Trueand input is sparse, return immediately.save_debug (bool) – if
True, save intermediate results for debugging.**kwargs – unused.