source: CMIP6dreqbuild/trunk/srcMisc/sx2_extra.py @ 681

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

near release

Line 
1
2import collections, re
3
4
5l1 = [u'ISMIP6.new_LImon', u'PMIP.PMIP-LIclim', u'HighResMIP.6hrPlev_extr_dr', u'LUMIP.Lmon_Lut', u'FAFMIP.fafOyr', u'PMIP.PMIP-day', u'DynVar.DYVR_daily', u'C4MIP.C_LandT2', u'PMIP.PMIP-aeroclim', u'PMIP.PMIP-aero', u'C4MIP.C_LandT1', u'HighResMIP.1hrLev', u'PMIP.PMIP-Omon', 'C4MIP.L_day', u'FAFMIP.fafOmonB', u'CFMIP.cfDayExtra', u'CFMIP.cfDay_2d_new', u'PMIP.PMIP-Oclim', u'ISMIP6.new_Omon', u'ISMIP6.new_fx', u'CFMIP.aeroDay_2d', u'HighResMIP.Amon_ext', u'HighResMIP.1hr_energy', u'HighResMIP.day_jet', u'C4MIP.C_Hist', u'CFMIP.cfSites_new', u'PMIP.PMIP-Amon', u'HighResMIP.6hrPlev_intense', u'CFMIP.cfMonExtra', u'LS3MIP.LCmon', u'GeoMIP.aeroGeo', u'PMIP.PMIP-Lmon', u'HighResMIP.3hr_cloud', u'HighResMIP.1ts', u'ISMIP6.icesheetmon', u'HighResMIP.Amon_sparc', u'C4MIP.C_Ocean_T1', u'HighResMIP.Amon_conv', u'LUMIP.Lyr_Lut', u'HighResMIP.1hr_strat', u'HighResMIP.3hr_extr', u'PMIP.PMIP-Lclim', u'CFMIP.cf3hr_sim', u'FAFMIP.fafOmon', u'FAFMIP.fafOyrB', u'RFMIP.aero_irf', u'PMIP.PMIP-Aclim', u'LS3MIP.LWday', u'C4MIP.C_Basic', u'CFMIP.cfMon_3dstd_new', u'HighResMIP.3hrPlev', u'ISMIP6.icesheetyear', u'C4MIP.C_Ocean_T2', 'C4MIP.L_3hr', u'RFMIP.OfflineRad', u'VolMIP.VIRF', u'HighResMIP.6hrPlev_extr', u'PMIP.PMIP-OIclim', u'PMIP.PMIP-6hr', u'HighResMIP.Amon_diag', 'DynVar.DYVR_monthly', 'LS3MIP.LEday', 'DAMIP.new_monthly','DCPP.DCPP-day', u'DCPP.DCPP-6hr', 'DCPP.DCPP-mon', 'DynVar.DYVR_zg', 'SIMIP.seaicemon', 'SIMIP.seaiceday' ]
6
7l1p = [
8'DynVar.DYVR_daily_d',
9'DynVar.DYVR_daily_c',
10'DynVar.DYVR_daily_b',
11'DynVar.DYVR_daily_a',
12'DAMIP.DAMIP_6hrPlev_p2',
13'DAMIP.DAMIP_Amon_new',
14'DynVar.DYVR_monthly_d',
15'DynVar.DYVR_monthly_a',
16'DynVar.DYVR_monthly_c',
17'DynVar.DYVR_monthly_b',
18'DAMIP.DAMIP_day',
19'CFMIP.cf3hr_sim_new',
20'DAMIP.DAMIP_3hr_p2',
21'DAMIP.DAMIP_Omon_p2',
22'DAMIP.DAMIP_day_zm',
23'DAMIP.DAMIP_emMon',
24'CFMIP.cf1hrClimMon',
25'DAMIP.DAMIP_emMonZ',
26'DAMIP.DAMIP_aermonthly']
27
28l2p = [
29'DynVar-daily-d',
30'DynVar-daily-c',
31'DynVar-daily-b',
32'DynVar-daily-a',
33'DAMIP-6hrPlev-p2',
34'DAMIP-Amon-new',
35'DynVar-monthly-d',
36'DynVar-monthly-a',
37'DynVar-monthly-c',
38'DynVar-monthly-b',
39'DAMIP-day',
40'cf3hr-sim-new',
41'DAMIP-3hr-p2',
42'DAMIP-Omon-p2',
43'DAMIP-day-zm',
44'DAMIP-emMon',
45'cf1hrClimMon',
46'DAMIP-emMonZ',
47'DAMIP-aermonthly']
48
49l2 = [u'ISMIP6-LImon', u'PMIP-LIclim', u'HighResMIP-6hrPlevExtrDr', u'LUMIP-LmonLut', u'FAFMIP-fafOyr', u'PMIP-day', u'DynVar-day', u'C4MIP-LandT2', u'PMIP-aeroclim', u'PMIP-aero', u'C4MIP-LandT1', u'HighResMIP-1hrLev', u'PMIP-Omon', 'C4MIP-day', u'FAFMIP-OmonB', u'CFMIP-cfDayExtra', u'CFMIP-cfDay2dNew', u'PMIP-Oclim', u'ISMIP6-OmonNew', u'ISMIP6-fxNew', u'CFMIP-aeroDay2d', u'HighResMIP-AmonExt', u'HighResMIP-1hrEnergy', u'HighResMIP-dayJet', u'C4MIP-Hist', u'CFMIP-cfSitesNew', u'PMIP-Amon', u'HighResMIP-6hrPlevIntense', u'CFMIP-cfMonExtra', u'LS3MIP-LCmon', u'GeoMIP-aeroGeo', u'PMIP-Lmon', u'HighResMIP-3hrCloud', u'HighResMIP-1ts', u'ISMIP6-icesheetmon', u'HighResMIP-AmonSparc', u'C4MIP-OceanT1', u'HighResMIP-AmonConv', u'LUMIP-LyrLut', u'HighResMIP-1hrStrat', u'HighResMIP-3hrExtr', u'PMIP-Lclim', u'CFMIP-cf3hrSim', u'FAFMIP-Omon', u'FAFMIP-OyrB', u'RFMIP-aeroIrf', u'PMIP-Aclim', u'LS3MIP-LWday', u'C4MIP-Basic', u'CFMIP-cfMon3dstdNew', u'HighResMIP-3hrPlev', u'ISMIP6-icesheetyear', u'C4MIP-OceanT2', 'C4MIP-3hr', u'RFMIP-OfflineRad', u'VolMIP-VIRF', u'HighResMIP-6hrPlevExtr', u'PMIP-OIclim', u'PMIP-6hr', u'HighResMIP-AmonDiag', 'DynVar-mon', 'LS3MIP-LEday', 'DAMIP-newMonthly','DCPP-day', u'DCPP-6hr', 'DCPP-mon', 'DynVar-DYVRzg', 'SIMIP-seaicemon', 'SIMIP-seaiceday']
50
51l1 += l1p
52l2 += l2p
53
54r1 = re.compile( '^([a-zA-Z0-9-]*)$' )
55lf = []
56for i in l2:
57  if r1.match( i ) == None:
58    lf.append(i)
59
60assert len(lf) == 0,'Element(s) of l2 not matching constraint: %s' % str(lf)
61print 'INFO.001.0001: All elements of l2 checked against character constraint'
62
63assert len(l1) == len(l2), 'key and value lists (l1,l2) have different lengths: %s, %s' % (len(l1),len(l2))
64len1 = len(l1)
65
66class c1(object):
67  def __init__(self):
68    self.a = collections.defaultdict(int)
69lk1 = collections.defaultdict( c1 )
70lk2 = collections.defaultdict( c1 )
71for i in range(len1):
72  lk1[l2[i]].a[l1[i]] += 1
73  lk2[l1[i]].a[l2[i]] += 1
74
75k2 = lk2.keys()
76k2.sort()
77k1 = lk1.keys()
78k1.sort()
79ldup = []
80lmult = []
81for k in k1:
82  if len( lk1[k].a.keys() ) > 1:
83    ldup.append(k)
84  for kk in lk1[k].a.keys():
85    if lk1[k].a[kk] > 1:
86      lmult.append( (k,kk) )
87
88assert len(ldup) == 0, 'Ambiguous mappings in lk1: %s' % str(ldup)
89
90ldup = []
91lmult2 = []
92for k in k2:
93  if len( lk2[k].a.keys() ) > 1:
94    ldup.append(k)
95  for kk in lk2[k].a.keys():
96    if lk2[k].a[kk] > 1:
97      lmult2.append( (k,kk) )
98
99assert len(ldup) == 0, 'Ambiguous mappings in lk2: %s' % str(ldup)
100print 'INFO.001.0002: Checked for ambiguous mappings '
101
102assert len(lmult) == 0 and len(lmult2) == 0, 'Multiple mappings found: %s, %s' % (str(lmult),str(lmult2))
103
104class map(dict):
105  def __init__(self):
106    self.__inv__ = {}
107
108  def set(self,a,b):
109    self.__setitem__(a,b)
110    self.__inv__[b] = a
111
112  def inv(self,k):
113    return self.__inv__[k]
114
115ngmap = map()
116for k in k2:
117  ngmap.set( k, lk2[k].a.keys()[0] )
Note: See TracBrowser for help on using the repository browser.