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) # Fetch information from reference trid # Valid for both ensemble and single simulations trid_ref = list(mapper["inputs"].keys())[0] sparse_in = mapper["inputs"][trid_ref]["sparse_data"] sparse_out = mapper["outputs"][trid_ref]["sparse_data"] sampled_in = mapper["inputs"][trid_ref]["sampled"] sampled_out = mapper["outputs"][trid_ref]["sampled"] # Deal differently sparse and array data # Array data is parallelized along trid externally, while sparse share indexing if sampled_out or sparse_out: sparse_forward(transf, mapper, inout_datastore, ddi, onlyinit, mode, **kwargs) else: # inout_datastore["outputs"][trid] = {ddi: {}} array_forward(transf, mapper, inout_datastore, ddi, mode, onlyinit, **kwargs)
# 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)