source: CCCC/trunk/ceda_cc/config_c4.py @ 287

Subversion URL: http://proj.badc.rl.ac.uk/svn/exarch/CCCC/trunk/ceda_cc/config_c4.py@287
Revision 287, 25.4 KB checked in by mjuckes, 6 years ago (diff)

adjusted CCMI requirements; added '-v' and '--unitTest' args

Line 
1import string
2import utils_c4 as utils
3import os
4import os.path as op
5import shutil, collections
6from versionConfig import version, versionComment
7
8NT_project = collections.namedtuple( 'project', ['id','v'] )
9NT_fnParts = collections.namedtuple( 'fnParts', ['len','fxLen','unfLen','checkTLen','ixDomain','ixFreq'] )
10
11##############################################################################
12# Configure config-file paths
13#
14# All configuration directories, e.g. cmip5_vocabs, are looked for in a single
15# parent directory.  This is the "config" directory within the package unless
16# the environment variable CC_CONFIG_DIR is set.
17
18HERE = op.dirname(__file__)
19CC_CONFIG_DEFAULT_DIR = op.join(HERE, 'config')
20CC_CONFIG_DIR = os.environ.get('CC_CONFIG_DIR', CC_CONFIG_DEFAULT_DIR)
21
22##############################################################################
23
24validCmip5Experiments = ['1pctCO2', 'abrupt4xCO2', 'amip', 'amip4K', 'amip4xCO2', 'amipFuture', 'aqua4K', 'aqua4xCO2', 'aquaControl', 'decadal1959', 'decadal1960', 'decadal1961', 'decadal1962', 'decadal1963', 'decadal1964', 'decadal1965', 'decadal1966', 'decadal1967', 'decadal1968', 'decadal1969', 'decadal1970', 'decadal1971', 'decadal1972', 'decadal1973', 'decadal1974', 'decadal1975', 'decadal1976', 'decadal1977', 'decadal1978', 'decadal1979', 'decadal1980', 'decadal1981', 'decadal1982', 'decadal1983', 'decadal1984', 'decadal1985', 'decadal1986', 'decadal1987', 'decadal1988', 'decadal1989', 'decadal1990', 'decadal1991', 'decadal1992', 'decadal1993', 'decadal1994', 'decadal1995', 'decadal1996', 'decadal1997', 'decadal1998', 'decadal1999', 'decadal2000', 'decadal2001', 'decadal2002', 'decadal2003', 'decadal2004', 'decadal2005', 'decadal2006', 'decadal2007', 'decadal2008', 'decadal2009', 'decadal2010', 'decadal2011', 'decadal2012', 'esmControl', 'esmFdbk1', 'esmFdbk2', 'esmFixClim1', 'esmFixClim2', 'esmHistorical', 'esmrcp85', 'historical', 'historicalExt', 'historicalGHG', 'historicalMisc', 'historicalNat', 'lgm', 'midHolocene', 'noVolc1960', 'noVolc1965', 'noVolc1970', 'noVolc1975', 'noVolc1980', 'noVolc1985', 'noVolc1990', 'noVolc1995', 'noVolc2000', 'noVolc2005', 'past1000', 'piControl', 'rcp26', 'rcp45', 'rcp60', 'rcp85', 'sst2020', 'sst2030', 'sst2090', 'sst2090rcp45', 'sstClim', 'sstClim4xCO2', 'sstClimAerosol', 'sstClimSulfate', 'volcIn2010']
25
26validCordexExperiment = validCmip5Experiments + ['evaluation']
27
28
29validCmip5Frequencies = ['fx','yr','monClim','mon','day','6hr','3hr','subhr']
30validCordexFrequencies = ['fx','sem','mon','day','6hr','3hr']
31validSpecsFrequencies = ['fx','mon','day','6hr']
32validCcmiFrequencies = ['fx','yr','mon','day','hr','subhr']
33validSpecsExptFamilies = map( lambda x: string.strip( x ), 
34                              open( op.join(CC_CONFIG_DIR, 'specs_vocabs/exptFamily.txt' )).readlines() )
35
36validCordexDomainsL = [ 'SAM-44', 'CAM-44', 'NAM-44', 'EUR-44', 'AFR-44', 'WAS-44', 'EAS-44', 'CAS-44', 'AUS-44', 'ANT-44', 'ARC-44', 'MED-44']
37validCordexDomainsLi = map( lambda x: x + 'i', validCordexDomainsL )
38validCordexDomainsH = ['EUR-11']
39validCordexDomains = validCordexDomainsL + validCordexDomainsLi + validCordexDomainsH
40
41plevRequired = ['clh', 'clm', 'cll', 'ua850', 'va850', 'ta850', 'hus850', 'ua500', 'va500', 'ta500', 'zg500', 'ua200', 'va200', 'ta200', 'zg200']
42plevBndsRequired = ['clh', 'clm', 'cll']
43heightRequired = ['tas','tasmax','tasmin','huss','sfcWind','sfcWindmax','wsgsmax','uas','vas']
44
45
46ii = open( op.join(CC_CONFIG_DIR, 'cordex_vocabs/GCMModelName.txt' )).readlines()
47validGcmNames = []
48for l in ii:
49  if l[0] != '#' and len( string.strip(l) ) > 0:
50    validGcmNames.append( string.split(l)[0] )
51
52ii = open( op.join(CC_CONFIG_DIR, 'cordex_vocabs/RCMModelName.txt' )).readlines()
53validRcmNames = []
54validInstNames = []
55for l in ii:
56  if l[0] != '#' and len( string.strip(l) ) > 0:
57    bits = string.split(l)
58    validRcmNames.append( bits[0] )
59    validInstNames.append( bits[1] )
60
61plevValues = {'clh':22000, 'clm':56000, 'cll':84000}
62for i in [200,500,850]:
63  for v in ['zg','ua', 'va', 'ta', 'hus']:
64    k = '%s%s' % (v,i)
65    plevValues[k] = i*100
66
67heightRequired = ['tas', 'tasmax', 'tasmin', 'huss', 'sfcWind', 'sfcWindmax', 'wsgsmax', 'uas', 'vas']
68heightValues = {}
69heightRange = {}
70for v in heightRequired:
71  if v in ['tas', 'tasmax', 'tasmin', 'huss']:
72    heightValues[v] = 2
73  else:
74    heightValues[v] = 10
75  heightRange[v] = (1.5,10.)
76
77ii = open( op.join(CC_CONFIG_DIR, 'cordex_vocabs/cordex_domains.csv' )).readlines()
78keys = ['name','tag','res','grid_np_lon','grid_np_lat','nlon','nlat','w','e','s','n']
79rotatedPoleGrids = {}
80for l in ii[2:16]:
81  bits = string.split(string.strip(l),',')
82  ee = {}
83  i = 0
84  for k in keys:
85    if k in ['nlon','nlat']:
86      ee[k] = int(bits[i])
87    elif k in ['grid_np_lon','grid_np_lat','w','e','s','n','res']:
88      if bits[i] != 'N/A':
89        ee[k] = float(bits[i])
90      else:
91        ee[k] = bits[i]
92    else:
93      ee[k] = bits[i]
94    i += 1
95    rotatedPoleGrids[bits[1]] = ee
96
97##Area,Name, deg,Nlon,Nlat,West8,East8,South8,North8,
98keys = ['name','tag','res','nlon','nlat','w','e','s','n']
99interpolatedGrids = {}
100for l in ii[18:33]:
101  bits = string.split(string.strip(l),',')
102  ee = {}
103  i = 0
104  for k in keys:
105    if k in ['nlon','nlat']:
106      ee[k] = int(bits[i])
107    elif k in ['w','e','s','n','res']:
108        ee[k] = float(bits[i])
109    else:
110      ee[k] = bits[i]
111    i += 1
112    interpolatedGrids[bits[1]] = ee
113
114class readVocab(object):
115
116  def __init__(self,dir):
117    self.dir = dir
118
119  def getSimpleList(self,file,bit=None,omt=None,options=None):
120    ii = open('%s/%s/%s' % (CC_CONFIG_DIR, self.dir,file) )
121    oo = []
122    if options == 'returnMappings':
123      assert bit == -1, 'only support returnMappings for bit == -1'
124      ee = {}
125
126   
127    for l in ii.readlines():
128      if l[0] != '#':
129        ll = string.strip(l)
130        if omt == 'last':
131          oo.append(string.join(string.split(ll)[:-1]))
132        elif bit == None:
133          oo.append(ll)
134        else:
135          if options == 'returnMappings':
136            bb = string.split(ll)
137            ee[bb[-1]] = string.join( bb[:-1] )
138            oo.append( bb[-1] )
139          else:
140            oo.append(string.split(ll)[bit])
141    if options == 'returnMappings':
142      return oo, ee
143    else:
144      return oo
145
146validSpecsInstitutions = ['IC3', 'MPI-M', 'KNMI', 'UOXF', 'CNRM-CERFACS', 'ENEA', 'MOHC', 'SMHI', 'IPSL', 'UREAD', 'ECWMF']
147
148class projectConfig(object):
149
150  def __init__(self, project, version=-1):
151    knownProjects = ['CMIP5','CCMI','CORDEX','SPECS','ESA-CCI', '__dummy']
152    assert project in knownProjects, 'Project %s not in knownProjects %s' % (project, str(knownProjects))
153
154    self.project = project
155    self.fNameSep = '_'
156    self.varIndex = 0
157    self.fnvdict = None
158    self.varTables='CMIP'
159    self.checkVarType = True
160    self.projectV = NT_project(project,version)
161    self.gridSpecTol = 0.01
162## default encoding of time range in file names: YYYY[MM[DD[HH]]]-YYYY[MM[DD[HH]]]
163    self.trangeType = 'CMIP'
164    self.controlledFnParts = []
165    if project == 'CORDEX':
166      self.requiredGlobalAttributes = [ 'institute_id', 'contact', 'rcm_version_id', 'product', 'CORDEX_domain', 'creation_date', \
167             'frequency', 'model_id', 'driving_model_id', 'driving_experiment', 'driving_model_ensemble_member', 'experiment_id']
168      self.controlledGlobalAttributes = ['frequency', 'driving_experiment_name', 'project_id', 'CORDEX_domain', 'driving_model_id', 'model_id', 'institute_id','driving_model_ensemble_member','rcm_version_id']
169      self.globalAttributesInFn = [None,'CORDEX_domain','driving_model_id','experiment_id','driving_model_ensemble_member','model_id','rcm_version_id']
170      self.requiredVarAttributes = ['long_name', 'standard_name', 'units']
171      self.drsMappings = {'variable':'@var','institute':'institute_id', 'product':'product', 'experiment':'experiment_id', \
172                        'ensemble':'driving_model_ensemble_member', 'model':'model_id', 'driving_model':'driving_model_id', \
173                        'frequency':'frequency', \
174                        'project':'project_id', 'domain':'CORDEX_domain', 'model_version':'rcm_version_id' }
175
176    elif project == 'SPECS':
177      lrdr = readVocab( 'specs_vocabs/')
178      self.requiredGlobalAttributes = lrdr.getSimpleList( 'globalAts.txt' )
179      self.exptFamilies = lrdr.getSimpleList( 'exptFamily.txt', bit=0 )
180      self.controlledGlobalAttributes = [ 'project_id','experiment_id', 'frequency','Conventions','modeling_realm', \
181                       'initialization_method','physics_version','realization']
182      self.globalAttributesInFn = [None,'@mip_id','model_id','experiment_id','startdate','@ensemble']
183#sic_Oimon_EC-Earth2_seaIceBestInit_S19910501_r1i1p1_199501-199502.nc
184## mip_id derived from global attribute Table_id (CMOR convention); ensemble derived from rip attributes.
185      self.requiredVarAttributes = ['long_name', 'standard_name', 'units']
186      self.drsMappings = {'variable':'@var', 'institute':'institute_id', 'product':'product', 'experiment':'experiment_id', \
187                        'ensemble':'@ensemble', 'model':'model_id', 'realm':'modeling_realm', \
188                        'frequency':'frequency', 'start_date':'@forecast_reference_time', \
189                        'table':'@mip_id',
190                        'project':'project_id'}
191
192    elif project == 'CMIP5':
193      lrdr = readVocab( 'cmip5_vocabs/')
194      self.requiredGlobalAttributes = [ 'contact', 'product', 'creation_date', 'tracking_id', \
195              'experiment_id']
196      ##self.requiredGlobalAttributes = lrdr.getSimpleList( 'globalAts.txt' )
197      self.controlledGlobalAttributes = [ 'project_id','experiment_id', 'frequency','Conventions','modeling_realm', \
198                       'initialization_method','physics_version','realization']
199      self.globalAttributesInFn = [None,'@mip_id','model_id','experiment_id','@ensemble']
200#sic_Oimon_EC-Earth2_seaIceBestInit_S19910501_series1_r1i1p1_199501-199502.nc
201## mip_id derived from global attribute Table_id (CMOR convention); experiment family derived from experiment_id, ensemble derived from rip attributes.
202      self.requiredVarAttributes = ['long_name', 'standard_name', 'units']
203## key: DRS element name, value: global attribute name or tag for mapping from file information ("@....").
204      self.drsMappings = {'variable':'@var', 'institute':'institute_id', 'product':'product', 'experiment':'experiment_id', \
205                        'ensemble':'@ensemble', 'model':'model_id', 'realm':'modeling_realm', \
206                        'frequency':'frequency',  'table':'@mip_id',
207                        'project':'project_id'}
208
209    elif project == 'CCMI':
210      lrdr = readVocab( 'ccmi_vocabs/')
211      self.requiredGlobalAttributes = [ 'creation_date', 'tracking_id', 'forcing', 'model_id', 'parent_experiment_id', 'parent_experiment_rip', 'branch_time', 'contact', 'institute_id' ]
212      self.requiredGlobalAttributes = lrdr.getSimpleList( 'globalAts.txt', bit=0 )
213      self.controlledGlobalAttributes = [ 'experiment_id', 'project', 'frequency' ]
214      self.globalAttributesInFn = [None,'@mip_id','model_id','experiment_id','@ensemble']
215      self.requiredVarAttributes = ['long_name', 'units']
216      self.drsMappings = {'variable':'@var', 'institute':'institute_id', 'product':'product', 'experiment':'experiment_id', \
217                        'ensemble':'@ensemble', 'model':'model_id', 'realm':'modeling_realm', \
218                        'frequency':'frequency',  'table':'@mip_id',
219                        'project':'project_id'}
220
221    elif project == 'ESA-CCI':
222      lrdr = readVocab( 'esacci_vocabs/')
223      self.varTables='FLAT'
224      self.fNameSep = '-'
225      self.checkVarType = False
226      self.requiredGlobalAttributes = lrdr.getSimpleList( 'requiredGlobalAts.txt', bit=0 )
227      self.controlledGlobalAttributes = ['platform','sensor','project','Conventions','institution','cdm_data_type','time_coverage_duration','spatial_resolution' ]
228      self.controlledFnParts = ['level','cciProject','var','version']
229      self.requiredVarAttributes = ['long_name', 'standard_name', 'units']
230      self.drsMappings = {'variable':'#var','platform':'platform','sensor':'sensor','level':'#level', \
231                'standard_name':'*standard_name', \
232                'algorithm':'$algorithm:unset', 'frequency':'$frequency', \
233                'spatial_resolution':'spatial_resolution', 'ecv':'@ecv','version':'#version','convention_version':'#gdsv'}
234      self.globalAttributesInFn = [None,]
235    elif project == '__dummy':
236      self.requiredGlobalAttributes = map( lambda x: 'ga%s' % x, range(10) )
237      self.controlledGlobalAttributes = [ ]
238      self.globalAttributesInFn = [None,'ga2', 'ga3', 'ga4' ]
239      self.requiredVarAttributes = ['long_name', 'standard_name', 'units']
240      self.drsMappings = {'variable':'@var'}
241
242####### used in checkStandardDims
243
244    self.plevRequired = plevRequired
245    self.plevValues = plevValues
246    self.heightRequired = heightRequired
247    self.heightValues = heightValues
248    self.heightRange = heightRange
249
250####### used in checkGrids
251    self.rotatedPoleGrids = rotatedPoleGrids
252    self.interpolatedGrids = interpolatedGrids
253    self.doCheckGrids = self.projectV.id in ['CORDEX',]
254
255####### used in checkFileName (freqIndex also used in checkByVar)
256
257    if self.projectV.id == 'CORDEX':
258      self.fnParts = NT_fnParts( len=[8,9], fxLen=[8,],  unfLen=[9,], checkTLen=True, ixDomain=1, ixFreq=7 )
259    ##  self.fnPartsOkLen = [5,6]
260      ##self.fnPartsOkFixedLen = [5,]
261      ##self.fnPartsOkUnfixedLen = [6,]
262      ##self.checkTrangeLen = True
263      ##self.domainIndex = 1
264      ##self.freqIndex = 7
265    elif self.projectV.id == 'CMIP5':
266      self.fnParts = NT_fnParts( len=[5,6], fxLen=[5,],  unfLen=[6,], checkTLen=False, ixDomain=None, ixFreq=None )
267      ##self.fnPartsOkLen = [5,6]
268      ##self.fnPartsOkFixedLen = [5,]
269      ##self.fnPartsOkUnfixedLen = [6,]
270      ##self.checkTrangeLen = False
271      ##self.domainIndex = None
272      ##self.freqIndex = None
273    elif self.projectV.id == 'SPECS':
274      self.fnParts = NT_fnParts( len=[6,7], fxLen=[6,],  unfLen=[7,], checkTLen=False, ixDomain=None, ixFreq=1 )
275      ##self.fnPartsOkLen = [6,7]
276      ##self.fnPartsOkFixedLen = [6,]
277      ##self.fnPartsOkUnfixedLen = [7,]
278      ##self.checkTrangeLen = False
279      ##self.domainIndex = None
280      ##self.freqIndex = 1
281    elif self.projectV.id == 'CCMI':
282      self.fnParts = NT_fnParts( len=[5,6], fxLen=[5,],  unfLen=[6,], checkTLen=False, ixDomain=None, ixFreq=None )
283      ##self.fnPartsOkLen = [5,6]
284      ##self.fnPartsOkFixedLen = [5,]
285      ##self.fnPartsOkUnfixedLen = [6,]
286      ##self.checkTrangeLen = False
287      ##self.domainIndex = None
288      ##self.freqIndex = None
289    elif self.projectV.id == 'ESA-CCI':
290      self.fnParts = NT_fnParts( len=[7,8,9], fxLen=[0,],  unfLen=[7,8,9,], checkTLen=False, ixDomain=None, ixFreq=1 )
291      self.trangeType = 'ESA-CCI'
292    elif self.projectV.id == '__dummy':
293      self.fnParts = NT_fnParts( len=[4,5], fxLen=[4,],  unfLen=[5,], checkTLen=False, ixDomain=None, ixFreq=1 )
294
295    self.fnPartsOkLen = self.fnParts.len
296    self.fnPartsOkFixedLen = self.fnParts.fxLen
297    self.fnPartsOkUnfixedLen = self.fnParts.unfLen
298    self.checkTrangeLen = self.fnParts.checkTLen
299    self.domainIndex = self.fnParts.ixDomain
300    self.freqIndex = self.fnParts.ixFreq
301
302
303    self.defaults = { 'variableDataType':'float' }
304######## used in mipVocabs
305    if self.projectV.id == 'CORDEX':
306       self.mipVocabDir = op.join(CC_CONFIG_DIR, 'cordex_vocabs/mip/')
307       self.mipVocabTl = ['fx','sem','mon','day','6h','3h']
308       self.mipVocabVgmap = {'6h':'6hr','3h':'3hr'}
309       self.mipVocabFnpat = 'CORDEX_%s'
310    elif self.projectV.id == 'CMIP5':
311       self.mipVocabDir = op.join(CC_CONFIG_DIR, 'cmip5_vocabs/mip/')
312       self.mipVocabTl = ['fx','Oyr','Oclim','Omon','Amon','Lmon','LImon','OImon','cfMon','aero','cfDay','day','cfOff','cfSites','6hrLev','6hrPlev','3hr','cf3hr']
313       self.mipVocabVgmap = {}
314       self.mipVocabFnpat = 'CMIP5_%s'
315       self.defaults['variableDataType'] = None 
316    elif self.projectV.id == 'SPECS':
317       self.mipVocabDir = op.join(CC_CONFIG_DIR, 'specs_vocabs/mip/')
318       self.mipVocabTl = ['fx','Omon','Amon','Lmon','OImon','day','6hr']
319       self.mipVocabVgmap = {}
320       self.mipVocabFnpat = 'SPECS_%s'
321    elif self.projectV.id == 'CCMI':
322       self.mipVocabDir = op.join(CC_CONFIG_DIR, 'ccmi_vocabs/mip/')
323       self.mipVocabTl = ['fixed','annual','monthly','daily','hourly']
324       self.mipVocabVgmap = {'fixed':'fx','annual':'yr','monthly':'mon','daily':'day','hourly':'hr'}
325       self.mipVocabFnpat = 'CCMI1_%s'
326    elif self.projectV.id == 'ESA-CCI':
327       self.mipVocabDir = op.join(CC_CONFIG_DIR, 'esacci_vocabs/')
328       self.mipVocabTl = []
329       self.mipVocabVgmap = 'ESACCI'
330       self.mipVocabFnpat = 'variableInFile.txt'
331    else:
332       self.mipVocabDir = None
333       self.mipVocabTl = ['day', 't2']
334       self.mipVocabVgmap = {}
335       self.mipVocabFnpat = None
336    self.mipVocabPars = [self.mipVocabDir, self.mipVocabTl, self.mipVocabVgmap, self.mipVocabFnpat]
337
338######## used in checkByVar
339    if self.project == 'CORDEX':
340      self.groupIndex = 7
341    elif self.project in ['CMIP5','CCMI','SPECS','__dummy']:
342      self.groupIndex = 1
343    elif self.project in ['ESA-CCI']:
344      self.fnvdict = { 'SSTskin':{'v':'sea_surface_temperature', 'sn':'sea_surface_skin_temperature'} }
345      self.fnoptions = {'groupIndex':[3,1], 'trangeIndex':[0,-2] }
346      self.fnoptions['inFn'] = [[None,'*activity','*level','*project','*var','*product','*additional','*gdsv','*version'],
347                                ['*activity','*project','*level','*var','*additional',None,'*version']]
348      self.fnoptions['varIndex'] = [4,3]
349##Indicative Date>[<Indicative Time>]-ESACCI-<Processing Level>_<CCI Project>-<Data Type>-<Product String>[- <Additional Segregator>][-v<GDS version>]-fv<File version>.nc
350##ESACCI-<CCI Project>-<Processing Level>-<Data Type>-<Product String>[-<Additional Segregator>]-<IndicativeDate>[<Indicative Time>]-fv<File version>.nc
351
352    self.trangeIndex = -1
353
354    self.getVocabs()
355    test = False
356    if test:
357      for k in self.vocabs['variable'].varcons.keys():
358        for k2 in self.vocabs['variable'].varcons[k].keys():
359          if "height2m" in self.vocabs['variable'].varcons[k][k2].get( '_dimension',[]):
360            print 'config_c4: %s , %s: %s' % (k,k2,str(self.vocabs['variable'].varcons[k][k2]['_dimension'] ) )
361
362    ##assert self.project != 'CCMI', 'Not completely set up for CCMI yet'
363
364  def getExtraAtts(self):
365
366    eafile = self.mipVocabDir + 'extraAtts.txt'
367    self.extraAtts = {}
368    if os.path.isfile( eafile ):
369      for l in open( eafile ).readlines():
370        if l[0] != '#':
371          bits = map( string.strip, string.split(l,',') )
372          id = '%s.%s' % (bits[0],bits[1])
373          ee = {}
374          for b in bits[2:]:
375            bb = string.split(b,'=')
376            ee[bb[0]] = bb[1]
377          self.extraAtts[id] = ee
378
379  def getVocabs(self):
380  ## "Returns a dictionary of vocabulary details for the project provided."
381    if self.projectV.id == 'SPECS':
382               ##'experiment_id':utils.patternControl( 'experiment_id', "(?P<val>.*)[0-9]{4}", list=validSpecsExptFamilies ), \
383      vocabs = { 'variable':utils.mipVocab(self), \
384               'Conventions':utils.listControl( 'Conventions', ['CF-1.6'] ), \
385               'frequency':utils.listControl( 'frequency', validSpecsFrequencies ), \
386               'experiment_id':utils.listControl( 'experiment_id', validSpecsExptFamilies ), \
387               'initialization_method':utils.patternControl( 'initialization_method', "[0-9]+" ), \
388               'physics_version':utils.patternControl( 'physics_version', "[0-9]+" ), \
389               'realization':utils.patternControl( 'realization', "[0-9]+" ), \
390               'startdate':utils.patternControl( 'startdate', "S[0-9]{8}" ), \
391               ## 'associated_experiment':utils.patternControl( 'associated_experment', "(?P<val>(N/A|(decadal|seasonal): r\*i[0-9]{1,4}p[0-9]{1,4}))" ), \
392               'project_id':utils.listControl( 'project_id', ['SPECS', 'NMME-SPECS'] ), \
393               ## 'institution':utils.listControl( 'institution', validSpecsInstitutions ), \
394               'modeling_realm':utils.listControl( 'realm', ['atmos', 'ocean', 'land', 'landIce', 'seaIce', 'aerosol', 'atmosChem', 'ocnBgchem'], split=True ), \
395             }
396    elif self.projectV.id == 'CMIP5':
397               ##'experiment_id':utils.patternControl( 'experiment_id', "(?P<val>.*)[0-9]{4}", list=validSpecsExptFamilies ), \
398      lrdr = readVocab( 'cmip5_vocabs/')
399      vocabs = { 'variable':utils.mipVocab(self), \
400               'Conventions':utils.listControl( 'Conventions', ['CF-1.4','CF-1.5'] ), \
401               'experiment_id':utils.listControl( 'experiment_id', lrdr.getSimpleList( 'experiments.txt' ) ), \
402               'frequency':utils.listControl( 'frequency', validCmip5Frequencies ), \
403               'initialization_method':utils.patternControl( 'initialization_method', "[0-9]+" ), \
404               'physics_version':utils.patternControl( 'physics_version', "[0-9]+" ), \
405               'realization':utils.patternControl( 'realization', "[0-9]+" ), \
406               'project_id':utils.listControl( 'project_id', ['CMIP5'] ), \
407               ## 'institution':utils.listControl( 'institution', validSpecsInstitutions ), \
408               'modeling_realm':utils.listControl( 'realm', ['atmos', 'ocean', 'land', 'landIce', 'seaIce', 'aerosol', 'atmosChem', 'ocnBgchem'], split=True ), \
409             }
410    elif self.projectV.id == 'CCMI':
411   
412      lrdr = readVocab( 'ccmi_vocabs/')
413      vocabs = { 'variable':utils.mipVocab(self), \
414               'frequency':utils.listControl( 'frequency', validCcmiFrequencies ), \
415               'experiment_id':utils.listControl( 'experiment_id', lrdr.getSimpleList( 'ccmi_experiments.txt', bit=-1 ) ), \
416## do not preserve or check relation between model and institution.
417               'institution':utils.listControl( 'institution', lrdr.getSimpleList( 'models_insts.txt', bit=1 ) ), \
418               'model_id':utils.listControl( 'model_id', lrdr.getSimpleList( 'models_insts.txt', bit=0 ) ), \
419               'modeling_realm':utils.listControl( 'realm', ['atmos', 'ocean', 'land', 'landIce', 'seaIce', 'aerosol', 'atmosChem', 'ocnBgchem'] ), \
420               'project_id':utils.listControl( 'project_id', ['CCMI'] ) }
421
422    elif self.projectV.id == 'ESA-CCI':
423      lrdr = readVocab( 'esacci_vocabs/')
424      cciProjectList, self.ecvMappings = lrdr.getSimpleList( 'cciProject.txt', bit=-1, options='returnMappings' )
425      vocabs = { 'variable':utils.mipVocab(self), \
426               'version':utils.patternControl( 'version',  '^(fv[0-9]+(\.[0-9]+){0,1})$', examples=['fv1.1'] ), \
427               'level':utils.listControl( 'level', lrdr.getSimpleList( 'procLevel01.txt', bit=0 ) ), \
428               'platform':utils.listControl( 'platforms', lrdr.getSimpleList( 'platforms.txt', bit=0), enumeration=True, split=True, splitVal=',' ), \
429               'institution':utils.listControl( 'institution', lrdr.getSimpleList( 'institutions.txt', omt='last' ) ), \
430               'Conventions':utils.patternControl( 'Conventions', '^CF-1.[56789](,.*){0,1}$', examples=['CF-1.6'] ), \
431               'sensor':utils.listControl( 'sensors', lrdr.getSimpleList( 'sensors.txt', bit=0 ) ), \
432               'cdm_data_type':utils.listControl( 'cdm_data_type', lrdr.getSimpleList( 'threddsDataType.txt', bit=0 ) ), \
433               'time_coverage_duration':utils.patternControl( 'time_coverage_duration',  'ISO8601 duration', cls='ISO',examples=['P1Y'] ), \
434               'spatial_resolution':utils.patternControl( 'spatial_resolution',  '([0-9]+(.[0-9]+){0,1})[\s]*(km|m).*', examples=['20km','1 km at nadir'] ), \
435               'project':utils.listControl( 'project', ['Climate Change Initiative - European Space Agency'] ), \
436               'cciProject':utils.listControl( 'cciproject', cciProjectList ), \
437               'var':utils.listControl( 'var', lrdr.getSimpleList( 'variables.txt', bit=-1 ) ) \
438             }
439    elif self.projectV.id == '__dummy':
440      vocabs = { 'variable':utils.mipVocab(self,dummy=True) }
441    else:
442      vocabs = { 'variable':utils.mipVocab(self), \
443           'driving_experiment_name':utils.listControl( 'driving_experiment_name', validCordexExperiment ), \
444           'project_id':utils.listControl( 'project_id', ['CORDEX'] ), \
445           'CORDEX_domain':utils.listControl( 'CORDEX_domain',  validCordexDomains ), \
446           'driving_model_id':utils.listControl( 'driving_model_id',  validGcmNames ), \
447           'driving_model_ensemble_member':utils.patternControl( 'driving_model_ensemble_member',  'r[0-9]+i[0-9]+p[0-9]+' ), \
448           'rcm_version_id':utils.patternControl( 'rcm_version_id',  '[a-zA-Z0-9-]+' ), \
449           'model_id':utils.listControl( 'model_id',  validRcmNames ), \
450           'institute_id':utils.listControl( 'institute_id',  validInstNames ), \
451           'frequency':utils.listControl( 'frequency', validCordexFrequencies ) }
452
453    self.vocabs = vocabs
454
455
456  def setEsaCciFNType(self,id):
457      self.groupIndex =  self.fnoptions['groupIndex'][id]
458      self.trangeIndex = self.fnoptions['trangeIndex'][id]
459      self.globalAttributesInFn = self.fnoptions['inFn'][id]
460      self.varIndex = self.fnoptions['varIndex'][id]
461
462
463def copy_config(dest_dir):
464   """
465   Copy the current default configuration directory into a separate directory.
466
467   The directory <ceda_cc-package-dir>/config is copied to `dest_dir`.
468   This is useful when ceda-cc is installed as a Python package and the user may
469   not know where the config directory is stored.
470
471   :param dest_dir: should be a path to a directory which does not yet exist. 
472       The configuration directory will be copied to this path.
473
474   """
475   shutil.copytree(CC_CONFIG_DEFAULT_DIR, dest_dir)
Note: See TracBrowser for help on using the repository browser.