1 | |
---|
2 | ## |
---|
3 | ## still missing map from new groups to old table variables. |
---|
4 | ## need a key lookup by variable in each table. |
---|
5 | ## |
---|
6 | |
---|
7 | import collections, string, hashlib, uuid, os, sys |
---|
8 | import shelve |
---|
9 | import dreqSX as sx |
---|
10 | import dreq_utils |
---|
11 | import utils_wb |
---|
12 | from sets import Set |
---|
13 | odir = 'sh20150827' |
---|
14 | |
---|
15 | vdate = '20150907' |
---|
16 | if not os.path.isdir( odir ): |
---|
17 | os.mkdir( odir ) |
---|
18 | |
---|
19 | class uid1(object): |
---|
20 | def __init__(self, uid=None): |
---|
21 | if uid == None: |
---|
22 | self.uid = str( uuid.uuid1() ) |
---|
23 | else: |
---|
24 | self.uid = uid |
---|
25 | |
---|
26 | uidgen = collections.defaultdict( uid1 ) |
---|
27 | |
---|
28 | def labcoerce(s): |
---|
29 | s = string.replace(s, '.', '' ) |
---|
30 | s = string.replace(s, '+', '' ) |
---|
31 | s = string.replace(s, '/', ' ' ) |
---|
32 | s = string.replace(s, '--', '-' ) |
---|
33 | if string.find(s, '-' ) != -1: |
---|
34 | s = string.replace(s, '-', ' ' ) |
---|
35 | if string.find(s, ' ' ) != -1: |
---|
36 | s = string.replace( string.capwords( s ), ' ', '' ) |
---|
37 | return s |
---|
38 | |
---|
39 | sh1 = shelve.open( '%s/cmip5Groups' % odir, 'n' ) |
---|
40 | ## |
---|
41 | ## list of CMIP5 tables which have groups |
---|
42 | ## |
---|
43 | cmip5GroupsIx = set() |
---|
44 | ## |
---|
45 | ## dictionary, specifying group for each variable in table |
---|
46 | ## |
---|
47 | cmip5GroupsIVAR = collections.defaultdict( dict ) |
---|
48 | for k in sx.cmip5so.sop.keys(): |
---|
49 | sh1[k] = sx.cmip5so.sop[k][:] |
---|
50 | cmip5GroupsIx.add( string.split( k, '_' )[0] ) |
---|
51 | for v in sx.cmip5so.sop[k]: |
---|
52 | cmip5GroupsIVAR[ string.split( k, '_' )[0] ][v] = k |
---|
53 | if sx.cmip5so.omipInsert and k in sx.cmip5so.sxp: |
---|
54 | for v in sx.cmip5so.sxp[k]: |
---|
55 | cmip5GroupsIVAR[ string.split( k, '_' )[0] ][v] = k |
---|
56 | sh1.close() |
---|
57 | #### 'uuid', 'mip', 'label','title','ref','refNote' |
---|
58 | #### i, "CMIP6", key, ...., "CMIP5", '' |
---|
59 | cmip5tbs = [] |
---|
60 | cmip5tbs0 = set() |
---|
61 | cmip5gps = [] |
---|
62 | cmip5gplk = {} |
---|
63 | for k in sx.cmip5so.so.keys(): |
---|
64 | u = str( uuid.uuid1() ) |
---|
65 | cmip5gplk[k] = u |
---|
66 | cmip5tbs0.add( k ) |
---|
67 | cmip5tbs.append( [u,"CMIP6",k,"CMIP6 CMOR Table: %s" % k, "CMIP5", "CMIP5 MIP Table: %s" % k] ) |
---|
68 | |
---|
69 | for k in sx.cmip5so.sop.keys(): |
---|
70 | u = str( uuid.uuid1() ) |
---|
71 | cmip5gplk[k] = u |
---|
72 | t,s = string.split( k, '_' ) |
---|
73 | assert sx.cmip5so.so.has_key(t), 'Table for group %s not found' % k |
---|
74 | u2 = cmip5gplk[t] |
---|
75 | cmip5gps.append( [u,u2,"CMIP6",k,"CMIP6 Variable Group: %s" % k, "CMIP5", "CMIP5 MIP Table section: %s" % k] ) |
---|
76 | u3 = str( uuid.uuid1() ) |
---|
77 | ### section link .... variables in sections are linked to a section which carries a link to the group. |
---|
78 | ### request links can refer to a section or a group ..... |
---|
79 | |
---|
80 | cmip5vgr = ['Omon','fx','Oyr','Oclim','Omon_3d','Omon_oth','Amon','Lmon','LImon','OImon','aero_3d','aero_oth','cfDay_2d','cfDay_3d','cfMon_3dstd','cfMon_3dmod','cfMon_2dmod','cfMon_sim','day_oth','day_ss','cfOff','cfSites','6hrLev','6hrPlev','3hr','cf3hr_grid','cf3hr_sim'] |
---|
81 | ccmivgrdict = {'fixed':'fx','annual':'yr','monthly':'mon','daily':'day','hourly':'hr'} |
---|
82 | specsvgr = ['fx','mon','day','6hr'] |
---|
83 | |
---|
84 | ee_nv1 = collections.defaultdict( list ) |
---|
85 | ee_var_nv1 = collections.defaultdict( list ) |
---|
86 | ee_tabs = collections.defaultdict( list ) |
---|
87 | ee_grps = collections.defaultdict( list ) |
---|
88 | ee_usedVars = collections.defaultdict( list ) |
---|
89 | |
---|
90 | kmap = { 'cfday':'cfDay', 'Limon':'LImon', 'CMIP5_Llmon':'CMIP5_LImon', 'CMIP5 day':'CMIP5_day', 'NEW':'new', 'New':'new', \ |
---|
91 | 'CCMI monthly mean 3d':'CCMI1_monthly', \ |
---|
92 | 'CCMI Daily zonal mean 2d':'CCMI1_daily', \ |
---|
93 | 'CCMI monthly mean zonal mean 2d':'CCMI1_monthly', \ |
---|
94 | 'PMIP-LImon':'PMIP_LImon', 'CMIP5 Amon':'CMIP5_Amon', 'CCMI monthly':'CCMI1_monthly', 'PMIP-OImon':'PMIP_OImon'} |
---|
95 | |
---|
96 | for k in sx.eenv.keys(): |
---|
97 | mip = string.strip(sx.eenv[k][1]) |
---|
98 | var = string.strip(sx.eenv[k][5]) |
---|
99 | uid = sx.eenv[k][-1] |
---|
100 | ee_nv1[uid].append( k ) |
---|
101 | ee_var_nv1[var].append( k ) |
---|
102 | assert uid == k, 'mismatch in uid in record %s' % k |
---|
103 | |
---|
104 | def tabref1( ti ): |
---|
105 | if ti == 'new BUT': |
---|
106 | return 'CMIP5_Lmon' |
---|
107 | elif ti == 'new': |
---|
108 | return 'new' |
---|
109 | else: |
---|
110 | return ti |
---|
111 | |
---|
112 | for k in sx.ee0.keys(): |
---|
113 | r = sx.ee0[k] |
---|
114 | mip = r[10] |
---|
115 | assert mip == r[-3],'Double check failed' |
---|
116 | tab = r[2] |
---|
117 | grp = r[0] |
---|
118 | thistab = tabref1(tab) |
---|
119 | ##ee_tabs[tab].append(k) |
---|
120 | ee_tabs[thistab].append(k) |
---|
121 | ee_grps[grp].append(k) |
---|
122 | |
---|
123 | |
---|
124 | import sys |
---|
125 | |
---|
126 | kf = [] |
---|
127 | kfn = [] |
---|
128 | kfxx = [] |
---|
129 | kfgp = [] |
---|
130 | knf = [] |
---|
131 | kmapmap = {} |
---|
132 | for k in ee_tabs.keys(): |
---|
133 | k1 = kmap.get( k,k) |
---|
134 | if string.find( k1, ' ' ) != -1: |
---|
135 | k2 = string.split(k1)[0] |
---|
136 | else: |
---|
137 | k2 = k |
---|
138 | |
---|
139 | k2 = kmap.get( k2,k2) |
---|
140 | |
---|
141 | if k2 in ['new','']: |
---|
142 | kfn.append(k) |
---|
143 | kmapmap[k] = 'new' |
---|
144 | elif sx.ee_miptables_old.has_key(k2): |
---|
145 | kf.append(k) |
---|
146 | kmapmap[k] = k2 |
---|
147 | elif ee_grps.has_key(k2): |
---|
148 | kfgp.append(k) |
---|
149 | kmapmap[k] = k2 |
---|
150 | else: |
---|
151 | if sx.ee_miptables_old.has_key('CMIP5_%s' % k2 ): |
---|
152 | kfxx.append(k) |
---|
153 | kmapmap[k] = 'CMIP5_%s' % k2 |
---|
154 | else: |
---|
155 | knf.append(k) |
---|
156 | |
---|
157 | thisd = {} |
---|
158 | print 'Missing groups' |
---|
159 | for k in knf: |
---|
160 | thise = collections.defaultdict( int ) |
---|
161 | for k2 in ee_tabs[k]: |
---|
162 | thise[sx.ee0[k2][12-2]] += 1 |
---|
163 | keys = thise.keys() |
---|
164 | keys.sort() |
---|
165 | thisd[k] = keys[:] |
---|
166 | print 'ERROR.020.0001: Missing Group: %s :: %s' % (k, keys) |
---|
167 | |
---|
168 | ### look for new variables in variable groups. |
---|
169 | class d1(object): |
---|
170 | def __init__(self): |
---|
171 | self.d = collections.defaultdict( list ) |
---|
172 | self.onItemNotFound = 'error' |
---|
173 | |
---|
174 | def keys(self): |
---|
175 | return self.d.keys() |
---|
176 | |
---|
177 | def __setitem__(self,k,v): |
---|
178 | self.d[k].append(v) |
---|
179 | |
---|
180 | def __itemNotFound__(self,k): |
---|
181 | if self.onItemNotFound == 'error': |
---|
182 | raise KeyError( 'Key %s not found in dictionary keys' % k) |
---|
183 | |
---|
184 | def __getitem__(self,k): |
---|
185 | if self.d.has_key(k): |
---|
186 | return self.d[k] |
---|
187 | else: |
---|
188 | return self.__itemNotFound__(k) |
---|
189 | |
---|
190 | ## look up table, giving uuid from old mip tables for each mip, var combination. |
---|
191 | mvlookup = collections.defaultdict( d1 ) |
---|
192 | mvlookup2 = collections.defaultdict( list ) |
---|
193 | |
---|
194 | ee_unusedVars = [] |
---|
195 | nok = 0 |
---|
196 | nn = 0 |
---|
197 | ee0_null = collections.defaultdict( list ) |
---|
198 | ee0_xref = collections.defaultdict( list ) |
---|
199 | ee0_xref_old = collections.defaultdict( list ) |
---|
200 | for t in sx.ee_miptables_old.keys(): |
---|
201 | for u in sx.ee_miptables_old[t]: |
---|
202 | v1 = sx.ee_mip[u][15] |
---|
203 | v2 = sx.ee_mip[u][21] |
---|
204 | if v2 != '': |
---|
205 | vid = v2 |
---|
206 | else: |
---|
207 | vid = v1 |
---|
208 | mvlookup[t].d[vid].append( u ) |
---|
209 | |
---|
210 | for u in sx.eeold.keys(): |
---|
211 | mvlookup2[sx.eeold[u][1]].append( u ) |
---|
212 | |
---|
213 | ##for k in kfn: |
---|
214 | ##for u in ee_tabs[k]: |
---|
215 | |
---|
216 | |
---|
217 | ## ee0_xref values are values of ee_var_nv1 |
---|
218 | for u in sx.ee0.keys(): |
---|
219 | var = string.strip(sx.ee0[u][1]) |
---|
220 | tab = kmapmap.get(tabref1(sx.ee0[u][2]), None ) |
---|
221 | if ee_var_nv1.has_key(var): |
---|
222 | nok += 1 |
---|
223 | ee_usedVars[var].append( u ) |
---|
224 | ## reference to kex in eenv |
---|
225 | ee0_xref[u] += ((0,ee_var_nv1[var] ),) |
---|
226 | elif ee_var_nv1.has_key(var + "**"): |
---|
227 | nok += 1 |
---|
228 | ee_usedVars[var].append( u ) |
---|
229 | ee0_xref[u] += ((0,ee_var_nv1[var + "**"] ),) |
---|
230 | else: |
---|
231 | ok = False |
---|
232 | if mvlookup.has_key(tab): |
---|
233 | if mvlookup[tab].d.has_key( var ): |
---|
234 | ul = mvlookup[tab].d[var] |
---|
235 | if len(ul) > 1: |
---|
236 | print 'ERROR.001.011: variable %s has multiple entries %s' % (var,tab) |
---|
237 | ee0_xref[u] += ((1,[ul[0],]),) |
---|
238 | ok = True |
---|
239 | else: |
---|
240 | emsg = '.001.010: variable %s not found in %s' % (var,tab) |
---|
241 | else: |
---|
242 | emsg = '.001.012: [%s] table not found: %s' % (var,tab) |
---|
243 | |
---|
244 | if not ok: |
---|
245 | if mvlookup2.has_key( var ): |
---|
246 | if len( mvlookup2[var] ) == 1: |
---|
247 | ee0_xref[u] += ((2,[mvlookup2[var][0],]),) |
---|
248 | ok = True |
---|
249 | print 'WARN' + emsg + ' [alternative found]' |
---|
250 | else: |
---|
251 | print 'ERROR' + emsg |
---|
252 | |
---|
253 | if not ok: |
---|
254 | print 'ERROR.090.077000:',tab,sx.ee0[u] |
---|
255 | ee0_xref[u] += ((-1,['__var_not_found_012__',]),) |
---|
256 | |
---|
257 | if ( len(sx.ee0[u][1]) > 0 and sx.ee0[u][1][0] == '#' ) or ( len(sx.ee0[u][0]) > 0 and sx.ee0[u][0][0] == '#' ): |
---|
258 | ee0_null[u].append( '# comment' ) |
---|
259 | elif ( len(sx.ee0[u][0]) > 5 and sx.ee0[u][0][:4] == 'PMIP' ) and ( sx.ee0[u][1] in ['','*'] ): |
---|
260 | ee0_null[u].append( 'PMIP bulk copy' ) |
---|
261 | elif len(sx.ee0[u][1]) == 0 and len(sx.ee0[u][2]) == 0: |
---|
262 | ee0_null[u].append( 'comment' ) |
---|
263 | else: |
---|
264 | nn += 1 |
---|
265 | ee_unusedVars.append((u,var)) |
---|
266 | |
---|
267 | print nn, nok |
---|
268 | nok = 0 |
---|
269 | nn = 0 |
---|
270 | thise1 = [] |
---|
271 | uclear = {} |
---|
272 | ### run through CMIP5 variables which are modified, re-used etc in new CMIP6 groups. |
---|
273 | ### 43 not found .... as above ..... |
---|
274 | for k in kf + kfxx: |
---|
275 | k2 = kmapmap[k] |
---|
276 | for u in ee_tabs[k]: |
---|
277 | var = string.strip(sx.ee0[u][1] ) |
---|
278 | if not var in sx.ee_miptables_vars_old[k2]: |
---|
279 | print 'ERROR.0001.002: variables in sx.ee0 [new groups] not found: ',k,var,sx.ee0[u] |
---|
280 | nn += 1 |
---|
281 | else: |
---|
282 | ee_usedVars[var].append( u ) |
---|
283 | |
---|
284 | ok = False |
---|
285 | if sx.ee_ovars_old.has_key('%s.%s' % (k2,var)): |
---|
286 | uclear[u] = sx.ee_ovars_old['%s.%s' % (k2,var)] |
---|
287 | ok = True |
---|
288 | elif sx.ee_ovars_old.has_key('%s.%s**' % (k2,var)): |
---|
289 | uclear[u] = sx.ee_ovars_old['%s.%s**' % (k2,var)] |
---|
290 | ok = True |
---|
291 | elif len(string.split( k, ' ')) > 1: |
---|
292 | bits = string.split( k, ' ') |
---|
293 | v1 = string.strip(bits[1])[1:-1] |
---|
294 | if sx.ee_ovars_old.has_key('%s.%s' % (k2,v1)): |
---|
295 | uclear[u] = sx.ee_ovars_old['%s.%s' % (k2,v1)] |
---|
296 | ok = True |
---|
297 | |
---|
298 | if not ok: |
---|
299 | thise1.append((u,k2,var)) |
---|
300 | ##ee0_xref_old[u] |
---|
301 | |
---|
302 | ee_mv0 = {} |
---|
303 | ee_mv1 = {} |
---|
304 | ee_mv2 = {} |
---|
305 | ee_mv3 = {} |
---|
306 | for k in sx.eeold.keys(): |
---|
307 | k1 = sx.eeold[k][7] |
---|
308 | assert k1[:3] == 'mv.', 'Key not in correct syntax: %s' % k1 |
---|
309 | ee_mv0[k1] = k |
---|
310 | k2 = sx.eeold[k][8] |
---|
311 | if k2 != "": |
---|
312 | if k2 in ["*omit",'null','Depricated']: |
---|
313 | if k2 in ["*omit",'Depricated']: |
---|
314 | ee_mv3[ k1 ] = k2 |
---|
315 | else: |
---|
316 | starflag = False |
---|
317 | if k2[0] == '*': |
---|
318 | k2 = k2[1:] |
---|
319 | starflag = True |
---|
320 | assert k2[:3] == 'mv.', 'target key not in correct syntax: %s' % k2 |
---|
321 | if starflag: |
---|
322 | ee_mv2[k1] = k2 |
---|
323 | else: |
---|
324 | ee_mv1[k1] = k2 |
---|
325 | |
---|
326 | for k in ee_mv1.keys(): |
---|
327 | assert ee_mv0.has_key(k), 'key cross-ref not found: %s' % k |
---|
328 | |
---|
329 | ll_ov = [] |
---|
330 | for k in ee_mv0.keys(): |
---|
331 | if not (ee_mv3.has_key(k) or ee_mv1.has_key(k)): |
---|
332 | ll_ov.append( ee_mv0[k] ) |
---|
333 | print 'Number of old variables: %s [%s]' % (len(ll_ov), len(ee_mv0.keys()) ) |
---|
334 | print len(sx.eenv.keys()) |
---|
335 | print "Number of new variables: %s" % ( len(sx.eenv.keys()) ) |
---|
336 | ## |
---|
337 | ## extract variable name, units, standard name, long name, comment |
---|
338 | nt_vrecix = collections.namedtuple( 'vrecix', ['v','u','s','l','c'] ) |
---|
339 | vrecix_new = nt_vrecix._make( (5,9,6,10,11) ) |
---|
340 | vrecix_old = nt_vrecix._make( (1,5,3,2,4) ) |
---|
341 | |
---|
342 | nnf = 0 |
---|
343 | nnm = 0 |
---|
344 | nno = 0 |
---|
345 | for k in sx.ee_mip.keys(): |
---|
346 | t = map( lambda x: sx.ee_mip[k][x], [15,10,8,1,17] ) |
---|
347 | h = hashlib.md5(string.join(t) ).hexdigest() |
---|
348 | if not sx.ee_xref_bck.has_key(k): |
---|
349 | r1 = sx.ee_mip[k][1] |
---|
350 | if r1 in ['','29'] or r1[:23] == 'Reference to literature' or r1[:15] == '(copied from 3D': |
---|
351 | print 'WARN.002.0010: dud record',sx.ee_mip[k], sx.ee_mip[k][-2][:4] |
---|
352 | else: |
---|
353 | print 'ERROR.002.0010: missing back reference',sx.ee_mip[k], sx.ee_mip[k][-2][:4] |
---|
354 | nnf += 1 |
---|
355 | elif len(sx.ee_xref_bck[k]) > 1: |
---|
356 | nnm += 1 |
---|
357 | print 'ERROR.0001.001: #######', sx.ee_mip[k] |
---|
358 | for k2 in sx.ee_xref_bck[k]: |
---|
359 | print sx.eeold[k2] |
---|
360 | |
---|
361 | print '#### Number of missing back references: %s (%s)' % (nnf,nno) |
---|
362 | |
---|
363 | |
---|
364 | class dopenxx(object): |
---|
365 | def __init__(self): |
---|
366 | self.fn = 'xx_%s' % str( uuid.uuid1() ) |
---|
367 | self.oo = open('%s/%s' % (self.odir,self.fn), 'w' ) |
---|
368 | def write(self,x): |
---|
369 | self.oo.write(x) |
---|
370 | def close(self,rename=None): |
---|
371 | self.oo.close() |
---|
372 | if rename != None: |
---|
373 | os.rename( '%s/%s' % (self.odir,self.fn), '%s/%s' % (self.odir,rename) ) |
---|
374 | |
---|
375 | class dopen(object): |
---|
376 | def __init__(self,odir='./'): |
---|
377 | if not os.path.isdir(odir): |
---|
378 | os.mkdir(odir) |
---|
379 | self.odir = odir |
---|
380 | self.a = collections.defaultdict( self.ClassFact() ) |
---|
381 | def close(self,k,rename=None): |
---|
382 | if self.a.has_key(k): |
---|
383 | self.a[k].close(rename=rename) |
---|
384 | self.a.__delitem__(k) |
---|
385 | |
---|
386 | def ClassFact(self): |
---|
387 | class dopenyy(dopenxx): |
---|
388 | """Inherits all methods from dreqItemBase""" |
---|
389 | |
---|
390 | dopenyy.odir = self.odir |
---|
391 | return dopenyy |
---|
392 | print 'INFO 001 ##################',nnf, nnm |
---|
393 | |
---|
394 | ##sh = shelve.open( 'shelve_vars' ) |
---|
395 | sh = shelve.open( '%s/cmipVars' % odir, 'n' ) |
---|
396 | sh['__info__'] = { 'label':'cmipVars', 'title':'CMIP variables', 'prov':'sx.eenv and sx.eeold' } |
---|
397 | sh['__cols__'] = ['label','title','sn','units','description','procnote','procComment','prov','priority0','realm0'] |
---|
398 | |
---|
399 | ee = {} |
---|
400 | for k in sx.eenv.keys(): |
---|
401 | this = nt_vrecix._make( map( lambda x: sx.eenv[k][x], vrecix_new ) ) |
---|
402 | ##sh[k] = { 'label':this.v, 'title':this.l, 'sn':this.s, 'units':this.u, 'description':this.c, 'procnote':'', 'procComment':'','prov':'CMIP6 endorsement' } |
---|
403 | prov = 'CMIP6 endorsement [%s]' % sx.eenv[k][1] |
---|
404 | sh[k] = [ this.v, this.l, this.s, this.u, this.c, '', '',prov, sx.eenv[k][0], sx.eenv[k][8] ] |
---|
405 | ee[this.u] = k |
---|
406 | if this.u == 'atmos': |
---|
407 | print 'ERROR: bad units',k, sx.eenv[k] |
---|
408 | print '################################### var units #################' |
---|
409 | print ee.keys() |
---|
410 | print '##########################################################' |
---|
411 | |
---|
412 | nk = 0 |
---|
413 | for k in ll_ov: |
---|
414 | this = nt_vrecix._make( map( lambda x: sx.eeold[k][x], vrecix_old ) ) |
---|
415 | ##sh[k] = { 'label':this.v, 'title':this.l, 'sn':this.s, 'units':this.u, 'description':this.c, 'procnote':'', 'procComment':'','prov':sx.eeold[k][6]} |
---|
416 | if this.v in sx.cmip5ByVar.keys(): |
---|
417 | s = set() |
---|
418 | for t in sx.cmip5ByVar[this.v]: |
---|
419 | s.add( sx.cmip5so.so[t].a[this.v][18] ) |
---|
420 | |
---|
421 | s = list(s) |
---|
422 | rlm0 = string.join( s ) |
---|
423 | elif this.v in sx.eenvo: |
---|
424 | rlm0 = sx.eenvo[this.v][0][8] |
---|
425 | print 'INFO.llll: using eenvo .....',this.v |
---|
426 | else: |
---|
427 | rlm0 = '__na__' |
---|
428 | |
---|
429 | sh[k] = [ this.v, this.l, this.s, this.u, this.c, '', '',sx.eeold[k][6], 101, rlm0 ] |
---|
430 | nk += 1 |
---|
431 | |
---|
432 | print len( sx.eenv.keys() ) + len(ll_ov), len( sh.keys() ), len( sx.eenv.keys() ) |
---|
433 | sh.close() |
---|
434 | |
---|
435 | ### |
---|
436 | ### shelve contains 1682 variables, of which 561 are new. |
---|
437 | ### |
---|
438 | |
---|
439 | ### have lost somewhere the var/cmor var distinction. E.g. hfibthermds/hfibthermds2d --- 2 CMOR variable names with a single output variable name. |
---|
440 | ### But this will not be in the physical variable -- so should come in the output variable record. |
---|
441 | |
---|
442 | class c1(object): |
---|
443 | def __init__(self): |
---|
444 | self.d = collections.defaultdict( int ) |
---|
445 | class c2(object): |
---|
446 | def __init__(self): |
---|
447 | self.d = collections.defaultdict( list ) |
---|
448 | ee = collections.defaultdict( int ) |
---|
449 | ff = collections.defaultdict( c1 ) |
---|
450 | #count different shapes: |
---|
451 | blk = collections.defaultdict( c2 ) |
---|
452 | for k in sx.ee0.keys(): |
---|
453 | ee[sx.ee0[k][5]] += 1 |
---|
454 | ff[sx.ee0[k][5]].d[sx.ee0[k][10]] += 1 |
---|
455 | blk[sx.ee0[k][5]].d[sx.ee0[k][10]].append(k) |
---|
456 | keys = ee.keys() |
---|
457 | keys.sort() |
---|
458 | print keys |
---|
459 | ####################################### |
---|
460 | eeo = collections.defaultdict( int ) |
---|
461 | ffo = collections.defaultdict( c1 ) |
---|
462 | #count different shapes: |
---|
463 | hdims = [ 'latitude','longitude'] |
---|
464 | vdims = [ 'alevel','alevhalf', 'olevel', 'rho', 'alt40', 'location', 'plev','alev1', 'plev3', 'plev7', 'plev8', 'plevs', 'sdepth'] |
---|
465 | |
---|
466 | catdims = ['site', 'basin', 'oline', 'dbze', 'scatratio', 'sza5', 'tau', 'vegtype', 'vgidx'] |
---|
467 | tdims = ['time','time1','time2'] |
---|
468 | |
---|
469 | knowndims = hdims + vdims + catdims + tdims |
---|
470 | |
---|
471 | nsmap = {'':'MISC...', u'XYZKT':'lon.lat.ATMOS.other.time', u'XKT':'PMIP....', u'4-element vector':'..transsi.time', u'KZT':'RFMIP...', u'2D vector field':'lon.lat..sithick.time', u'XYZ':'lon.lat.olevel..time', u'XYZT':'lon.lat.ATMOS..time', u'2D':'SIMIP ... (xYT?)', u'scalar':'?...', u'XY':'FAFMIP, ISMIP6....', u'YZT':'MISC....', u'XYKT':'lon.lat..other.time', u'XYT':'lon.lat...time', u'ZST1':'..alevel.site.time', u'?':'PMIP', u'BasinYT':'.lat..basin.time'} |
---|
472 | ## XYZ: this occurs only in FAFMIP |
---|
473 | ## XYZT: {'C4MIP': 80, 'PMIP': 10, 'RFMIP': 3, 'CFMIP': 19, 'LS3MIP': 8, 'GeoMIP': 1, 'HighResMIP': 82} |
---|
474 | ## need to follow up on what is vertical. # of levels is captured in most cases. |
---|
475 | ## PMIP: email sent -- 29th June : some ocean, some atmos |
---|
476 | ## LS3MIP: soil or snow layers, |
---|
477 | ## RFMIP: all levels. |
---|
478 | ## XYZKT: CFMIP -- K has various forms. |
---|
479 | ## XKT: PMIP -- salt transport -- should be lat-basin-time? |
---|
480 | ## blank: {'LUMIP': 40, 'PMIP': 11, 'RFMIP': 4, 'HighResMIP': 11, 'FAFMIP': 3, 'DynVar': 10} |
---|
481 | #----- RFMIP: scalar .... email sent -- these ar OfflineRad varibles. |
---|
482 | #----- LUMIP: XYT |
---|
483 | #----- PMIP: occurs in bulk copy requests ..... |
---|
484 | #----- HighResMip: occurs in comment lines |
---|
485 | #----- FAFMIP: occurs in comment lines |
---|
486 | #----- DynVar: probably XYZT -- need to check whether on model or pressure levels. |
---|
487 | ## YZT: 'DAMIP': 4, 'VolMIP': 2, 'HighResMIP': 10, 'SolarMIP': 4 |
---|
488 | # ---- DAMIP: zonal mean, 17 or 23 levels (pressure) .. |
---|
489 | # ---- VolMIP: zonal mean, all levels |
---|
490 | # ---- HighResMIP: zonal mean, 36 levels |
---|
491 | # ---- SolarMIP: zonal mean, 17 or 23 levels. (withdrawn and merged with DAMIP ....). |
---|
492 | ## scalar: 'ISMIP6': 8, 'SIMIP': 6 |
---|
493 | ## --> to KT, with K set to icesheet/hemisphere |
---|
494 | ## ----- SIMIP: time (monthly) |
---|
495 | ## '?': PMIP, for variables specified in C4MIP. |
---|
496 | ## |
---|
497 | |
---|
498 | ed = collections.defaultdict( c1 ) |
---|
499 | for k in sx.ee_mip.keys(): |
---|
500 | dl = sx.ee_mip[k][-1] |
---|
501 | if dl == 's|c|a|l|a|r': |
---|
502 | dl = 'scalar' |
---|
503 | dd = string.split( dl, '|' ) |
---|
504 | for d in dd[:-1]: |
---|
505 | |
---|
506 | ed[d].d[dd.index(d)] += 1 |
---|
507 | ed[dd[-1]].d['f'] += 1 |
---|
508 | eeo[sx.ee_mip[k][-1]] += 1 |
---|
509 | ffo[sx.ee_mip[k][-1]].d[sx.ee_mip[k][-2]] += 1 |
---|
510 | keys = eeo.keys() |
---|
511 | keys.sort() |
---|
512 | |
---|
513 | nkn = [] |
---|
514 | for k in ed.keys(): |
---|
515 | if k not in knowndims: |
---|
516 | nkn.append(k) |
---|
517 | nkn.sort() |
---|
518 | |
---|
519 | presetlinks = {} |
---|
520 | shlnks = shelve.open( '%s/requestLinks_tmp' % odir, 'r' ) |
---|
521 | for k in shlnks.keys(): |
---|
522 | if k[0] != '_': |
---|
523 | if shlnks[k][9] > -1: |
---|
524 | print 'INFO.aaa.00001: Priority reset ',shlnks[k] |
---|
525 | presetlinks[ '%s.%s' % (shlnks[k][1],shlnks[k][2]) ] = shlnks[k][9] |
---|
526 | ## |
---|
527 | ## read in provisional request groups --- based on request scoping sheet |
---|
528 | ## |
---|
529 | shrvg = shelve.open( '%s/requestVarGroup_tmp' % odir, 'r' ) |
---|
530 | eervg = collections.defaultdict( list ) |
---|
531 | ## |
---|
532 | ## construct look-up by label |
---|
533 | ## |
---|
534 | for k in shrvg.keys(): |
---|
535 | if k[0] != '_': |
---|
536 | ##assert not eervg.has_key( shrvg[k][2] ), 'Duplicate rvg: %s' % shrvg[k][2] |
---|
537 | eervg[shrvg[k][2]].append( k ) |
---|
538 | |
---|
539 | |
---|
540 | sh = shelve.open( 'dreq_consol_tables_reviewed_b_v%s' % vdate, 'r' ) |
---|
541 | revTabIds = Set( sh.keys()[:] ) |
---|
542 | sh.close() |
---|
543 | |
---|
544 | ## parse 1 |
---|
545 | ee0_p1 = {} |
---|
546 | ee0_gp = collections.defaultdict( d1 ) |
---|
547 | st1 = set() |
---|
548 | for k in sx.ee0.keys(): |
---|
549 | r = list(sx.ee0[k][:] ) |
---|
550 | if r[1] != '' and r[1][0] != '#': |
---|
551 | if ee0_xref.has_key(k): |
---|
552 | r1 = ee0_xref[k] |
---|
553 | assert len(r1) == 1, 'FATAL:001.0001: unexpected duplicate cross ref, %s %s %s' % (k,str(r1),str(r) ) |
---|
554 | assert len(r1[0][1]) == 1, 'FATAL:001.0002: unexpected duplicate cross ref, %s %s %s' % (k,str(r1),str(r) ) |
---|
555 | r += [r1[0][0],r1[0][1][0]] |
---|
556 | else: |
---|
557 | r += [-1,'__none__'] |
---|
558 | ee0_p1[k] = r[:] |
---|
559 | ee0_gp[r[0]][r[10]] = k |
---|
560 | st1.add( r[10] ) |
---|
561 | if r[0] == '': |
---|
562 | print '################' |
---|
563 | print r |
---|
564 | |
---|
565 | |
---|
566 | ##assert 'CFMIP' in st1, 'FAILED sanity check 1 ... CFMIP not in st1 %s' % str(st1) |
---|
567 | assert len( list(st1) ) < 40, 'FAILED sanity check 2 ... too many items in st1 [should be list of MIPs] %s' % len(list(st1)) |
---|
568 | print '################### groups referenced from new groups sheets' |
---|
569 | print ee0_gp.keys() |
---|
570 | k1 = ee0_gp.keys() |
---|
571 | k1.sort() |
---|
572 | kmapk1 = {} |
---|
573 | for k in k1: |
---|
574 | assert len(ee0_gp[k].keys()) in [0,1], 'Multiple references to %s' % k |
---|
575 | for k2 in ee0_gp[k].keys(): |
---|
576 | if eervg.has_key( '%s.%s' % (k2,k) ): |
---|
577 | kmapk1[k] = ('%s.%s' % (k2,k),'newGp') |
---|
578 | else: |
---|
579 | kmapk1[k] = ('%s.%s' % (k2,k),'unresolved') |
---|
580 | |
---|
581 | gpids = [] |
---|
582 | for k in kmapk1.keys(): |
---|
583 | gpids.append(kmapk1[k][0]) |
---|
584 | kmapk2 = {} |
---|
585 | |
---|
586 | mmmm = [('C_OceanT1', 'C_Ocean_T1'), ('C_OceanT2', 'C_Ocean_T2'), ('3hr_extreme','3hr_extr'), ('Amon_extreme','Amon_ext'), \ |
---|
587 | ('Amon_convection','Amon_conv'), ('L3hr','L_3hr'), ('LEday','L_day'), ('DYNVAR_day','DYVR_daily') ] |
---|
588 | mmmm = [('C_OceanT1', 'C_Ocean_T1'), ('C_OceanT2', 'C_Ocean_T2'), ('3hr_extreme','3hr_extr'), ('Amon_extreme','Amon_ext'), \ |
---|
589 | ('Amon_convection','Amon_conv'), ('L3hr','L_3hr'), ('DYNVAR_day','DYVR_daily') ] |
---|
590 | kmap000 = {} |
---|
591 | for t in mmmm: |
---|
592 | kmap000[t[0]] = t[1] |
---|
593 | |
---|
594 | ## |
---|
595 | ## check links from variable output specs to group. |
---|
596 | ## need to identify what is meant by group labels in "Request Scoping" -- now in eervg.keys() |
---|
597 | ## |
---|
598 | ## 29th July: loosing some links for groups of revised table items .... |
---|
599 | ## |
---|
600 | ## these are the reviewed cmip5 standard output tables. |
---|
601 | ## |
---|
602 | tabuuidrefs = collections.defaultdict( int ) |
---|
603 | |
---|
604 | ### |
---|
605 | ### get some tables for looking up links from shelve |
---|
606 | ### |
---|
607 | shbx = dreq_utils.parseShb(vdate,sx,cmip5gplk) |
---|
608 | |
---|
609 | |
---|
610 | gpids = gpids + shbx.revisedTabKeysff |
---|
611 | ks = eervg.keys() |
---|
612 | ks.sort() |
---|
613 | for k0 in ks: |
---|
614 | a,b = string.split(k0,'.') |
---|
615 | if kmap000.has_key(b): |
---|
616 | k = '%s.%s' % (a,kmap000[b]) |
---|
617 | else: |
---|
618 | k = k0 |
---|
619 | ok = False |
---|
620 | if b[:5] == 'CCMI1': |
---|
621 | b1,b2 = string.split(b, '_' ) |
---|
622 | if ccmivgrdict.has_key( b2): |
---|
623 | ok = True |
---|
624 | kmapk2[k0] = ('CCMI',b2) |
---|
625 | elif b[:5] == 'SPECS': |
---|
626 | b1,b2 = string.split(b, '_' ) |
---|
627 | if b2 in specsvgr: |
---|
628 | ok = True |
---|
629 | kmapk2[k0] = ('SPECS',b2) |
---|
630 | elif b2 == 'Amon': |
---|
631 | kmapk2[k0] = ('SPECS','mon') |
---|
632 | ok = True |
---|
633 | if not ok: |
---|
634 | if k in gpids: |
---|
635 | ## print 'OK1: ',k |
---|
636 | kmapk2[k0] = ('new',k) |
---|
637 | ok = True |
---|
638 | elif a in ['LUMIP','LS3MIP']: |
---|
639 | tk = 'C4MIP.%s' % kmap000.get(b,b) |
---|
640 | if tk in gpids: |
---|
641 | kmapk2[k0] = ('new',tk) |
---|
642 | ok = True |
---|
643 | elif a in ['VolMIP','DAMIP']: |
---|
644 | tk = 'DynVar.%s' % kmap000.get(b,b) |
---|
645 | if tk in gpids: |
---|
646 | kmapk2[k0] = ('new',tk) |
---|
647 | ok = True |
---|
648 | if not ok: |
---|
649 | ## revTabIds has table names, revGpIds has group names |
---|
650 | if k in revTabIds or k in shbx.revGpIds: |
---|
651 | if k in shbx.revGpIds: |
---|
652 | print 'OK2: ',k |
---|
653 | kmapk2[k0] = ('CMIP5Rev',k) |
---|
654 | else: |
---|
655 | if b in cmip5vgr: |
---|
656 | kmapk2[k0] = ('CMIP5',b) |
---|
657 | elif b in cmip5tbs0: |
---|
658 | kmapk2[k0] = ('CMIP5',b) |
---|
659 | else: |
---|
660 | print 'WARN.080.09001: nomap for ',b,k |
---|
661 | kmapk2[k0] = ('nomap',k) |
---|
662 | |
---|
663 | print '###############################################################' |
---|
664 | print '###############################################################' |
---|
665 | ## |
---|
666 | ## following list currently contains separate entries for group references from different MIPs --- want to have a single one |
---|
667 | ## here, and multiple references to it ... |
---|
668 | ## |
---|
669 | rvgref2 = collections.defaultdict( list ) |
---|
670 | lookup1a = collections.defaultdict( d1 ) |
---|
671 | lookup1b = {} |
---|
672 | lookup1 = collections.defaultdict( d1 ) |
---|
673 | lookup2 = collections.defaultdict( d1 ) |
---|
674 | import sx2_extra as sx2e |
---|
675 | rvguids = set() |
---|
676 | #### prepare for requestVarGroup ########### |
---|
677 | ## C4MIP-OceanT2 C4MIP: C4MIP-OceanT2 C4MIP new C4MIP.C_Ocean_T2 |
---|
678 | ## label title mip ref refNote |
---|
679 | |
---|
680 | #### |
---|
681 | #### reconfigure to uuid, mip, label (no "."), title, class, refNote |
---|
682 | #### for "ttt==new", use sx2e.ngmap( kkk ) to give labels, keep kkk as refNote, ttt --> class |
---|
683 | ### |
---|
684 | ### lookup1: constructed from requestVarGroup list |
---|
685 | for k in shrvg.keys(): |
---|
686 | if k[0] != '_': |
---|
687 | id0 = shrvg[k][2] |
---|
688 | ttt,kkk = kmapk2[id0] |
---|
689 | lookup1a[ttt].d[kkk].append(k) |
---|
690 | if ttt == 'new': |
---|
691 | rvgref2[kkk].append( shrvg[k][0] ) |
---|
692 | |
---|
693 | for k in lookup1a.keys(): |
---|
694 | for k2 in lookup1a[k].d.keys(): |
---|
695 | id0 = lookup1a[k].d[k2][0] |
---|
696 | id = str( uuid.uuid1() ) |
---|
697 | lookup1[k].d[k2].append( id) |
---|
698 | lookup1b[id0] = id |
---|
699 | |
---|
700 | ### |
---|
701 | ## add cmip5tbs to lookup, so that these will be picked up in links from "rqeuestLinks" |
---|
702 | for g in cmip5tbs: |
---|
703 | ####cmip5tbs.append( [u,"CMIP6",k,"CMIP6 CMOR Table: %s" % k, "CMIP5", "CMIP5 MIP Table: %s" % k] ) |
---|
704 | k = g[2] |
---|
705 | u = g[0] |
---|
706 | lookup1['CMIP5'].d[k] = [u,] |
---|
707 | |
---|
708 | ### shlnks carries the "request scoping rows" ### |
---|
709 | ndup = 0 |
---|
710 | for k in shlnks.keys(): |
---|
711 | thistr = False |
---|
712 | if k[0] != '_': |
---|
713 | if shlnks[k][9] > -1: |
---|
714 | print 'INFO.aaa.00001: Priority reset ',shlnks[k] |
---|
715 | if shlnks[k][2][-4:] == '_oth': |
---|
716 | thistr = True |
---|
717 | k1 = '%s.%s' % (shlnks[k][1],shlnks[k][2]) |
---|
718 | if thistr: |
---|
719 | print k1 |
---|
720 | assert kmapk2.has_key(k1), 'Key missing %s, %s' % (k,k1) |
---|
721 | if not kmapk2.has_key(k1): |
---|
722 | pass |
---|
723 | #print '###########',shlnks[k] |
---|
724 | else: |
---|
725 | ttt,kkk = kmapk2[k1] |
---|
726 | id = lookup1[ttt].d[kkk][0] |
---|
727 | if thistr: |
---|
728 | print ttt,kkk,id |
---|
729 | if id == k: |
---|
730 | print '***DUPLICATE:',k,k1, ttt, kkk, lookup1[ttt].d[kkk] |
---|
731 | ndup += 1 |
---|
732 | |
---|
733 | assert ndup==0, ndup |
---|
734 | |
---|
735 | tmp = collections.defaultdict( list ) |
---|
736 | for k in lookup1.keys(): |
---|
737 | for k2 in lookup1[k].d.keys(): |
---|
738 | if k2 in presetlinks: |
---|
739 | print 'INFO.aaa.00200: preset refound,', k2 |
---|
740 | for idi in lookup1a[k].d[k2]: |
---|
741 | id = lookup1[k].d[k2][0] |
---|
742 | ####idi = lookup1a[k].d[k2][0] |
---|
743 | id0 = shrvg[idi][2] |
---|
744 | mip = shrvg[idi][1] |
---|
745 | ttt,kkk = kmapk2[id0] |
---|
746 | cls = k |
---|
747 | assert cls == k, 'Mismatch in lookup1' |
---|
748 | refNote = k2 |
---|
749 | kl = 0 |
---|
750 | lab = '__unset__' |
---|
751 | ##print k2, cls |
---|
752 | if cls == 'new': |
---|
753 | if kkk in shbx.revisedTabKeys: |
---|
754 | lab = kkk |
---|
755 | cls = 'rev' |
---|
756 | lab = string.replace( kkk, '.', '-' ) |
---|
757 | kl = 1 |
---|
758 | else: |
---|
759 | if not sx2e.ngmap.has_key(kkk): |
---|
760 | print 'ERROR.002.0001: key %s not found' % kkk |
---|
761 | else: |
---|
762 | lab = sx2e.ngmap[kkk] |
---|
763 | kl = 2 |
---|
764 | elif cls == 'CMIP5': |
---|
765 | lab = string.replace( k2, '_', '-' ) |
---|
766 | kl = 3 |
---|
767 | elif cls in ['CMIP5Rev','rev']: |
---|
768 | lab = string.replace( k2, '.', '-' ) |
---|
769 | kl = 4 |
---|
770 | elif cls == 'nomap': |
---|
771 | lab = string.replace( k2, '.', '-' ) |
---|
772 | kl = 5 |
---|
773 | lab = string.replace( lab, '_', '-' ) |
---|
774 | else: |
---|
775 | lab = '%s-%s' % (mip,k2) |
---|
776 | kl = 6 |
---|
777 | if sx2e.r1.match( lab ) == None: |
---|
778 | print 'NON_COMPLIANT label', lab,k2, cls |
---|
779 | rec, sup = ([id,mip,lab,'%s: %s' % (mip,lab), cls, refNote],[ttt,kkk]) |
---|
780 | if string.find( string.join( rec ), '__unset__' ) != -1: |
---|
781 | print 'INFO.ppp.00003: ',rec, sup, lab,k2, cls, kl |
---|
782 | if refNote == 'C4MIP.Lmon': |
---|
783 | print 'WARN.051.00001: ',rec,sup, lab,k2, cls, kl |
---|
784 | ##['6a7ed72e-98d7-11e5-9c3a-ac72891c3257', 'LUMIP', u'C4MIP-Lmon', u'LUMIP: C4MIP-Lmon', 'rev', u'C4MIP.Lmon'] ['new', u'C4MIP.Lmon'] C4MIP-Lmon C4MIP.Lmon rev 1 |
---|
785 | tmp[id].append( (rec, sup) ) |
---|
786 | |
---|
787 | sh = shelve.open( '%s/requestVarGroup' % odir, 'n' ) |
---|
788 | sh['__info__'] = { 'label':'requestVarGroup', 'title':'Identify variable groups' } |
---|
789 | sh['__cols__'] = [ 'uuid', 'mip', 'label','title','ref','refNote'] |
---|
790 | sss = collections.defaultdict( list ) |
---|
791 | for id in tmp.keys(): |
---|
792 | dosh = False |
---|
793 | trc = '>' |
---|
794 | if len(tmp[id]) == 1: |
---|
795 | rec,sup = tmp[id][0] |
---|
796 | dosh = True |
---|
797 | tr = 1 |
---|
798 | else: |
---|
799 | s = {tuple(sup) for rec,sup in tmp[id]} |
---|
800 | if len(s) == 1: |
---|
801 | rec,sup = tmp[id][0] |
---|
802 | dosh = True |
---|
803 | tr=2 |
---|
804 | else: |
---|
805 | tr=3 |
---|
806 | print 'ERROR.070.0020: ambiguous variable groups ' |
---|
807 | for l in tmp[id]: |
---|
808 | print l |
---|
809 | if sup[0] not in ['new','CMIP5Rev']: |
---|
810 | ttt, kkk = sup |
---|
811 | lab = '%s-%s' % (ttt,kkk) |
---|
812 | cls, refNote = rec[-2:] |
---|
813 | rec = [id,ttt,lab,'%s: %s' % (ttt,kkk), cls, refNote] |
---|
814 | print 'INFO:070.0001: modifying record: %s --> %s' % (mip,ttt) |
---|
815 | tr += 0.5 |
---|
816 | trc += 'mod:' |
---|
817 | kc = '%s.%s' % (rec[-2],rec[-1]) |
---|
818 | if rec[-2] == 'CCMI': |
---|
819 | kc = '%s1.%s' % (rec[-2],rec[-1]) |
---|
820 | print 'WARN.080.08100: adjusting CCMI to CCMI1: ',rec |
---|
821 | if kc == 'SPECS.6hr': |
---|
822 | print kc, rec, tr |
---|
823 | if kc[:4] == 'CCMI': |
---|
824 | print 'INFO.cccc: ',rec |
---|
825 | sss[kc].append( id ) |
---|
826 | rvguids.add( rec[0] ) |
---|
827 | uidgen[ kc ] = uid1(uid=rec[0]) |
---|
828 | |
---|
829 | if rec[3] in ['CMIP6 CMOR Table: Oyr',]: |
---|
830 | print 'INFO.ppp.00001: omitting ',rec |
---|
831 | else: |
---|
832 | sh[rec[0]] = rec |
---|
833 | |
---|
834 | a = {k for k in sss.keys() if len(sss[k]) > 1} |
---|
835 | if len(a) > 0: |
---|
836 | for k in a: |
---|
837 | print 'SEVERE.090.0001: ',k,sss[k] |
---|
838 | |
---|
839 | ## |
---|
840 | ## appears to have become redundant |
---|
841 | ## |
---|
842 | dosi = False |
---|
843 | if dosi: |
---|
844 | for k in ['seaiceday', 'seaicemon']: |
---|
845 | id = str( uuid.uuid1() ) |
---|
846 | mip = 'SIMIP' |
---|
847 | lab = '%s-%s' % (mip,k) |
---|
848 | title = '%s: %s' % (mip,k) |
---|
849 | cls = 'newOrp' |
---|
850 | refNote = '%s.%s' % (mip,k) |
---|
851 | rvguids.add( id ) |
---|
852 | sh[id] = [id,mip,lab,title, cls, refNote] |
---|
853 | lookup1[cls].d[refNote].append(id) |
---|
854 | |
---|
855 | ## add CMIP5 groups ......... |
---|
856 | for g in cmip5tbs: |
---|
857 | kc = '%s.%s' % (g[-2],g[-1]) |
---|
858 | sss[kc].append( g[0] ) |
---|
859 | rvguids.add( g[0] ) |
---|
860 | if g[3] in ['CMIP6 CMOR Table: Oyr',]: |
---|
861 | print 'INFO.ppp.00002: omitting ',g |
---|
862 | else: |
---|
863 | sh[g[0]] = g[:] |
---|
864 | sh.close() |
---|
865 | |
---|
866 | ############################################## |
---|
867 | a = {k for k in sss.keys() if len(sss[k]) > 1} |
---|
868 | if len(a) > 0: |
---|
869 | for k in a: |
---|
870 | print 'SEVERE.090.0002: ',k,sss[k] |
---|
871 | ############################################## |
---|
872 | |
---|
873 | sh = shelve.open( '%s/requestVarSections' % odir, 'n' ) |
---|
874 | sh['__info__'] = { 'label':'requestVarGroup', 'title':'Identify variable groups' } |
---|
875 | sh['__cols__'] = [ 'uuid', 'gpid', 'mip', 'label','title','ref','refNote'] |
---|
876 | ## add CMIP5 groups ......... |
---|
877 | for g in cmip5gps: |
---|
878 | sh[g[0]] = g[:] |
---|
879 | sh.close() |
---|
880 | ######## |
---|
881 | ######## this does not work .... the variables need to be added to "revTabItems", |
---|
882 | ######## with link to variable group associated with the CMIP5 group. |
---|
883 | ######## latter should be available through "CMIP5-Omon_3d" etc....: |
---|
884 | |
---|
885 | ## |
---|
886 | |
---|
887 | err001 = collections.defaultdict( int ) |
---|
888 | sh = shelve.open( '%s/groupItems' % odir, 'n' ) |
---|
889 | sh['__info__'] = {'label':'groupItems', 'title':'List of items in new groups', 'description':"New groups" } |
---|
890 | ##(u'DYVR_daily', u'utendnogw', '', u'daily', '', '', '', '', '', u'DynVar', 'DynVar', '772da0b6-25b6-11e5-8cf6-ac72891c3257') |
---|
891 | sh['__cols__'] = ['group','var','table','freq','', 'shape', '', '', '','mip','mip?','uuid','rowIndex','new','gpid','vkey','vid'] |
---|
892 | for k in ee0_p1.keys(): |
---|
893 | kkk = '%s.%s' % (ee0_p1[k][10],ee0_p1[k][0]) |
---|
894 | ##if not sx2e.ngmap.has_key(kkk): |
---|
895 | if lookup1['new'].d.has_key(kkk): |
---|
896 | id = lookup1['new'].d[kkk][0] |
---|
897 | elif lookup1['newOrp'].d.has_key(kkk): |
---|
898 | id = lookup1['newOrp'].d[kkk][0] |
---|
899 | else: |
---|
900 | id = None |
---|
901 | err001[kkk] += 1 |
---|
902 | r = ee0_p1[k][:] |
---|
903 | if id != None: |
---|
904 | r[-2] = 1 |
---|
905 | r[-1] = id |
---|
906 | else: |
---|
907 | r[-2] = -1 |
---|
908 | r[-1] = '__none__' |
---|
909 | t = ee0_xref[k][0] |
---|
910 | r += [t[0],t[1][0]] |
---|
911 | sh[k] = r[:] |
---|
912 | sh.close() |
---|
913 | |
---|
914 | sh = shelve.open( '%s/requestLinks' % odir, 'n' ) |
---|
915 | sh['__info__'] = { 'label':'requestLinks', 'title':'Links from variable groups to a request id' } |
---|
916 | sh['__cols__'] = [ 'uid', 'mip', 'tab','objective','grid','gridreq','comment','opt','opar','preset','ref','refNote','refid'] |
---|
917 | ndup = 0 |
---|
918 | for k in shlnks.keys(): |
---|
919 | if k[0] != '_': |
---|
920 | k1 = '%s.%s' % (shlnks[k][1],shlnks[k][2]) |
---|
921 | preset = shlnks[k][9] |
---|
922 | assert kmapk2.has_key(k1), 'Key missing %s, %s' % (k,k1) |
---|
923 | if not kmapk2.has_key(k1): |
---|
924 | #print '###########',shlnks[k] |
---|
925 | pass |
---|
926 | else: |
---|
927 | ttt,kkk = kmapk2[k1] |
---|
928 | |
---|
929 | if shbx.revisedTabKeysNM.has_key(k1): |
---|
930 | print 'INFO.010.0010: Replacing link for %s' % k1 |
---|
931 | id = shbx.revisedTabKeysNM[k1] |
---|
932 | else: |
---|
933 | id = lookup1[ttt].d[kkk][0] |
---|
934 | |
---|
935 | if preset > -1: |
---|
936 | print 'INFO.aaa.00100: ', shlnks[k], kmapk2[k1], id |
---|
937 | sh[k] = list( shlnks[k] ) + list( kmapk2[k1] ) + [id,] |
---|
938 | if id not in rvguids: |
---|
939 | print 'ERROR.080.06005: Request variable group link broken:', sh[k] |
---|
940 | if sh[k][0] == sh[k][-1]: |
---|
941 | print 'DUPLICATE LINK:',k,sh[k] |
---|
942 | ndup += 1 |
---|
943 | print 'INFO: Number of duplicates %s (%s)' % (ndup, len(sh.keys())) |
---|
944 | sh.close() |
---|
945 | ## link to group items is now via mip + group id, using stuff from kmapk2 .... |
---|
946 | |
---|
947 | dorest = True |
---|
948 | |
---|
949 | class psort(object): |
---|
950 | |
---|
951 | def __init__(self): |
---|
952 | pass |
---|
953 | |
---|
954 | def p(self,z): |
---|
955 | return tabpri.get(z,9) |
---|
956 | |
---|
957 | def cmp(self,x,y): |
---|
958 | return cmp( self.p(x), self.p(y) ) |
---|
959 | |
---|
960 | if dorest: |
---|
961 | tabpri = { 'SPECS':2, 'CMIP5':0, 'CORDEX':3, 'PMIP3':4 } |
---|
962 | |
---|
963 | gg = {} |
---|
964 | for k in sx.eeold.keys(): |
---|
965 | if sx.eeold[k][7][:6] == 'mv.005': |
---|
966 | gg[sx.eeold[k][1]] = k |
---|
967 | ### |
---|
968 | ### BUT need to get full OMIP records in here ...... |
---|
969 | cmip5GroupCol = collections.defaultdict( list ) |
---|
970 | sh = shelve.open( '%s/refTableItems' % odir, 'n' ) |
---|
971 | sh['__info__'] = {'label':'refTableItems', 'title':'List of items in reference tables', 'prov':'sx.ee_mip' } |
---|
972 | sh['__cols__'] = ['uuid', 'comment', 'deflate_level', 'shuffle', 'ok_max_mean_abs', 'flag_meanings', \ |
---|
973 | 'type', 'ok_min_mean_abs', 'standard_name', 'deflate', 'long_name', 'valid_min',\ |
---|
974 | 'cell_methods', 'flag_values', 'cell_measures', 'out_name', 'modeling_realm', 'units',\ |
---|
975 | '#cell_methods', 'valid_max', 'positive', 'var', 'mipTable','dimensions','vid','gpid','ssect','priority'] |
---|
976 | |
---|
977 | ## added gpid for link to variable group .... not clear at this point how OMIP to be dealt with here. |
---|
978 | ## for sections, perhaps need new section linking sections to groups .... |
---|
979 | |
---|
980 | vdefex = {} |
---|
981 | rwixkkk = 0 |
---|
982 | for k in sx.ee_mip.keys(): |
---|
983 | gpid = '__group_unknown__' |
---|
984 | rwix = 0 |
---|
985 | mipt = sx.ee_mip[k][22] |
---|
986 | if shbx.tabuuid.has_key( mipt ): |
---|
987 | gpid = shbx.tabuuid[mipt] |
---|
988 | p = 0 |
---|
989 | ssect = '' |
---|
990 | if mipt[:4] in { "CMIP", "CCMI", "SPEC", "CORD"}: |
---|
991 | m,t = string.split( mipt, '_' ) |
---|
992 | # output name |
---|
993 | v0 = sx.ee_mip[k][15] |
---|
994 | # variable name |
---|
995 | v1 = sx.ee_mip[k][21] |
---|
996 | if type(v0) == type( 'y' ) and v0 not in ['', ' ']: |
---|
997 | v1 = v0 |
---|
998 | |
---|
999 | if v1 == 'rtmt': |
---|
1000 | print 'xxyyyy',v1,sx.ee_mip[k] |
---|
1001 | |
---|
1002 | trc = [] |
---|
1003 | if m == "CMIP5": |
---|
1004 | assert cmip5gplk.has_key(t), 'ERROR.009.0010: CMIP5 table link not found for %s' % mipt |
---|
1005 | gpid = cmip5gplk[t] |
---|
1006 | assert sx.cmip5so.so.has_key(t), 'Key %s not found in cmip5.so keys' % t |
---|
1007 | if not sx.cmip5so.so[t].a.has_key(v1): |
---|
1008 | if t in sx.cmip5so.sx and v1 in sx.cmip5so.sx[t].a: |
---|
1009 | print 'ERROR.030.0001xx: Variable %s not found in cmip5so %s' % (v1,t) |
---|
1010 | else: |
---|
1011 | print 'ERROR.030.0001: Variable %s not found in cmip5so %s' % (v1,t) |
---|
1012 | p = 0 |
---|
1013 | trc.append( 'p0' ) |
---|
1014 | else: |
---|
1015 | p = sx.cmip5so.so[t].a[v1][0] |
---|
1016 | trc.append( 'pp' ) |
---|
1017 | rwix = sx.cmip5so.so[t].a[v1][23] |
---|
1018 | si = sx.cmip5so.so[t].a[v1][24] |
---|
1019 | try: |
---|
1020 | rwix = rwix + 200*si |
---|
1021 | except: |
---|
1022 | print sx.cmip5so.so[t].a[v1], len(sx.cmip5so.so[t].a[v1]) |
---|
1023 | raise |
---|
1024 | |
---|
1025 | ## the "Oyr" group is for import, not needed in request |
---|
1026 | if t in cmip5GroupsIx and t not in ['Oyr','Amon']: |
---|
1027 | trc.append( 'ix' ) |
---|
1028 | ##assert cmip5GroupsIVAR[t].has_key(v1) or cmip5GroupsIVAR[t].has_key(v0), '%s not found in table %s' % (v1,t) |
---|
1029 | if not (cmip5GroupsIVAR[t].has_key(v1) or cmip5GroupsIVAR[t].has_key(v0) ): |
---|
1030 | print 'ERROR.080.0020: %s not found in table %s' % (v1,t) |
---|
1031 | else: |
---|
1032 | if cmip5GroupsIVAR[t].has_key(v1): |
---|
1033 | trc.append( '1' ) |
---|
1034 | gp = cmip5GroupsIVAR[t][v1] |
---|
1035 | else: |
---|
1036 | gp = cmip5GroupsIVAR[t][v0] |
---|
1037 | trc.append( '0' ) |
---|
1038 | ## |
---|
1039 | ## collect variables in each group, along with key and priority, to create "revTabItems" |
---|
1040 | ## |
---|
1041 | ##if v1 == 'rtmt': |
---|
1042 | ##print 'zzzzzz',gp,v1,k,p,trc |
---|
1043 | cmip5GroupCol[ gp ].append( (v1,k,p) ) |
---|
1044 | else: |
---|
1045 | thisk = '%s.%s' % (m,t) |
---|
1046 | if thisk in shbx.tabuuid: |
---|
1047 | gpid = shbx.tabuuid[thisk] |
---|
1048 | else: |
---|
1049 | gpid = uidgen[thisk].uid |
---|
1050 | |
---|
1051 | elif mipt[:5] == "OMIP.": |
---|
1052 | #### |
---|
1053 | #### this would be the place to create "OMIP.Omon_3d" and "OMIP.Omon_oth" |
---|
1054 | #### |
---|
1055 | #### also need to generate "OMIP.Oyr_3dtr" .... |
---|
1056 | #### |
---|
1057 | #### some information added to tabsectbyvar in dreq_utils |
---|
1058 | #### |
---|
1059 | #### might be cleaner in framework/scanDreq ... |
---|
1060 | #### |
---|
1061 | #### |
---|
1062 | m,t = string.split( mipt, '.' ) |
---|
1063 | # output name |
---|
1064 | v0 = sx.ee_mip[k][15] |
---|
1065 | # variable name |
---|
1066 | v1 = sx.ee_mip[k][21] |
---|
1067 | if type(v0) == type( 'y' ) and v0 not in ['', ' ']: |
---|
1068 | v1 = v0 |
---|
1069 | ## check to see if sections are defined. |
---|
1070 | if shbx.tabsectbyvar.has_key(m): |
---|
1071 | tv = '%s.%s' % (t,v1) |
---|
1072 | if shbx.tabsectbyvar[m].has_key(tv): |
---|
1073 | gpid = shbx.tabsectuuid[m][ '%s.%s' % (t,shbx.tabsectbyvar[m][tv][2]) ] |
---|
1074 | rwix = shbx.tabsectbyvar[m][tv][3] |
---|
1075 | ssect = shbx.tabsectbyvar[m][tv][2] |
---|
1076 | p = shbx.tabsectbyvar[m][tv][1] |
---|
1077 | rwixkkk += 1 |
---|
1078 | |
---|
1079 | if gpid == '__group_unknown__': |
---|
1080 | print 'ERROR.040.0010: OMIP group not found %s, %s, %s' % (mipt,v0,) |
---|
1081 | elif gpid == '__group_unknown__': |
---|
1082 | print 'ERROR:040.0011: failed to set gpid: ',sx.ee_mip[k] |
---|
1083 | omit = False |
---|
1084 | if not sx.ee_xref_bck.has_key( k ): |
---|
1085 | r1 = sx.ee_mip[k][1] |
---|
1086 | if r1 in ['','29'] or r1[:23] == 'Reference to literature' or r1[:15] == '(copied from 3D': |
---|
1087 | print 'WARN.002.0003: dud record',sx.ee_mip[k], sx.ee_mip[k][-2][:4] |
---|
1088 | omit = True |
---|
1089 | elif sx.ee_mip[k][-2][:4] == 'OMIP': |
---|
1090 | print 'ERROR.002.0004: no back references %s' % str(sx.ee_mip[k]) |
---|
1091 | else: |
---|
1092 | print 'ERROR.002.0003: no back references %s' % str(sx.ee_mip[k]) |
---|
1093 | kl = ['__none__',] |
---|
1094 | vnam0 = '' |
---|
1095 | else: |
---|
1096 | kl = sx.ee_xref_bck[ k ] |
---|
1097 | if len(kl) != 1: |
---|
1098 | print 'ERROR.002.0001: multiple back references %s' % str(kl) |
---|
1099 | #print sx.ee_mip[k] |
---|
1100 | kv = kl[0] |
---|
1101 | r = sx.eeold[kv] |
---|
1102 | vnam0 = r[1] |
---|
1103 | kit = 0 |
---|
1104 | itl = [] |
---|
1105 | while r[8] not in [ '','null','Depricated'] and r[8][0] != '*': |
---|
1106 | itl.append(r) |
---|
1107 | if ee_mv0.has_key(r[8]): |
---|
1108 | kv = ee_mv0[ r[8] ] |
---|
1109 | r = sx.eeold[kv] |
---|
1110 | else: |
---|
1111 | print 'ERROR.002.0002: ambiguous back reference: %s' % str(r) |
---|
1112 | kit += 1 |
---|
1113 | assert kit < 5, 'Too many iterations: %s,\n%s' % (str(r),str(itl)) |
---|
1114 | if kit > 1: |
---|
1115 | print 'WARNING.002.0001: chained reference: %s' % str(r) |
---|
1116 | kl = [kv,] |
---|
1117 | print 'INFO.999.00005: ',omit, rec |
---|
1118 | if not omit: |
---|
1119 | ## count refs, for use in determining where to create group records .... |
---|
1120 | tabuuidrefs[gpid] += 1 |
---|
1121 | if r[1] != vnam0: |
---|
1122 | print 'INFO.0001.001: name change:',r,vnam0 |
---|
1123 | vdefex[k] = list(r) + [vnam0,] |
---|
1124 | if len( sx.ee_mip[k][:] ) != 24: |
---|
1125 | print 'ERROR.015.0002: Bad record length %s: %s' % (k,sx.ee_mip[k]) |
---|
1126 | rec = sx.ee_mip[k][:] + [kl[0],gpid,rwix,p] |
---|
1127 | if rec[21] == u'bsi' or rec[15] == u'bsi': |
---|
1128 | print 'INFO.999.00001: ',[rec[i] for i in [15,21,22,25]] |
---|
1129 | sh[k] = sx.ee_mip[k][:] + [kl[0],gpid,rwix,ssect,p] |
---|
1130 | if gpid not in rvguids: |
---|
1131 | print 'ERROR.080.06006: Request variable group link broken:', sh[k] |
---|
1132 | sh.close() |
---|
1133 | |
---|
1134 | sha = shelve.open( 'dreq_consol_tables_reviewed_a_v%s' % vdate ) |
---|
1135 | shb = shelve.open( 'dreq_consol_tables_reviewed_b_v%s' % vdate ) |
---|
1136 | keys = shb.keys() |
---|
1137 | keys.sort() |
---|
1138 | k0 = [] |
---|
1139 | for k in shbx.revisedTabKeysff: |
---|
1140 | bb = string.split(k, '.' ) |
---|
1141 | if len(bb) == 2: |
---|
1142 | k0.append( tuple(bb) ) |
---|
1143 | |
---|
1144 | sh = shelve.open( '%s/revTabItems' % odir, 'n' ) |
---|
1145 | sh['__info__'] = {'label':'revTabItems', 'title':'List of items in revised tables', 'description':"uuid (col 3) references an item in 'refTableItems'", 'prov':'from dreq_consol_tables_reviewed_b_v%s, cross-referenced with sx.ee_miptables_old' % vdate } |
---|
1146 | sh['__cols__'] = ['var','table','mip','uuid','priority'] |
---|
1147 | #### |
---|
1148 | dop = dopen('check3') |
---|
1149 | kr = 0 |
---|
1150 | krn = 0 |
---|
1151 | |
---|
1152 | for m,t in k0: |
---|
1153 | vars = shb[ '%s.%s' % (m,t) ] |
---|
1154 | print 'INFO.003.0001: ',m,t, sorted( vars.keys() )[:3] |
---|
1155 | ee = {} |
---|
1156 | ff = {} |
---|
1157 | ## |
---|
1158 | ## inclusion of CFMIP here was an error .... |
---|
1159 | if m in ["OMIP",'CFMIPx']: |
---|
1160 | rk = '%s.%s' % (m,t) |
---|
1161 | else: |
---|
1162 | rk = 'CMIP5_%s' % t |
---|
1163 | |
---|
1164 | if not sx.ee_miptables_old.has_key(rk): |
---|
1165 | print 'ERROR.003.0002: key %s not found ' % rk |
---|
1166 | else: |
---|
1167 | for u in sx.ee_miptables_old[rk]: |
---|
1168 | ee[ sx.ee_mip[u][21] ] = u |
---|
1169 | if vdefex.has_key(u): |
---|
1170 | if vdefex[u][1] != sx.ee_mip[u][21]: |
---|
1171 | ff[vdefex[u][1]] = u |
---|
1172 | ##if sx.ee_xref_bck.has_key(u): |
---|
1173 | |
---|
1174 | for v0 in vars.keys(): |
---|
1175 | v = string.strip( v0 ) |
---|
1176 | r = sha['records'][vars[v0][0]] |
---|
1177 | if not ee.has_key(v): |
---|
1178 | if ff.has_key(v): |
---|
1179 | print 'INFO ... rename found',v |
---|
1180 | thisu = ff[v] |
---|
1181 | elif v[:7] == 'include': |
---|
1182 | thisu = '__inc__' |
---|
1183 | else: |
---|
1184 | thisu = None |
---|
1185 | if sx.ee_byvar.has_key( v ): |
---|
1186 | tabs = map( lambda x: sx.ee_mip[x][-2], sx.ee_byvar[v] ) |
---|
1187 | tbs = map( lambda x: string.split(x, '_' )[-1], tabs ) |
---|
1188 | cls = map( lambda x: string.split(x, '_' )[0], tabs ) |
---|
1189 | if t in tbs: |
---|
1190 | cl0 = [] |
---|
1191 | for k in range(len(tbs)): |
---|
1192 | if tbs[k] == t: |
---|
1193 | cl0.append( cls[k] ) |
---|
1194 | |
---|
1195 | cl0.sort( psort().cmp ) |
---|
1196 | ix = tabs.index( '%s_%s' % (cl0[0],t) ) |
---|
1197 | print 'WARN.003.0001 var not found -- alternative table used [%s]: %s (%s, %s)' % (cl0[0],v,m,t) |
---|
1198 | thisu = sx.ee_byvar[v][ix] |
---|
1199 | |
---|
1200 | ##print map( lambda x: sx.ee_mip[x][-2], sx.ee_byvar[v] ) |
---|
1201 | elif m in ['OMIP','CFMIP'] and gg.has_key(v): |
---|
1202 | print 'INFO.003.00010: new %s var found: %s' % (m,v) |
---|
1203 | thisu = '__new.%s__' % m |
---|
1204 | krn += 1 |
---|
1205 | id = str( uuid.uuid1() ) |
---|
1206 | dop.a[ '%s3' % string.lower( m ) ].write( string.join( [id,] + map(lambda x: r[x],[4,0,5,2,7]) + ['%s_%s' % (m,t),'mv.006.%4.4i' % krn], '\t' ) + '\n' ) |
---|
1207 | |
---|
1208 | if thisu == None: |
---|
1209 | print 'ERROR.003.0001 var not found: %s (%s, %s)' % (v,m,t) |
---|
1210 | thisu = "__var_not_found__" |
---|
1211 | |
---|
1212 | if m == 'OMIP': |
---|
1213 | kr += 1 |
---|
1214 | sr = map(str,r) |
---|
1215 | dop.a['omip'].write( string.join( map(str,r), '\t' ) + '\n' ) |
---|
1216 | dop.a['omip2'].write( string.join( map(lambda x: str(r[x]),[4,0,5,2,7]) + ['%s_%s' % (m,t),'mv.005.%4.4i' % kr], '\t' ) + '\n' ) |
---|
1217 | |
---|
1218 | else: |
---|
1219 | thisu = ee[v] |
---|
1220 | kv = str( uuid.uuid1() ) |
---|
1221 | if t == 'day_oth': |
---|
1222 | print 'xxxxxx', v,t,m,r |
---|
1223 | if v == 'clic': |
---|
1224 | print 'INFO.clic.00002: ',v,t,m,thisu,v0,vars[v0] |
---|
1225 | sh[kv] = [v,t,m,thisu,vars[v0][1]] |
---|
1226 | |
---|
1227 | ### cmip5GroupCol[ gp ].append( (v1,k,p) ) |
---|
1228 | gpextra = [] |
---|
1229 | for gp in cmip5GroupCol.keys(): |
---|
1230 | for v,k,p in cmip5GroupCol[gp]: |
---|
1231 | kv = str( uuid.uuid1() ) |
---|
1232 | rec = [v,gp,'CMIP5',k,int(p)] |
---|
1233 | if gp == 'day_oth': |
---|
1234 | print 'xxxxyy', rec, gp |
---|
1235 | gpextra.append(rec) |
---|
1236 | sh[kv] = rec[:] |
---|
1237 | dop.close('omip',rename='omip.csv') |
---|
1238 | dop.close('omip2',rename='omip2.csv') |
---|
1239 | dop.close('omip3',rename='omip3.csv') |
---|
1240 | sh.close() |
---|
1241 | |
---|
1242 | sh = shelve.open( '%s/requestVarGroup' % odir ) |
---|
1243 | ## add OMIP (+ ....?) |
---|
1244 | nomip = 0 |
---|
1245 | for k in shbx.tabuuid.keys(): |
---|
1246 | if k[0] != '_': |
---|
1247 | ####cmip5tbs.append( [u,"CMIP6",k,"CMIP6 CMOR Table: %s" % k, "CMIP5", "CMIP5 MIP Table: %s" % k] ) |
---|
1248 | if tabuuidrefs[shbx.tabuuid[k]] > 0: |
---|
1249 | mip,tab = string.split( k, '.' ) |
---|
1250 | u = shbx.tabuuid[k] |
---|
1251 | if mip in {u'OMIP', 'OMIP'}: |
---|
1252 | lab = '%s-%s' % (mip,tab) |
---|
1253 | else: |
---|
1254 | lab = tab |
---|
1255 | sh[u] = [u,mip,lab,"CMOR Table variant: %s" % k, "CMIP5Rev", k ] |
---|
1256 | ####'OMIP', u'OMIP-fx', u'OMIP: OMIP-fx', 'CMIP5Rev', u'OMIP.fx' |
---|
1257 | print 'INFO: ADDING GROUP: %s' % str(sh[u]) |
---|
1258 | nomip += 1 |
---|
1259 | sh.close() |
---|
1260 | print nomip |
---|
1261 | |
---|
1262 | |
---|
1263 | ##wb = utils_wb.workbook( 'CMIP6DataRequest_ConsolidatedExperiments_20151028.xls' ) |
---|
1264 | wb = utils_wb.workbook( 'CMIP6DataRequest_ConsolidatedExperiments_20160110.xls' ) |
---|
1265 | sht = wb.book.sheet_by_name( 'Experiments' ) |
---|
1266 | p = dreq_utils.prconsolexpt() |
---|
1267 | p.parse(sht) |
---|
1268 | |
---|
1269 | ## info about the deck to fill in. |
---|
1270 | wb2 = utils_wb.workbook( 'CMIP6DataRequest_deckInfo.xls' ) |
---|
1271 | sht2 = wb2.book.sheet_by_name( 'Experiments' ) |
---|
1272 | |
---|
1273 | ## appends records to "p.records" |
---|
1274 | p.parse(sht2) |
---|
1275 | |
---|
1276 | sh = shelve.open( '%s/experiments' % odir, 'n' ) |
---|
1277 | sh['__info__'] = { 'label':'experiments', 'title':'Experiments', 'prov':'ConsolidatedExperiments' } |
---|
1278 | sh['__cols__'] = ['uuid','egid','label','description','mip','mcfg','tier','nstart','starty','endy','yps','ensz','ntot','comment'] |
---|
1279 | ##['label','group','mip','description','modelClass','tier','nstart','starty','endy','yps','ensz','ntot','comment'] |
---|
1280 | eegg = {} |
---|
1281 | eetm = collections.defaultdict( set ) |
---|
1282 | eent = collections.defaultdict( int ) |
---|
1283 | for r in p.records: |
---|
1284 | u = str( uuid.uuid1() ) |
---|
1285 | gp = r[1] |
---|
1286 | if not eegg.has_key(gp): |
---|
1287 | eegg[gp] = str( uuid.uuid1() ) |
---|
1288 | |
---|
1289 | if type( r[5] ) == type( 1 ): |
---|
1290 | eetm[gp].add( r[5] ) |
---|
1291 | else: |
---|
1292 | eetm[gp].add( r[5][-1] ) |
---|
1293 | eent[gp] += r[11] |
---|
1294 | label = labcoerce( r[0] ) |
---|
1295 | oo = [u,eegg[gp],label] |
---|
1296 | for j in [3,2,4,5,6,7,8,9,10,11,12]: |
---|
1297 | oo.append( r[j] ) |
---|
1298 | sh[u] = oo[:] |
---|
1299 | sh.close() |
---|
1300 | |
---|
1301 | sh = shelve.open( '%s/exptGroups' % odir, 'n' ) |
---|
1302 | sh['__info__'] = { 'label':'exptGroups', 'title':'Experiment groups', 'prov':'ConsolidatedExperiments' } |
---|
1303 | sh['__cols__'] = ['uuid','label','tiermin','ntot'] |
---|
1304 | for k in eegg.keys(): |
---|
1305 | if not eegg.has_key(gp): |
---|
1306 | eegg[gp] = str( uuid.uuid1() ) |
---|
1307 | |
---|
1308 | lab = labcoerce(k) |
---|
1309 | oo = [eegg[k],lab,min(eetm[k]),eent[k]] |
---|
1310 | sh[oo[0]] = oo[:] |
---|
1311 | sh.close() |
---|
1312 | |
---|
1313 | print uidgen.keys() |
---|