Newer
Older
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
import numpy as np
from autosubmit.config.log import Log
from basins import Basins
from earthdiagnostics import Diagnostic, TempFile, cdftools, Utils
class Moc(Diagnostic):
"""
Compute the MOC for oceanic basins
Created in March 2012
Author : vguemas@ic3.cat
# :param input_file: input grid_V file namez
# :type input_file: str
# :param output_file: output file name (=> 2D, depth-y)
# :param output_file: str
# :return:
"""
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 = ['vo']
self.generated_vars = ['vsftmyz']
@classmethod
def generate_jobs(cls, diags, 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(Moc(diags.data_manager, startdate, member, chunk))
return job_list
def compute(self):
temp = TempFile.get()
input_file = self.data_manager.get_file('ocean', 'vo', self.startdate, self.member, self.chunk)
Log.debug('Computing MOC')
cdftools.run('cdfmoc', input=input_file, output=temp)
Utils.nco.ncks(input=input_file, output=temp, options='-A -v lev')
Utils.convert2netcdf4(temp)
Log.debug('Reformatting variables')
handler = Utils.openCdf(temp)
handler.createDimension('basin', 5)
handler.createVariable('basin', str, 'basin')
handler.variables['basin'][:] = np.array([Basins.Global.fullname, Basins.Atlantic.fullname,
Basins.Pacific.fullname, Basins.IndoPacific.fullname,
Basins.Indian.fullname], dtype=object)
example = handler.variables['zomsfglo']
# noinspection PyProtectedMember
moc = handler.createVariable('vsftmyz', example.datatype,
('time', 'lev', 'i', 'j', 'basin'),
fill_value=example._FillValue)
moc.units = example.units
moc.add_offset = example.add_offset
moc.scale_factor = example.scale_factor
moc[:, :, :, :, 0] = handler.variables['zomsfglo'][:]
moc[:, :, :, :, 1] = handler.variables['zomsfatl'][:]
moc[:, :, :, :, 2] = handler.variables['zomsfpac'][:]
moc[:, :, :, :, 3] = handler.variables['zomsfinp'][:]
moc[:, :, :, :, 4] = handler.variables['zomsfind'][:]
handler.close()
Utils.nco.ncks(input=temp, output=temp,
options='-O -x -v zomsfglo,zomsfatl,zomsfpac,zomsfinp,zomsfind,zomsfinp0')
Utils.setminmax(temp, 'vsftmyz')
self.data_manager.send_file(temp, 'ocean', 'vsftmyz', self.startdate, self.member, self.chunk)