relinkall.py 1.76 KB
Newer Older
# coding=utf-8
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
"""Create links for all variables in a startdate"""
from earthdiagnostics.diagnostic import Diagnostic


class RelinkAll(Diagnostic):
    """
    Recreates the links for the variable specified

    :original author: Javier Vegas-Regidor<javier.vegas@bsc.es>

    :created: September 2016

    :param data_manager: data management object
    :type data_manager: DataManager
    :param startdate: startdate
    :type startdate: str
    """

    alias = 'relinkall'
    "Diagnostic alias for the configuration file"

    def __init__(self, data_manager, startdate):
        Diagnostic.__init__(self, data_manager)
        self.startdate = startdate

    def __str__(self):
        return 'Relink all output Startdate: {0}'.format(self.startdate)

    def __eq__(self, other):
        return self.startdate == other.startdate

    @classmethod
    def generate_jobs(cls, diags, options):
        """
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
            Create a job for each chunk to compute the diagnostic

            :param diags: Diagnostics manager class
            :type diags: Diags
            :param options: variable, domain, move_old=False
            :type options: list[str]
            :return:
            """
        if len(options) > 1:
            raise Exception('The Relink All diagnostic has no options')
        job_list = list()
        for startdate in diags.config.experiment.startdates:
            job_list.append(RelinkAll(diags.data_manager, startdate))
        return job_list

Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
    def request_data(self):
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
        """Request data required by the diagnostic"""
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
        pass

    def declare_data_generated(self):
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
        """Declare data to be generated by the diagnostic"""
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
        pass

    def compute(self):
Javier Vegas-Regidor's avatar
Javier Vegas-Regidor committed
        """Run the diagnostic"""
        self.data_manager.create_links(self.startdate)