Newer
Older
from earthdiagnostics.diagnostic import Diagnostic, DiagnosticOption, DiagnosticDomainOption, DiagnosticBoolOption, \
DiagnosticVariableOption
from earthdiagnostics.modelingrealm import ModelingRealm
from earthdiagnostics.variable import VariableManager
class Relink(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
:param member: member number
:type member: int
:param chunk: chunk's number
:type chunk: int
:param variable: variable's name
:type variable: str
:param domain: variable's domain
Javier Vegas-Regidor
committed
:param move_old: if true, looks for files following the old convention and moves to avoid collisions
:type move_old: bool
"""
alias = 'relink'
"Diagnostic alias for the configuration file"
def __init__(self, data_manager, startdate, member, chunk, domain, variable, move_old, grid):
Diagnostic.__init__(self, data_manager)
self.startdate = startdate
self.member = member
self.chunk = chunk
self.variable = variable
self.domain = domain
Javier Vegas-Regidor
committed
self.move_old = move_old
Javier Vegas-Regidor
committed
return 'Relink output Startdate: {0} Member: {1} Chunk: {2} Move old: {5} ' \
'Variable: {3}:{4} Grid: {6}'.format(self.startdate, self.member, self.chunk, self.domain, self.variable,
self.move_old, self.grid)
def __eq__(self, other):
return self.startdate == other.startdate and self.member == other.member and self.chunk == other.chunk and \
self.domain == other.domain and self.variable == other.variable and self.move_old == other.move_old and \
self.grid == other.grid
@classmethod
def generate_jobs(cls, diags, options):
"""
Creates a job for each chunk to compute the diagnostic
:param diags: Diagnostics manager class
:type diags: Diags
Javier Vegas-Regidor
committed
:param options: variable, domain, move_old=False
:type options: list[str]
:return:
"""
options_available = (DiagnosticVariableOption('variable'),
DiagnosticDomainOption('domain'),
DiagnosticBoolOption('move_old', True),
DiagnosticOption('grid', ''))
Javier Vegas-Regidor
committed
options = cls.process_options(options, options_available)
job_list = list()
for startdate, member, chunk in diags.config.experiment.get_chunk_list():
job_list.append(Relink(diags.data_manager, startdate, member, chunk,
options['domain'], options['variable'], options['move_old'], options['grid']))
def request_data(self):
pass
def declare_data_generated(self):
pass
def compute(self):
"""
Runs the diagnostic
"""
self.data_manager.link_file(self.domain, self.variable, VariableManager().get_variable(self.variable),
self.startdate, self.member, self.chunk,
move_old=self.move_old, grid=self.grid)