Source code for earthdiagnostics.ocean.mixedlayerheatcontent

# coding=utf-8
"""Compute mixed layer heat content"""
import os

from earthdiagnostics import cdftools
from earthdiagnostics.diagnostic import Diagnostic
from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.utils import Utils, TempFile


[docs]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 """ alias = 'mlotsthc' "Diagnostic alias for the configuration file" 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 __eq__(self, other): if self._different_type(other): return False return self.startdate == other.startdate and self.member == other.member and self.chunk == other.chunk def __str__(self): return 'Mixed layer heat content Startdate: {0} Member: {1} Chunk: {2}'.format(self.startdate, self.member, self.chunk)
[docs] @classmethod def generate_jobs(cls, diags, options): """ Create 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() for startdate, member, chunk in diags.config.experiment.get_chunk_list(): job_list.append(MixedLayerHeatContent(diags.data_manager, startdate, member, chunk)) return job_list
[docs] def request_data(self): """Request data required by the diagnostic""" self.thetao = self.request_chunk(ModelingRealms.ocean, 'thetao', self.startdate, self.member, self.chunk) self.mlotst = self.request_chunk(ModelingRealms.ocean, 'mlotst', self.startdate, self.member, self.chunk)
[docs] def declare_data_generated(self): """Declare data to be generated by the diagnostic""" self.ohcsum = self.declare_chunk(ModelingRealms.ocean, 'ohcvsumlotst', self.startdate, self.member, self.chunk)
[docs] def compute(self): """Run the diagnostic""" temperature_file = TempFile.get() Utils.copy_file(self.thetao.local_file, temperature_file) Utils.nco.ncks(input=self.mlotst.local_file, output=temperature_file, options=('-A -v mlotst',)) temp = TempFile.get() cdftools.run('cdfmxlheatc', input_file=temperature_file, output_file=temp) os.remove(temperature_file) Utils.rename_variables(temp, {'x': 'i', 'y': 'j', 'somxlheatc': 'ohcvsumlotst'}, False) Utils.setminmax(temp, 'ohcvsumlotst') self.ohcsum.set_local_file(temp)