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

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

adding python scripts

Line 
1
2import shelve, string, collections
3from utils_wb import workbook, uniCleanFunc
4
5vdate = "20150714"
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
10shold = shelve.open( 'dreq_consol_tables_old_shelve_v%s' % vdate, 'r' )
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 = {}
45for ee,shv in [(ee0,sh),(eenv,shnv),(eeold,shold)]:
46  for k in shv.keys():
47    ee[k] = shv[k]
48
49for ee,fn in [(ee_xref,'vlsc5_xref_v20150713.xls'),(ee_mip,'vlsc5_mip_v20150713.xls')]:
50  wb = workbook( fn )
51  sh = wb.book.sheet_by_name( 'Sheet1' )
52  for i in range(sh.nrows):
53    r = map( lambda x: string.strip(str(uniCleanFunc(x.value))), sh.row(i) )
54    ee[r[0]] = r
55
56k2m = []
57km = []
58for k in ee_xref.keys():
59  if eeold.has_key(k):
60    for k2 in ee_xref[k][1:]:
61      if k2 != '':
62        if ee_mip.has_key(k2):
63          ee_xref_bck[k2].append(k)
64        else:
65          k2m.append( (k2,k) )
66  else:
67    km.append(k)
68
69##
70## had bug here due to extension of ee_mip to include dimensions.
71##
72for k in ee_mip.keys():
73  tid = ee_mip[k][-2]
74  ee_miptables_old[tid].append(  ee_mip[k][0] )
75  ee_miptables_vars_old[tid].append(  ee_mip[k][-3] )
76  ee_ovars_old['%s.%s' % (tid,ee_mip[k][-3]) ].append(  k )
77
78for s in shlist:
79  s.close()
Note: See TracBrowser for help on using the repository browser.