Source code for pycif.utils.classes.obsvects
from types import MethodType
import pandas as pd
from ...utils.check.errclass import PluginError
from .baseclass import Plugin
[docs]
class ObsVect(Plugin):
"""Plugin type for observation vectors.
Manages the observation datastore and provides the R-matrix
inverse-product operation (``rinvprod``) along with serialisation
(``dump`` / ``read``) and initialisation (``init_y0``, ``init_invprod``)
interfaces.
Concrete implementations live in ``pycif/plugins/obsvects/``.
"""
def __init__(self, **kwargs):
"""Initialise an ObsVect plugin with an empty datastore."""
super(ObsVect, self).__init__(**kwargs)
# Attribute an empty datastore
self.datastore = {}
[docs]
def initiate_template(self):
"""Initialise the ObsVect plugin template.
Loads the registered obs-vector module and attaches ``init_y0``,
``init_invprod``, ``rinvprod``, ``dump`` and ``read`` as bound methods
on this instance.
"""
super(ObsVect, self).initiate_template(
plg_type="obsvect",
default_functions={
"init_y0": True, "init_invprod": True, "rinvprod": True,
"dump": True, "read": True}
)
[docs]
def init_y0(self, *args, **kwargs):
"""Default empty init_y0 method"""
raise PluginError("This is the default empty init_y0 method")
[docs]
def init_invprod(self, *args, **kwargs):
"""Default empty init_invprod method"""
raise PluginError("This is the default empty init_invprod method")
[docs]
def rinvprod(self, *args, **kwargs):
"""Default empty rinvprod method"""
raise PluginError("This is the default empty rinvprod method")
[docs]
def dump(self, *args, **kwargs):
"""Default empty dump method"""
raise PluginError("This is the default empty dump method")
[docs]
def read(self, *args, **kwargs):
"""Default empty read method"""
raise PluginError("This is the default empty read method")
[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(ObsVect, cls).register_plugin(
name, version, module, plugin_type="obsvect", subtype=subtype
)