Newer
Older
from earthdiagnostics.diagnostic import *
from earthdiagnostics.modelingrealm import ModelingRealm
class AverageSection(Diagnostic):
"""
Compute an average of a given zone. The variable MUST be in a regular grid
:original author: Virginie Guemas <virginie.guemas@bsc.es>
:contributor: Javier Vegas-Regidor<javier.vegas@bsc.es>
:created: March 2012
:last modified: June 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
:param box: box to use for the average
:type box: Box
alias = 'avgsection'
"Diagnostic alias for the configuration file"
def __init__(self, data_manager, startdate, member, chunk, domain, variable, box, grid):
Diagnostic.__init__(self, data_manager)
self.startdate = startdate
self.member = member
self.chunk = chunk
self.variable = variable
self.domain = domain
self.box = box
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.box == other.box
return 'Average section Startdate: {0.startdate} Member: {0.member} Chunk: {0.chunk} Box: {0.box} ' \
'Variable: {0.domain}:{0.variable} Grid: {0.grid}'.format(self)
@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
:param options: variable, minimum longitude, maximum longitude, minimum latitude, maximum latitude, domain=ocean
DiagnosticVariableOption(diags.data_manager.config.var_manager),
Javier Vegas-Regidor
committed
DiagnosticIntOption('min_lon'),
DiagnosticIntOption('max_lon'),
DiagnosticIntOption('min_lat'),
DiagnosticIntOption('max_lat'),
Javier Vegas-Regidor
committed
options = cls.process_options(options, options_available)
Javier Vegas-Regidor
committed
box.min_lon = options['min_lon']
box.max_lon = options['max_lon']
box.min_lat = options['min_lat']
box.max_lat = options['max_lat']
for startdate, member, chunk in diags.config.experiment.get_chunk_list():
Javier Vegas-Regidor
committed
job_list.append(AverageSection(diags.data_manager, startdate, member, chunk,
options['domain'], options['variable'], box, options['grid']))
def request_data(self):
self.variable_file = self.request_chunk(self.domain, self.variable, self.startdate, self.member, self.chunk,
grid=self.grid)
def declare_data_generated(self):
self.mean = self.declare_chunk(self.domain, self.variable + 'mean', self.startdate, self.member, self.chunk,
box=self.box, grid=self.grid)
variable_file = self.variable_file.local_file
Utils.cdo.zonmean(input='-sellonlatbox,{0},{1},{2},{3} {4}'.format(self.box.min_lon, self.box.max_lon,
self.box.min_lat, self.box.max_lat,
variable_file),
output=temp)
os.remove(variable_file)