Source code for earthdiagnostics.ocean.mixedlayersaltcontent

# coding=utf-8
"""Compute mixed layer salt 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 MixedLayerSaltContent(Diagnostic): """ Compute mixed layer salt 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 = 'mlotstsc' "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 __str__(self): return 'Mixed layer salt content Startdate: {0} Member: {1} Chunk: {2}'.format(self.startdate, self.member, self.chunk) 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
[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 salt content diagnostic has no options') job_list = list() for startdate, member, chunk in diags.config.experiment.get_chunk_list(): job_list.append(MixedLayerSaltContent(diags.data_manager, startdate, member, chunk)) return job_list
[docs] def request_data(self): """Request data required by the diagnostic""" self.so = self.request_chunk(ModelingRealms.ocean, 'so', 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.sosum = self.declare_chunk(ModelingRealms.ocean, 'scvsummlotst', self.startdate, self.member, self.chunk)
[docs] def compute(self): """Run the diagnostic""" salinity_file = TempFile.get() Utils.copy_file(self.so.local_file, salinity_file) Utils.nco.ncks(input=self.mlotst.local_file, output=salinity_file, options=('-A -v mlotst',)) temp = TempFile.get() cdftools.run('cdfmxlsaltc', input_file=salinity_file, output_file=temp) os.remove(salinity_file) Utils.rename_variables(temp, {'x': 'i', 'y': 'j', 'somxlsaltc': 'scvsummlotst'}, False) Utils.setminmax(temp, 'scvsummlotst') self.sosum.set_local_file(temp)