Source code for pycif.plugins.obsvects.standard.utils.check_monitor
from logging import info
[docs]
def check_monitor(self, tracer):
"""Check whether a pre-existing monitor file is compatible with the current run.
Compares the domain dimensions and simulation dates stored in the
monitor's ``nc_attributes`` (or ``.attrs``) against the current model
configuration. This allows :func:`~.init_param` to decide whether to
re-use the monitor as-is or to reload and re-crop the raw observations.
Args:
self (Plugin): obsvect plugin instance (provides ``model.domain``,
``datei``, and ``datef``).
tracer (Plugin): datavect tracer plugin instance whose ``datastore``
contains the pre-existing monitor data.
Returns:
tuple[bool, bool, bool, bool]: a four-element tuple
``(allcorrect, ok_hcoord, ok_vcoord, do_tstep)`` where:
* ``allcorrect`` — all checks passed; the monitor can be used as-is.
* ``ok_hcoord`` — horizontal domain (``nlat``, ``nlon``) matches.
* ``ok_vcoord`` — vertical coordinate is consistent (always ``True``
in the current implementation — reserved for future use).
* ``do_tstep`` — temporal re-cropping is required (``True`` when
dates do not match).
When the monitor has no ``nc_attributes`` (old format), returns
``(False, False, False, True)`` to trigger a full reload.
"""
datastore = tracer.datastore
# For old monitor with no nc_attributes, do nothing
if "nc_attributes" not in datastore:
info(
"Cannot check the datastore from a previous version. "
"Please be careful with the use of it"
)
return False, False, False, True
# check what part of the monitor is to be re-computed
try:
nc_attributes = datastore.attrs
except AttributeError:
nc_attributes = datastore["nc_attributes"]
ok_hcoord = (
nc_attributes.get("domain nlat", None) == str(self.model.domain.nlat)
) and (
nc_attributes.get("domain nlon", None) == str(self.model.domain.nlon)
)
ok_vcoord = True
ok_tstep = (
nc_attributes.get("datei", None)
== self.datei.strftime("%d-%m-%Y %H:%M:%S")
) and (
nc_attributes.get("datef", None)
== self.datef.strftime("%d-%m-%Y %H:%M:%S")
)
allcorrec = ok_hcoord and ok_tstep and ok_vcoord
return allcorrec, ok_hcoord, ok_vcoord, not ok_tstep