source: CCCC/tags/0.1/extractMipInfo.py @ 158

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CCCC/tags/0.1/extractMipInfo.py@1241
Revision 158, 1.2 KB checked in by mjuckes, 6 years ago (diff)

add script to extract info from mip files -- effort to generate reference list of variables

Line 
1
2import collections, glob, string
3from fcc_utils2 import mipTableScan
4
5ms = mipTableScan()
6
7NT_mip = collections.namedtuple( 'mip',['label','dir','pattern'] )
8
9mips = ( NT_mip( 'cmip5','cmip5_vocabs/mip/', 'CMIP5_*' ), )
10
11cmip5_ignore = ['depth','depth_c','eta','nsigma','vertices_latitude','vertices_longitude','ztop','ptop','p0','z1','z2','href','k_c','a','a_bnds','ap','ap_bnds','b','b_bnds','sigma','sigma_bnds','zlev','zlev_bnds','zfull','zhalf']
12
13vl0 = []
14for mip in mips:
15  dl = glob.glob( '%s%s' % (mip.dir,mip.pattern) )
16  dl.sort()
17  tl = []
18  td = {}
19  for d in dl:
20    tab = string.split( d, '/')[-1]
21    l2 = ms.scan_table( open( d ).readlines(), None, asDict=True, lax=True, tag="x", warn=True)
22    l2k = []
23    for k in l2.keys():
24      if k not in cmip5_ignore:
25        l2k.append(k)
26    l2k.sort()
27    vl0 += l2k
28    tl.append( [tab,l2, l2k] )
29    td[tab] = l2
30
31vl0.sort()
32vl = []
33vl.append( vl0[0] )
34vdict = { vl[0]:[] }
35for v in vl0[1:]:
36  if v != vl[-1]:
37    vl.append(v)
38    vdict[v] = []
39
40for t in tl:
41  print t[0],t[2]
42  for k in t[2]:
43    vdict[k].append(t[0])
44
45vars = vdict.keys()
46vars.sort()
47for v in vars:
48  l = vdict[v]
49  l.sort()
50  print v, l, td[l[0]][v][1].get('standard_name','__NO_STANDARD_NAME__')
51
Note: See TracBrowser for help on using the repository browser.