Source code for pycif.utils.classes.measurements
from types import MethodType
from ...utils.check.errclass import PluginError
from ...utils.datastores.empty import init_empty
from .baseclass import Plugin
[docs]
class Measurement(Plugin):
"""Plugin type for observation measurement parsers.
Reads and parses observation data into a pyCIF datastore for a given
simulation period, iterating over tracers as needed.
Concrete implementations live in ``pycif/plugins/measurements/``.
"""
[docs]
def initiate_template(self):
"""Initialise the Measurement plugin template.
Loads the registered measurement module and attaches
``parse_tracers`` as a bound method on this instance.
"""
super(Measurement, self).initiate_template(
plg_type="measurements",
default_functions={"parse_tracers": True}
)
[docs]
@classmethod
def register_plugin(cls, name, version, module, subtype="", **kwargs):
"""Register a module for a plugin and version with possibly options
Args:
name (str): name of the plugin
version (str): version of the plugin
module (types.ModuleType): module defining the interface
between pyCIF and the plugin
plugin_type (str): type of plugin
**kwargs (dictionary): default options for module
"""
super(Measurement, cls).register_plugin(
name, version, module, plugin_type="measurements", subtype=subtype
)
[docs]
def ini_data(self, **kwargs):
"""Load measurement data for the simulation period.
Calls :meth:`parse_tracers` to read all tracers for the period
``[self.datei, self.datef]`` and stores the result in
``self.datastore``.
Args:
**kwargs: Forwarded to :meth:`parse_tracers`.
"""
datei = self.datei
datef = self.datef
# If the measurement definition is empty in the Yaml,
# return an empty datastore
self.datastore = self.parse_tracers(datei, datef, **kwargs)
[docs]
def parse_tracers(self, *args, **kwargs):
"""Parse observation tracers for a given time window.
Must be overridden by each concrete measurement plugin. Should return a
pyCIF datastore (``pd.DataFrame``) containing all observations for the
requested period.
Raises:
PluginError: Always, in this default implementation.
"""
raise PluginError("The function parse_tracers was not defined")