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

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

adding python scripts

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']
6
7l2 = [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']
8
9r1 = re.compile( '^([a-zA-Z0-9-]*)$' )
10lf = []
11for i in l2:
12  if r1.match( i ) == None:
13    lf.append(i)
14
15assert len(lf) == 0,'Element(s) of l2 not matching constraint: %s' % str(lf)
16print 'INFO.001.0001: All elements of l2 checked against character constraint'
17
18assert len(l1) == len(l2), 'key and value lists (l1,l2) have different lengths: %s, %s' % (len(l1),len(l2))
19len1 = len(l1)
20
21class c1(object):
22  def __init__(self):
23    self.a = collections.defaultdict(int)
24lk1 = collections.defaultdict( c1 )
25lk2 = collections.defaultdict( c1 )
26for i in range(len1):
27  lk1[l2[i]].a[l1[i]] += 1
28  lk2[l1[i]].a[l2[i]] += 1
29
30k2 = lk2.keys()
31k2.sort()
32k1 = lk1.keys()
33k1.sort()
34ldup = []
35lmult = []
36for k in k1:
37  if len( lk1[k].a.keys() ) > 1:
38    ldup.append(k)
39  for kk in lk1[k].a.keys():
40    if lk1[k].a[kk] > 1:
41      lmult.append( (k,kk) )
42
43assert len(ldup) == 0, 'Ambiguous mappings in lk1: %s' % str(ldup)
44
45ldup = []
46lmult2 = []
47for k in k2:
48  if len( lk2[k].a.keys() ) > 1:
49    ldup.append(k)
50  for kk in lk2[k].a.keys():
51    if lk2[k].a[kk] > 1:
52      lmult2.append( (k,kk) )
53
54assert len(ldup) == 0, 'Ambiguous mappings in lk2: %s' % str(ldup)
55print 'INFO.001.0002: Checked for ambiguous mappings '
56
57assert len(lmult) == 0 and len(lmult2) == 0, 'Multiple mappings found: %s, %s' % (str(lmult),str(lmult2))
58
59class map(dict):
60  def __init__(self):
61    self.__inv__ = {}
62
63  def set(self,a,b):
64    self.__setitem__(a,b)
65    self.__inv__[b] = a
66
67  def inv(self,k):
68    return self.__inv__[k]
69
70ngmap = map()
71for k in k2:
72  ngmap.set( k, lk2[k].a.keys()[0] )
Note: See TracBrowser for help on using the repository browser.