Source code for pycif.plugins.obsoperators.standard.check
from logging import info
[docs]
def check_inputs(inputs, mode):
"""Check the consistency of inputs given to the observation operator.
Validates that *mode* is one of the accepted values and that *inputs*
carries the attributes required by that mode.
Args:
inputs: control or observation vector passed to the operator; must
expose at least ``x`` for ``'fwd'`` mode, and both ``x`` and
``dx`` for ``'tl'`` mode.
mode (str): requested execution mode — one of ``'fwd'``, ``'tl'``,
or ``'adj'``.
Returns:
bool: ``True`` if all checks pass.
Raises:
Exception: if *mode* is not one of ``'fwd'``, ``'tl'``, or
``'adj'``.
Exception: if *mode* is ``'tl'`` and *inputs* does not expose both
``x`` and ``dx``.
"""
if mode not in ["tl", "fwd", "adj"]:
info(
"The following running mode is not accepted by the "
"observation operator: {}".format(mode)
)
raise Exception
if mode == "tl" and not (hasattr(inputs, "x") and hasattr(inputs, "dx")):
info(
"The observation operator was operated in tangent-linear mode "
"but not with both increments and control vector"
)
raise Exception
if mode == "fwd" and not hasattr(inputs, "x"):
info(
"The observation operator was operated in forward mode "
"with no control vector"
)
info("All inputs will be dealt as fixed")
return True