source: CMIP6dreqbuild/trunk/srcMisc/dreqSX.py @ 375

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CMIP6dreqbuild/trunk/srcMisc/dreqSX.py@375
Revision 375, 4.6 KB checked in by mjuckes, 4 years ago (diff)

various

RevLine 
[355]1
2import shelve, string, collections
3from utils_wb import workbook, uniCleanFunc
4
[374]5vdate = "20150827"
[355]6
7sh = shelve.open( 'dreq_consol_tables_shelve_v%s' % vdate, 'r' )
8shnv = shelve.open( 'dreq_consol_tables_nv_shelve_v%s' % vdate, 'r' )
9## from vlsc5b --- includes new names from OMIP
[374]10shold = shelve.open( 'dreq_consol_tables_old_shelve_v20150713', 'r' )
[355]11shlist = [sh,shnv,shold]
12
13##MIP columns: recordid, ['comment', 'deflate_level', 'shuffle', 'ok_max_mean_abs', 'flag_meanings', 'type', 'ok_min_mean_abs', 'standard_name', 'deflate', 'long_name', 'valid_min', 'cell_methods', 'flag_values', 'cell_measures', 'out_name', 'modeling_realm', 'units', '#cell_methods', 'valid_max', 'positive'] , var, mip table, dims
14
15##ee0: Short name of group      Variable short name     Table   Frequency       Description extension (optional)        Shape   Levels  Time mean, point or climatology Mask (optional), priority, mip, uuid
16## vgrp, var, table, freq, comment, shape, levels, tform, mask, priority, mip, recordId
17## e.g. 'PMIP-Lmon', u'rh_c14', u'new', u'mon', '', u'XYT', '', '', '', 2, 'PMIP', '21de1a34-1597-11e5-861b-ac72891c3257')
18#####
19###['group','var','table','frequency','shape',''....
20### Want to map shape onto a "feature type" which will reference a set of dimensions.
21##XYT: latitude, longitude, time
22##'4 element vector' : seaice transect x time.
23## KZT: RFMIP: not clear what K is.
24## '2D vector field': from SIMIP, vector as in list: extra dimension is a list of thickness categories (
25
26##eenv:
27## MIP  standard name check     Review comments Shape etc       Short name      CF standard_name        standard name status    Native grid     units   Long Name       description/comments    Priority        associated observational dataset, ..., recordID (last)
28##e.g. [2, u'FAFMIP', -1.0, '', u'yr|XYZ|mean', u'ocontemppsmadvect', u'tendency_of_sea_water_conservative_temperature_expressed_as_heat_content_due_to_parameterized_submesoscale_advection', -1.0, u'ocean', u'W/m2', '', u'Level 2: priority unclear', 2.0, '', '', '', '', 'b1feb8a2-1598-11e5-92ad-ac72891c3257']
29
30##eeold:
31##e.g. ['ef36eefae77f82455c0a925167a0d4ca', 'rss', 'Net shortwave surface radiation', 'surface_net_downward_shortwave_flux', 'unset', 'W m-2', 'SPECS_day', 'mv.001.0094', 'mv.001.0394', '', '']
32##ee_xref
33##hash, uuid list -- list of mip tables for each parameter key (ee_old)
34
35ee_xref = {}
36ee_xref_bck = collections.defaultdict( list )
37ee_miptables_old = collections.defaultdict( list )
38ee_miptables_vars_old = collections.defaultdict( list )
39ee_ovars_old = collections.defaultdict( list )
40ee_mip = {}
41ee0 = {}
42eenv = {}
43## dictionary to carry short names of old variables.
44eeold = {}
[375]45###for ee,shv in [(ee0,sh),(eenv,shnv),(eeold,shold)]:
46for ee,shv in [(ee0,sh),(eenv,shnv)]:
[355]47  for k in shv.keys():
48    ee[k] = shv[k]
49
[375]50rmod = 'csv'
51eeoldl = collections.defaultdict( list )
52if rmod == 'xls':
53  for ee,fn in [(ee_xref,'vlsc5_xref_v20150826.xls'),(ee_mip,'vlsc5_mip_v20150826.xls'),(eeold,'vlsc5b_v20150826.xls')]:
54    wb = workbook( fn )
55    sh = wb.book.sheet_by_name( 'Sheet1' )
56    for i in range(sh.nrows):
57      r = map( lambda x: string.strip(str(uniCleanFunc(x.value))), sh.row(i) )
58      ee[r[0]] = r
59else:
60  for ee,fn,sep,xxx in [(ee_xref,'vlsc5_xref_v20150826.csv',',',False),(ee_mip,'vlsc5_mip_v20150826.csv', '\t',False),(eeoldl,'vlsc5b_v20150826.csv', '\t',True)]:
61    for i in open(fn).readlines():
62      r = map( lambda x: string.strip(str(uniCleanFunc(x))), string.split( string.strip(i), sep ) )
63      while len(r) < 9:
64        r.append( '' )
65      if xxx:
66        ee[r[0]].append( r )
67      else:
68        ee[r[0]] = r
[355]69
[375]70
71for h in eeoldl.keys():
72  if len( eeoldl[h] ) == 1:
73    eeold[h] = eeoldl[h][0]
74  else:
75    ll = []
76    for k in range( len( eeoldl[h] ) ):
77      if eeoldl[h][k][8] == '':
78        ll.append(k)
79    if len(ll) == 0:
80      print 'ERROR.004.0001: no unforwarded record in vlsc5b for h=%s' % h
81      eeold[h] = eeoldl[h][0]
82    elif len(ll) > 1:
83      print 'ERROR.004.0002: multiple unforwarded records in vlsc5b for h=%s (%s)' % (h,eeoldl[h][ll[0]][1])
84      eeold[h] = eeoldl[h][ll[0]]
85    else:
86      eeold[h] = eeoldl[h][ll[0]]
87
[355]88k2m = []
89km = []
90for k in ee_xref.keys():
91  if eeold.has_key(k):
92    for k2 in ee_xref[k][1:]:
93      if k2 != '':
94        if ee_mip.has_key(k2):
95          ee_xref_bck[k2].append(k)
96        else:
97          k2m.append( (k2,k) )
98  else:
99    km.append(k)
100
101##
102## had bug here due to extension of ee_mip to include dimensions.
103##
[375]104ee_byvar = collections.defaultdict(list)
[355]105for k in ee_mip.keys():
106  tid = ee_mip[k][-2]
107  ee_miptables_old[tid].append(  ee_mip[k][0] )
108  ee_miptables_vars_old[tid].append(  ee_mip[k][-3] )
109  ee_ovars_old['%s.%s' % (tid,ee_mip[k][-3]) ].append(  k )
[375]110  ee_byvar[ ee_mip[k][-3] ].append( k )
[355]111
112for s in shlist:
113  s.close()
Note: See TracBrowser for help on using the repository browser.