Newer
Older
Javier Vegas-Regidor
committed
import os
from earthdiagnostics.diagnostic import Diagnostic
Javier Vegas-Regidor
committed
from earthdiagnostics import cdftools
from earthdiagnostics.utils import Utils, TempFile
Javier Vegas-Regidor
committed
class MixedLayerHeatContent(Diagnostic):
"""
Compute mixed layer heat content
:original author: Virginie Guemas <virginie.guemas@bsc.es>
:contributor: Javier Vegas-Regidor<javier.vegas@bsc.es>
:created: February 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
Javier Vegas-Regidor
committed
"""
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 = ['so', 'mlotst']
self.generated_vars = ['scvertsum']
def __str__(self):
return 'Mixed layer heat content 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
:type options: list[str]
:return:
"""
if len(options) > 1:
raise Exception('The mixed layer ocean heat content diagnostic has no options')
job_list = list()
Javier Vegas-Regidor
committed
for startdate, member, chunk in diags.exp_manager.get_chunk_list():
job_list.append(MixedLayerHeatContent(diags.data_manager, startdate, member, chunk))
Javier Vegas-Regidor
committed
return job_list
def compute(self):
Javier Vegas-Regidor
committed
temperature_file = self.data_manager.get_file('ocean', 'thetao', self.startdate, self.member, self.chunk)
mlotst_file = self.data_manager.get_file('ocean', 'mlotst', self.startdate, self.member, self.chunk)
Utils.nco.ncks(input=mlotst_file, output=temperature_file, options='-A -v mlotst')
temp = TempFile.get()
Javier Vegas-Regidor
committed
cdftools.run('cdfmxlheatc', input=temperature_file, output=temp)
Javier Vegas-Regidor
committed
os.remove(temperature_file)
Utils.rename_variables(temp, {'x': 'i', 'y': 'j', 'somxlheatc': 'ohcvsumlotst'}, False, True)
Utils.setminmax(temp, 'ohcvsumlotst')
self.data_manager.send_file(temp, 'ocean', 'ohcvsumlotst', self.startdate, self.member, self.chunk)