-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapters.py
55 lines (42 loc) · 1.38 KB
/
adapters.py
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
import os
def get_adapter(project):
p = project.lower()
if p == 'cmip6':
return Cmip6Adapter()
elif p == 'cmip5':
return Cmip5Adapter()
else:
return None
class Cmip6Adapter(object):
fx = ['areacella', 'areacellr', 'orog', 'sftlf', 'sftgif', 'mrsofc', 'rootd', 'zfull']
drs = 'project/product/institution/model/experiment/ensemble/frequency/variable/grid/version'
def __init__(self, template='cmip.ncml.j2'):
self.template = template
self.facets = Cmip6Adapter.drs.split('/')
def drs_to_var(self, drs):
facets = os.path.dirname(drs).split('/')
return facets[7]
def drs_to_version(self, drs):
facets = os.path.dirname(drs).split('/')
return facets[9][1:]
def drs_to_ncml(self, drs):
facets = os.path.dirname(drs).split('/')
ncml = '_'.join(facets[:7] + facets[8:-1])
return ncml
def ncml_facets(self):
return self.facets[:7] + self.facets[8:]
def get_fx_dict(self, d):
d.pop('frequency')
return d
class Cmip5Adapter(object):
fx = ['areacella', 'areacellr', 'orog', 'sftlf', 'sftgif', 'mrsofc', 'rootd', 'zfull']
drs = 'project/product/institution/model/experiment/frequency/realm/table/ensemble/version/variable'
def __init__(self, template='cmip.ncml.j2'):
self.template = template
self.facets = Cmip5Adapter.drs.split('/')
def ncml_facets(self):
return self.facets[:-1]
def get_fx_dict(self, d):
d.pop('frequency')
d.pop('ensemble')
return d