source: CMIP6dreqbuild/trunk/src/framework/ing02/freqMap.py @ 1081

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

add missing file

Line 
1
2import shelve, collections
3
4CV_freq = {
5        "1hr":"sampled hourly",
6        "1hrCM":"monthly climatology of diurnal cycle computed from hourly samples",
7        "1hrPt":"sampled hourly, at specified time point within an hour",
8        "3hr":"sampled every 3 hours",
9        "3hrPt":"sampled 3 hourly, at specified time point within the time period",
10        "6hr":"sampled every 6 hours",
11        "6hrPt":"sampled 6 hourly, at specified time point within the time period",
12        "day":"daily mean samples",
13        "dec":"decadal mean samples",
14        "fx":"fixed (time invariant) field",
15        "mon":"monthly mean samples",
16        "monPt":"monthly mean samples",
17        "monC":"monthly climatology computed from monthly mean samples",
18        "subhrPt":"sampled sub-hourly, at specified time point within an hour",
19        "yr":"annual mean samples",
20        "yrPt":"sampled yearly, at specified time point within the time period"
21    }
22
23class freqMap(object):
24  def __init__(self):
25    shst = shelve.open( 'exports/l1sh/structure', 'r' )
26    cols = shst['__cols__']
27    il = cols.index( 'label' )
28    ittl = cols.index( 'title' )
29    iu = cols.index( 'uid' )
30    ic = cols.index( 'cell_methods' )
31    cc = collections.defaultdict( list )
32    for k in shst.keys():
33      if k[0:2] != '__':
34        r = shst[k]
35        cm = r[ic]
36        if cm.find( 'time: point' ) != -1:
37          cc['point'].append( k )
38        elif cm.find( 'time' ) == -1:
39          cc['fx'].append( k )
40        else:
41          cc['other'].append( k )
42
43    if 'f7e790c0-562c-11e6-a2a4-ac72891c3257' not in cc['point']:
44      print 'SEVERE: f7e790c0-562c-11e6-a2a4-ac72891c3257, CellMethods::apt-tpt missing from point'
45    for k in cc['fx']:
46      print shst[k][il], shst[k][ittl]
47       
48    em1 = {'monClim':'monC',  '1hrClimMon':'1hrCM' }
49
50    sh = shelve.open( 'exports/l1sh/CMORvar', 'r' )
51    ne = 0
52    nc = 0
53    cols = sh['__cols__']
54    il = cols.index( 'label' )
55    iu = cols.index( 'uid' )
56    istr = cols.index( 'stid' )
57    ifrq = cols.index( 'frequency' )
58    cmv = {}
59    targ = {}
60    ns = 0
61    for k in sh.keys():
62      if k[0:2] != '__':
63        r = sh[k]
64        if r[ifrq] in em1:
65          targ[k] = em1[ r[ifrq] ]
66        elif r[istr] in cc['point']:
67          targ[k] = r[ifrq] + 'Pt'
68        elif r[ifrq] == 'subhr':
69          stid = str( r[istr])
70          if stid not in shst:
71            print 'ERROR.001: missing structure ref:',r[istr],r[ifrq],r[il]
72          else:
73            print 'WARN: subhr missed point ',r[istr],r[ifrq],r[il],shst[ str(r[istr]) ][ic]
74
75        if k != r[iu]:
76          print 'WARNING: k,iu mismatch: ',k,r[iu]
77
78        if k in targ:
79          this = targ[k]
80        else:
81          this = r[ifrq]
82        if this not in CV_freq:
83          print 'SEVERE: missing frequency: ',this,k,r[il]
84          ns += 1
85         
86    sh.close()
87    shst.close()
88    if ns == 0:
89      print 'MAPPING FREQUENCIES'
90      sh = shelve.open( 'exports/l1sh/CMORvar' )
91      ks = set( sh.keys() )
92      for k in targ:
93        assert k in ks, 'Target record not found: %s' % targ
94      for k in targ:
95        r = sh[k]
96        r[ifrq] = targ[k]
97        sh[k] = r[:]
98      sh.close()
99     
100       
101
102
103if __name__ == "__main__":
104  fm = freqMap()
105   
Note: See TracBrowser for help on using the repository browser.