def create_domain(self, *args, **kwargs): """Creates a grid if needed Args: domain (dictionary): dictionary defining the domain. """ raise PluginError("The function create_domain was not defined")
def create_chemicalscheme(self, *args, **kwargs): """Creates a chemical scheme if needed Args: chemistry (dictionary): dictionary defining the chelical scheme """ raise PluginError("The function create_chemicalscheme was not defined")
def read_grid(self, *args, **kwargs): """Read a grid from an existing file Args: self (Domain): plugin defining the domain. Should include filegrid to be able to read the grid from a file Return: Grid domain with meshgrids for center lon/lat and corner lon/lat """ raise PluginError("The function read_grid was not defined")
def read_chemicalscheme(self, *args, **kwargs): """Read a chemical scheme from an existing file Args: self (Chemistry): plugin defining the chemistry. Should include dirscheme grid to be able to read the chemistry from files Return: Characteristics of the chemical scheme """ raise PluginError("The function read_scheme was not defined")
def get_loaded(cls, name, version, plugin_type): """Get the correct loaded plugin, given its name, version and type Args: name (str): name of the plugin version (str): version of the plugin plugin_type (str): type of plugin Returns: Plugin: plugin module for plugin version """ if not cls.is_loaded(name, version, plugin_type): raise PluginError( "No {} module loaded for plugin {} and Version {}".format( plugin_type, name, version)) return cls.loaded_instances[cls.plugin_key(name, version, plugin_type)]
def get_registered(cls, name, version, plugin_type): """Get the correct registered plugin, given its name, version and type Args: name (str): name of the plugin version (str): version of the plugin plugin_type (str): type of plugin Returns: Plugin: plugin module for plugin version """ if not cls.is_registered(name, version, plugin_type): raise PluginError( "No {} module found for plugin {} and Version {}".format( plugin_type, name, version)) module = importlib.import_module(cls.registered[cls.plugin_key( name, version, plugin_type)]) return module
def _fetch_requirement(cls, plg, key, name, version, plg_type, fromsub, empty, preftree): pref_plg = [ s for s in cls.subreference_instances.get(key, []) if preftree in s ] # If in children if key in cls._get_attribute_list(plg): plg_tmp = getattr(plg, key) # If not in children but at level 0 of Yaml elif key in cls.reference_instances: plg_tmp = cls.reference_instances[key] # If not at level 0, but no ambiguity elif len(cls.subreference_instances.get(key, [])) == 1 and fromsub: plg_tmp = list(cls.subreference_instances[key].values())[0] # If not at level 0, but ambiguity elif (len(cls.subreference_instances.get(key, [])) >= 1 and fromsub and len(pref_plg) == 1): plg_tmp = cls.subreference_instances[key][pref_plg[0]] elif empty: if cls.is_registered(name, version, plg_type): plg_tmp = cls.load_registered(name, version, plg_type) else: plg_tmp = cls.get_subclass(plg_type)() # Error in the yaml if reaching this point else: plg_tmp = None raise PluginError( "{} needs a plugin '{}/{}/{}' and an " "inconsistent one was proposed in the Yaml".format( plg, key, name, version)) return plg_tmp
def childclass_factory(cls, plg_orig, child_type=None, overwrite=False): """Generates an instance of one of Plugin's child classes. Transfers all existing attributes in the argument plugin to the output child-class instance Args: plg_orig (Plugin): the plugin to turn into a child-class instance child_type (str): sub-class type to generate if not available in plg_orig.plugin.type overwrite (bool): overwrite the class type of the origin plugin Return: child_plg: a plugin with all the attributes from plg_orig, but as a child-class instance """ if getattr(plg_orig.plugin, "type", None) is None: if child_type is None: raise PluginError( "The Child-class factory was called on a plugin " "that was not correctly initialized: {} / {}".format( plg_orig, plg_orig.orig_name)) else: plg_type = child_type plg_orig._load_plugin_type(plg_type) else: plg_type = plg_orig.plugin.type # If the type is not referenced, don't do anything if not cls.is_allowed(plg_type): return plg_orig # Load the subclass child_plg = cls.get_subclass(plg_type)(plg_orig=plg_orig) return child_plg
def ini_periods(self, *args, **kwargs): """Default empty ini_periods method""" raise PluginError("This is the default empty ini_periods method")
def flushrun(self, *args, **kwargs): """Default empty flushrun method""" raise PluginError("This is the default empty flushrun method")
def make_input(self, *args, **kwargs): """Default empty make_input method""" raise PluginError("This is the default empty make_input method")
def outputs2native(self, *args, **kwargs): """Default empty outputs2native method""" raise PluginError("This is the default empty outputs2native method")
def control2native(self, *args, **kwargs): """Default empty control2native method""" raise PluginError("This is the default empty control2native method")
def native2control(self, *args, **kwargs): """Default empty native2control method""" raise PluginError("This is the default empty native2control method")
def load(self, *args, **kwargs): """Default empty load method""" raise PluginError("This is the default empty load method")
def dump(self, *args, **kwargs): """Default empty dump method""" raise PluginError("This is the default empty dump method")
def sqrtbprod_ad(self, *args, **kwargs): """Default empty sqrtbprod_ad method""" raise PluginError("This is the default empty sqrtbprod_ad method")
def _check_requirements(cls, plg, parent_plg_type=None, level=None, **kwargs): """Checking that required modules and plugins are loaded. If not, load them. Requirements are defined in the __init__.py file of the corresponding plugin module. Args: plg (Plugin): a plugin to initialize Notes: Some basic parameters are added as requirements to all plugins; These are: 'datei', 'datef', 'workdir', 'logfile', 'verbose' """ # Dealing with default requirements supposed to be given at level 0 for key in plg.default_requirements: if key not in cls._get_attribute_list(plg): if key in cls.reference_instances: setattr(plg, key, cls.reference_instances[key]) else: raise PluginError( "The default key '{}' is not prescribed" "neither in the plugin {}, nor in the " "level 0 of the configuration file".format(key, plg)) # Looping over requirements and including them for key in plg.requirements: key_req = plg.requirements[key] fromany = key_req.get("any", False) fromsub = key_req.get("subplug", False) preftree = key_req.get("preftree", "") empty = key_req.get("empty", False) name = key_req.get("name", None) version = key_req.get("version", "") plg_type = key_req.get("type", key) newplg = key_req.get("newplg", False) # If not from any plugin, but no default value specified, error if not fromany and name is None: raise PluginError( "{} needs a specific {}, but none was specified \n" "Please check requirements in your module".format( plg, key)) # If needs a Plugin explicitly defined, # look for it at level 0 of setup, or in children, # or in unambiguous level N plugins plg_tmp = cls._fetch_requirement(plg, key, name, version, plg_type, fromsub, empty, preftree) # If has a prescribed name tmp_plugin = getattr(plg_tmp, "plugin", None) tmp_name = getattr(tmp_plugin, "name", None) tmp_version = getattr(tmp_plugin, "version", None) if (getattr(getattr(plg_tmp, "plugin", None), "name", None) is not None and fromany) or ( tmp_name is not None and name == tmp_name and version == tmp_version and type(plg_tmp) == cls.get_subclass(plg_type) and not fromany): plg_out = plg_tmp # If a default is defined, load from registered elif (name is not None and fromany) or (tmp_name is None and not fromany): plg_out = cls.load_registered(name, version, plg_type, plg_orig=plg_tmp) # Otherwise, if accepts empty classes elif empty: plg_out = plg_tmp # Error in the yaml if reaching this point else: raise PluginError( "{} needs a plugin '{}/{}/{}' and an " "inconsistent one was proposed in the Yaml".format( plg, key, name, version)) if plg_out is None: raise Exception( "{} needs a Plugin '{}' to run properly\n" "there is none in its children nor at the level 0 of " "Yaml\n" "Please check your Yaml".format(plg, key)) # Keep in memory to initialize a new instance of the plugin or not plg.plugin.newplg = newplg # Adding auxiliary attributes if any aux_ids = [ "name", "version", "type", "any", "subplug", "preftree", "empty", "newplg" ] for attr in key_req: if attr not in aux_ids: setattr(plg_out, attr, key_req[attr]) # Attaching the requirement to the parent plugin setattr(plg, key, plg_out) # Load the requirements if not already done cls.load_setup(plg, parent_plg_type, level, **kwargs)
def simul(self, *args, **kwargs): """Default empty simul method""" raise PluginError("This is the default empty simul method")
def minimize(self, *args, **kwargs): """Default empty minimize function """ raise PluginError("The function minimize was not defined")
def parse_tracers(self, *args, **kwargs): """Default empty minimize function """ raise PluginError("The function parse_tracers was not defined")
def native2inputs(self, *args, **kwargs): """Default empty native2inputs method""" raise PluginError("This is the default empty native2inputs method")
def execute(self, *args, **kwargs): """Default empty execute method""" raise PluginError("This is the default empty execute method")