source: CMIP6dreqbuild/trunk/src/framework/ing02/addcf3hrgrid2.py @ 1080

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreqbuild/trunk/src/framework/ing02/addcf3hrgrid2.py@1206
Revision 1080, 7.0 KB checked in by mjuckes, 2 years ago (diff)

add missing file

Line 
1import shelve, collections
2
3tmidtm = 'cf34c974-80be-11e6-97ee-ac72891c3257'
4tmidpt = '7a976ce0-8042-11e6-97ee-ac72891c3257'
5
6ttt = {tmidtm:'mn',tmidpt:'pt'}
7
8## exist as required, need to link CMORvars (with table 3hr) to group (i.e. 3 new requestvar records)
9lgrp = ['huss', 'tas', 'uas', 'vas']
10ulgrp = ['9250aee2-4b7f-11e7-903f-5404a60d96b5', '9250e4e8-4b7f-11e7-903f-5404a60d96b5', '925119d6-4b7f-11e7-903f-5404a60d96b5', '92514e42-4b7f-11e7-903f-5404a60d96b5']
11## exist, but table needs to be changed (and 4 new request var records)
12lmv = ['psl', 'rsuscs', 'ts']
13ulmv = ['bc5e692c-4b7f-11e7-903f-5404a60d96b5', 'bc5e6e9a-4b7f-11e7-903f-5404a60d96b5', 'bc5e7020-4b7f-11e7-903f-5404a60d96b5']
14## new variables and request variables needed: change prov, structure, mipTable
15cl1 = ['clivi', 'clt', 'clwvi', 'hfls', 'hfss', 'pr', 'prc', 'prsn', 'prw', 'rlds', 'rldscs', 'rlus', 'rlut', 'rlutcs', 'rsds', 'rsdscs', 'rsdt', 'rsus', 'rsut', 'rsutcs', 'sfcWind']
16ucl1 = ['e0ab34f4-4b7f-11e7-903f-5404a60d96b5', 'e0ab3896-4b7f-11e7-903f-5404a60d96b5', 'e0ab3abc-4b7f-11e7-903f-5404a60d96b5', 'e0ab3cc4-4b7f-11e7-903f-5404a60d96b5', 'e0ab3ee0-4b7f-11e7-903f-5404a60d96b5', 'e0ab40e8-4b7f-11e7-903f-5404a60d96b5', 'e0ab42e6-4b7f-11e7-903f-5404a60d96b5', 'e0ab4502-4b7f-11e7-903f-5404a60d96b5', 'e0ab4700-4b7f-11e7-903f-5404a60d96b5', 'e0ab4872-4b7f-11e7-903f-5404a60d96b5', 'e0ab49a8-4b7f-11e7-903f-5404a60d96b5', 'e0ab4ae8-4b7f-11e7-903f-5404a60d96b5', 'e0ab4c14-4b7f-11e7-903f-5404a60d96b5', 'e0ab4d54-4b7f-11e7-903f-5404a60d96b5', 'e0ab4e80-4b7f-11e7-903f-5404a60d96b5', 'e0ab4fc0-4b7f-11e7-903f-5404a60d96b5', 'e0ab50f6-4b7f-11e7-903f-5404a60d96b5', 'e0ab5254-4b7f-11e7-903f-5404a60d96b5', 'e0ab5380-4b7f-11e7-903f-5404a60d96b5', 'e0ab54ac-4b7f-11e7-903f-5404a60d96b5', 'e0ab55d8-4b7f-11e7-903f-5404a60d96b5', 'e0ab5718-4b7f-11e7-903f-5404a60d96b5', 'e0ab5858-4b7f-11e7-903f-5404a60d96b5', 'e0ab598e-4b7f-11e7-903f-5404a60d96b5', 'e0ab5ace-4b7f-11e7-903f-5404a60d96b5', 'e0ab5bfa-4b7f-11e7-903f-5404a60d96b5', 'e0ab5d3a-4b7f-11e7-903f-5404a60d96b5', 'e0ab5e66-4b7f-11e7-903f-5404a60d96b5', 'e0ab5f92-4b7f-11e7-903f-5404a60d96b5', 'e0ab60be-4b7f-11e7-903f-5404a60d96b5', 'e0ab6212-4b7f-11e7-903f-5404a60d96b5', 'e0ab6352-4b7f-11e7-903f-5404a60d96b5', 'e0ab647e-4b7f-11e7-903f-5404a60d96b5', 'e0ab65aa-4b7f-11e7-903f-5404a60d96b5', 'e0ab66d6-4b7f-11e7-903f-5404a60d96b5', 'e0ab67f8-4b7f-11e7-903f-5404a60d96b5', 'e0ab6938-4b7f-11e7-903f-5404a60d96b5', 'e0ab6a5a-4b7f-11e7-903f-5404a60d96b5', 'e0ab6b86-4b7f-11e7-903f-5404a60d96b5', 'e0ab6cc6-4b7f-11e7-903f-5404a60d96b5', 'e0ab6dfc-4b7f-11e7-903f-5404a60d96b5', 'e0ab6f28-4b7f-11e7-903f-5404a60d96b5']
17## new variables and request variables needed, change prov, structure, mipTable, frequency
18cl2 = ['ci', 'evspsbl', 'hurs', 'rtmt', 'sbl', 'sci', 'tauu', 'tauv']
19ucl2 = ['edbce584-4b7f-11e7-903f-5404a60d96b5', 'edbce8fe-4b7f-11e7-903f-5404a60d96b5', 'edbcea52-4b7f-11e7-903f-5404a60d96b5', 'edbcec8c-4b7f-11e7-903f-5404a60d96b5', 'edbcee44-4b7f-11e7-903f-5404a60d96b5', 'edbcefb6-4b7f-11e7-903f-5404a60d96b5', 'edbcf0f6-4b7f-11e7-903f-5404a60d96b5', 'edbcf236-4b7f-11e7-903f-5404a60d96b5', 'edbcf362-4b7f-11e7-903f-5404a60d96b5', 'edbcf498-4b7f-11e7-903f-5404a60d96b5', 'edbcf5e2-4b7f-11e7-903f-5404a60d96b5', 'edbcf72c-4b7f-11e7-903f-5404a60d96b5', 'edbcf86c-4b7f-11e7-903f-5404a60d96b5', 'edbcf998-4b7f-11e7-903f-5404a60d96b5', 'edbcface-4b7f-11e7-903f-5404a60d96b5', 'edbcfbfa-4b7f-11e7-903f-5404a60d96b5']
20
21
22strfrom = [(u'af250420-1e00-11e7-a625-5404a60d96b5', [u'str-d78', u'Temporal mean, Global field (single level) [XY-na] {:height10m} [tmean]', 'mn']), (u'f7dcac96-562c-11e6-a2a4-ac72891c3257', [u'str-013', u'Temporal mean, Global field (single level) [XY-na] [am-tm]', 'mn']), (u'f7e1ef26-562c-11e6-a2a4-ac72891c3257', [u'str-116', u'Temporal mean, Global field (single level) [XY-na] {:height2m} [tmean]', 'mn'])]
23
24strto = ['f7dfb7b0-562c-11e6-a2a4-ac72891c3257', '63c0cae8-15f2-11e7-87e0-5404a60d96b5', 'f7e8b996-562c-11e6-a2a4-ac72891c3257']
25
26smap = {}
27for k in range(3):
28  smap[ strfrom[k][0] ] = strto[k]
29
30## id for CF3hr grid variable group
31vgid = '008e672a-185c-11e7-8f2f-5404a60d96b5'
32
33nt__rqv = collections.namedtuple( 'rqv', ['uid','vid','vgid','priority','label','title','mip'] )
34nt__cmv = collections.namedtuple( 'cmv', ['uid','stid','rowIndex','mipTableSection','mipTable','mtid','frequency','prov'] )
35mip = 'CFMIP'
36mipTableSection = 'CF3hr_grid'
37mipTable = 'CF3hr'
38mtid = 'MIPtable::CF3hr'
39prov = 'CFMIP (CMIP5)'
40frequency = '3hr'
41
42sh = shelve.open( 'exports/l1sh/CMORvar' )
43shrqv = shelve.open( 'exports/l1sh/requestVar' )
44cols = sh['__cols__']
45print cols
46iu = cols.index( 'uid' )
47il = cols.index( 'label' )
48ir = cols.index( 'rowIndex' )
49istid = cols.index( 'stid' )
50im = cols.index( 'mipTable')
51ip = cols.index( 'prov')
52ifr = cols.index( 'frequency')
53ff = {}
54
55cc = collections.defaultdict( list )
56
57for k in sh.keys():
58  if k[0] != '_':
59    ff[(sh[k][il],sh[k][im])] = k
60    cc[(sh[k][il],sh[k][ifr])].append( k )
61
62
63k0 = ['uid','vid','vgid','priority','label','title','mip']
64ek0 = {}
65cols = shrqv['__cols__']
66for k in shrqv.keys()[:3]:
67   print shrqv[k]
68for x in k0:
69  ek0[x] = cols.index( x )
70for k in range(4):
71  ## add new request var
72  v = lgrp[k]
73  u = ulgrp[k]
74  vid = ff[(v,'3hr')]
75  this = nt__rqv( u,vid,vgid,1,v,'CF3hr: %s' % v,mip )
76  rec = k0[:]
77  for x in k0:
78    rec[ ek0[x] ] = this.__dict__[x]
79  print 'Create request var',rec
80  shrqv[u] = rec
81
82import sys
83
84cols2 = sh['__cols__']
85imt = cols2.index( 'mipTable' )
86imtid = cols2.index( 'mtid' )
87imts = cols2.index( 'mipTableSection' )
88for k in range(3):
89  ## change label and add request var
90  v = lmv[k]
91  u = ulmv[k]
92  vid = ff[(v,'E3hrPt')]
93  this = nt__rqv( u,vid,vgid,1,v,'CF3hr: %s' % v,mip )
94  rec = k0[:]
95  for x in k0:
96    rec[ ek0[x] ] = this.__dict__[x]
97  rec2 = sh[vid][:]
98  rec2[imt] = mipTable
99  rec2[imtid] = mtid
100  rec2[imts] = mipTableSection
101  print 'Create request var and update mipTable entry, uid=%s, vid=%s, var=%s' % (u,vid,v)
102  shrqv[u] = rec
103  sh[vid] = rec2
104
105k1 = ['uid','stid','rowIndex','mipTableSection','mipTable','mtid','frequency','prov']
106ek1 = {}
107for x in k1:
108  ek1[x] = cols2.index( x )
109for k in range(29):
110  ## clone mip variables, setting new values; add request var
111  if k < 21:
112    v = cl1[k]
113    u = ucl1[2*k]
114    vid2 = ucl1[2*k+1]
115  else:
116    kk = k - 21
117    v = cl2[kk]
118    u = ucl2[2*kk]
119    vid2 = ucl2[2*kk+1]
120  vid = ff[(v,'Amon')]
121  this = nt__rqv( u,vid2,vgid,1,v,'CF3hr: %s' % v,mip )
122  rec = k0[:]
123  for x in k0:
124    rec[ ek0[x] ] = this.__dict__[x]
125  rec2 = sh[vid][:]
126  stin = rec2[istid]
127  ss = smap[stin]
128  ix = rec2[ir]
129  ix = str( 200 + int( ix ) )
130  that = nt__cmv( vid2, ss, ix, mipTableSection, mipTable, mtid, frequency, prov )
131  for x in k1:
132    rec2[ek1[x]] = that.__dict__[x]
133  print 'Create request var, clone CMORvar and update attributes: ',this,rec2
134  shrqv[u] = rec
135  sh[vid2] = rec2
136
137
138shrqv.close()
139sh.close()
140
141##for k in range(8):
142  ## clone mip variables, setting new values; add request var
143  ##v = cl2[k]
144  ##u = ucl2[2*k]
145  ##vid2 = ucl2[2*k+1]
146  ##vid = ff[(v,'Amon')]
147  ##print 'Create request var, clone CMORvar and update attributes, uid=%s, vid=%s-->%s, var=%s' % (u,vid,vid2,v)
Note: See TracBrowser for help on using the repository browser.