Newer
Older
Javier Vegas-Regidor
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
from autosubmit.config.log import Log
from diagnostic import Diagnostic
from earthdiagnostics import cdftools
from utils import Utils, TempFile
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
"""
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()
for startdate in diags.startdates:
for member in diags.members:
for chunk in range(1, diags.chunks + 1):
job_list.append(MixedLayerHeatContent(diags.data_manager, startdate, member, chunk))
return job_list
def compute(self):
nco = Utils.nco
cdo = Utils.cdo
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')
ntime = int(cdo.ntime(input=temperature_file)[0])
files = list()
for time in range(ntime):
Log.debug('Running time {0}', time)
temp = TempFile.get()
temp2 = TempFile.get()
nco.ncks(input=temperature_file, output=temp, options='-O -d time,{0}'.format(time))
cdftools.run('cdfmxlheatc', input=temp, output=temp2)
os.remove(temp)
files.append(temp2)
temp = TempFile.get()
cdo.cat(input=' '.join(files), output=temp,)
nco.ncks(input=temperature_file, output=temp, options='-A -v time')
for temp_file in files:
os.remove(temp_file)
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)