Source code for earthdiagnostics.ocean.psi

# coding=utf-8
"""Compute the barotropic stream function"""
from earthdiagnostics import cdftools
from earthdiagnostics.diagnostic import Diagnostic
from earthdiagnostics.modelingrealm import ModelingRealms
from earthdiagnostics.utils import Utils, TempFile


[docs]class Psi(Diagnostic): """ 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 :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 = 'psi' "Diagnostic alias for the configuration file" vsftbarot = 'vsftbarot' def __init__(self, data_manager, startdate, member, chunk): Diagnostic.__init__(self, data_manager) self.startdate = startdate self.member = member self.chunk = 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 def __str__(self): return 'PSI 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 PSI diagnostic has no options') job_list = list() for startdate, member, chunk in diags.config.experiment.get_chunk_list(): job_list.append(Psi(diags.data_manager, startdate, member, chunk)) return job_list
[docs] def request_data(self): """Request data required by the diagnostic""" self.uo = self.request_chunk(ModelingRealms.ocean, 'uo', self.startdate, self.member, self.chunk) self.vo = self.request_chunk(ModelingRealms.ocean, 'vo', self.startdate, self.member, self.chunk)
[docs] def declare_data_generated(self): """Declare data to be generated by the diagnostic""" self.psi = self.declare_chunk(ModelingRealms.ocean, Psi.vsftbarot, self.startdate, self.member, self.chunk)
[docs] def compute(self): """Run the diagnostic""" temp = TempFile.get() cdftools.run('cdfpsi', input_file=[self.uo.local_file, self.vo.local_file], output_file=temp, options='-mean -mask') Utils.rename_variable(temp, 'sobarstf', Psi.vsftbarot) Utils.setminmax(temp, Psi.vsftbarot) self.psi.set_local_file(temp)