Newer
Older
from earthdiagnostics import cdftools
from earthdiagnostics.diagnostic import Diagnostic
from earthdiagnostics.utils import Utils, TempFile
"""
Compute the barotropic stream function
:original author: Virginie Guemas <virginie.guemas@bsc.es>
:contributor: Javier Vegas-Regidor<javier.vegas@bsc.es>
:created: March 2012
:last modified: June 2016
"""
def __init__(self, data_manager, startdate, member, chunk):
Diagnostic.__init__(self, data_manager)
self.startdate = startdate
self.member = member
self.chunk = chunk
self.required_vars = ['vo', 'uo']
self.generated_vars = ['vsftbarot']
def __str__(self):
return 'PSI Startdate: {0} Member: {1} Chunk: {2}'.format(self.startdate, self.member, self.chunk)
@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: None
:return:
"""
if len(options) > 1:
raise Exception('The PSI diagnostic has no options')
job_list = list()
for startdate in diags.startdates:
for member in diags.members:
for chunk in range(1, diags.chunks + 1):
job_list.append(Psi(diags.data_manager, startdate, member, chunk))
return job_list
def compute(self):
temp = TempFile.get()
input_file_u = self.data_manager.get_file('ocean', 'uo', self.startdate, self.member, self.chunk)
input_file_v = self.data_manager.get_file('ocean', 'vo', self.startdate, self.member, self.chunk)
cdftools.run('cdfpsi', input=[input_file_u, input_file_v], output=temp, options='-mean -mask')
Utils.rename_variable(temp, 'sobarstf', 'vsftbarot')
Utils.setminmax(temp, 'vsftbarot')
self.data_manager.send_file(temp, 'ocean', 'vsftbarot', self.startdate, self.member, self.chunk)