Source code for pycif.plugins.transforms.basic.vertical_interpolation.forward

import copy
from logging import warning
import numpy as np
import pandas as pd
import xarray as xr
from .....utils.classes.domains import Domain
try:
    import cPickle as pickle
except ImportError:
    import pickle

from .utils.array.forward import array_forward
from .utils.sparse.forward import sparse_forward


[docs] def forward( transf, inout_datastore, controlvect, obsvect, mapper, di, df, mode, runsubdir, workdir, onlyinit=False, save_debug=False, **kwargs ): """Vertically interpolate model fields to observation pressure/height levels. Dispatches to either the sparse/sampled or gridded (array) implementation: * **Sparse/sampled output** — :func:`~.utils.sparse.forward.sparse_forward`: extracts model values at the observation vertical coordinate. * **Array output** — :func:`~.utils.array.forward.array_forward`: applies the configured interpolation method (``static-levels``, ``linear``, ``closest``, ``match-layer``, or ``layer-weighted``) to the full gridded field. Args: transf (Plugin): vertical_interpolation instance (carries ``method``, ``coord_in``, ``coord_out``, ``ignore_level``, and optional ``file_statlev``). inout_datastore (dict): mutable datastore. controlvect: unused. obsvect: unused. mapper (dict): transform mapper (carries ``sparse_data``, ``sampled``, and domain objects). di (datetime): sub-simulation start date. df (datetime): sub-simulation end date. mode (str): ``'fwd'`` or ``'tl'``. runsubdir (str): unused. workdir (str): unused. onlyinit (bool): passed to the sparse/array implementations. save_debug (bool): if ``True``, save intermediate results. **kwargs: forwarded to the sparse/array implementations. """ ddi = min(di, df) for trid in mapper["outputs"]: is_sparse_out = mapper["outputs"][trid].get("sparse_data", False) is_sampled_out = mapper["outputs"][trid]["sampled"] # is_sparse_in = mapper["inputs"][trid].get("sparse_data", False) # is_sampled_in = mapper["inputs"][trid]["sampled"] # WARNING: for sparse data as targets, do nothing at the moment if is_sparse_out or is_sampled_out: sparse_forward(transf, mapper, inout_datastore, trid, ddi, onlyinit, mode, **kwargs) continue # Deal with full data inout_datastore["outputs"][trid] = {ddi: {}} array_forward(transf, mapper, inout_datastore, trid, ddi, mode, onlyinit, **kwargs)