Changeset 295 for CCCC


Ignore:
Timestamp:
06/02/15 14:29:53 (5 years ago)
Author:
mjuckes
Message:

streamline vocab management in configuration

Location:
CCCC/trunk/ceda_cc
Files:
5 added
1 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/ceda_cc/config_c4.py

    r292 r295  
    124124      print 'readVocab.driver: option %s not recgnised' % tt[0] 
    125125 
     126  def getEvalAssign(self, file ): 
     127    ii = open('%s/%s/%s' % (CC_CONFIG_DIR, self.dir,file) ) 
     128    ll = [] 
     129    for l in ii.readlines(): 
     130      if l[0] != '#': 
     131        ll.append( l ) 
     132    assert len(ll) == 1, 'Too many lines in %s' % file  
     133    try: 
     134      return eval( ll[0] ) 
     135    except: 
     136      print 'Failed to evaluate configuration line from %s:\n%s' % (file,l[0]) 
     137      raise 
     138 
    126139  def getSimpleList(self,file,bit=None,omt=None,options=None): 
    127140    ii = open('%s/%s/%s' % (CC_CONFIG_DIR, self.dir,file) ) 
    128141    oo = [] 
    129     if options == 'returnMappings': 
    130       assert bit == -1, 'only support returnMappings for bit == -1' 
     142    if options == None: 
     143      olist = [] 
     144    else: 
     145      olist = string.split(options,',') 
     146 
     147    if 'returnMappings' in olist: 
     148      assert bit in [0, -1], 'only support returnMappings for bit = -1 or 0' 
    131149      ee = {} 
    132150 
     
    139157          oo.append(ll) 
    140158        else: 
    141           if options == 'returnMappings': 
     159          if 'returnMappings' in olist: 
    142160            bb = string.split(ll) 
    143             ee[bb[-1]] = string.join( bb[:-1] ) 
    144             oo.append( bb[-1] ) 
     161            if bit == -1: 
     162              ee[bb[-1]] = string.join( bb[:-1] ) 
     163            else: 
     164              ee[bb[0]] = string.join( bb[1:] ) 
     165            oo.append( bb[bit] ) 
    145166          else: 
    146167            oo.append(string.split(ll)[bit]) 
    147168 
    148     if options == 'returnMappings': 
     169    if 'noneMap' in olist: 
     170      oo = map( lambda x: {'None':None}.get(x,x), oo ) 
     171 
     172    if 'returnMappings' in olist: 
    149173      return oo, ee 
    150174    else: 
     
    183207    elif project == 'SPECS': 
    184208      lrdr = readVocab( 'specs_vocabs/') 
    185       ##self.requiredGlobalAttributes = lrdr.getSimpleList( 'globalAts.txt' ) 
    186209      self.requiredGlobalAttributes = lrdr.driver( ('simpleList', 'globalAts.txt' ) ) 
    187       self.exptFamilies = lrdr.getSimpleList( 'exptFamily.txt', bit=0 ) 
    188       self.controlledGlobalAttributes = [ 'project_id','experiment_id', 'frequency','Conventions','modeling_realm', \ 
    189                        'initialization_method','physics_version','realization'] 
    190       self.globalAttributesInFn = [None,'@mip_id','model_id','experiment_id','startdate','@ensemble'] 
    191 #sic_Oimon_EC-Earth2_seaIceBestInit_S19910501_r1i1p1_199501-199502.nc  
    192 ## mip_id derived from global attribute Table_id (CMOR convention); ensemble derived from rip attributes. 
     210      self.exptFamilies = lrdr.driver( ('simpleList', 'exptFamily.txt', 0 ) ) 
     211      self.controlledGlobalAttributes = lrdr.driver( ('simpleList', 'controlledGlobalAttributes_sv0101.txt' ) ) 
     212                       ##'initialization_method','physics_version','realization'] 
     213      self.globalAttributesInFn = lrdr.driver( ('simpleList', 'globalAttributesInFn_sv0101.txt',0,0,'noneMap' ) ) 
    193214      self.requiredVarAttributes = ['long_name', 'standard_name', 'units'] 
    194       self.drsMappings = {'variable':'@var', 'institute':'institute_id', 'product':'product', 'experiment':'experiment_id', \ 
    195                         'ensemble':'@ensemble', 'model':'model_id', 'realm':'modeling_realm', \ 
    196                         'frequency':'frequency', 'start_date':'@forecast_reference_time', \ 
    197                         'table':'@mip_id', 
    198                         'project':'project_id'} 
     215      oo, self.drsMappings = lrdr.driver( ('simpleList', 'drsMappings_sv0101.txt',0,0,'returnMappings' ) ) 
     216 
     217      ##self.drsMappings = {'variable':'@var', 'institute':'institute_id', 'product':'product', 'experiment':'experiment_id', \ 
     218                        ##'ensemble':'@ensemble', 'model':'model_id', 'realm':'modeling_realm', \ 
     219                        ##'frequency':'frequency', 'start_date':'@forecast_reference_time', \ 
     220                        ##'table':'@mip_id', 
     221                        ##'project':'project_id'} 
    199222 
    200223    elif project == 'CMIP5': 
     
    265288    if self.projectV.id == 'CORDEX': 
    266289      self.fnParts = NT_fnParts( len=[8,9], fxLen=[8,],  unfLen=[9,], checkTLen=True, ixDomain=1, ixFreq=7 ) 
    267     ##  self.fnPartsOkLen = [5,6] 
    268       ##self.fnPartsOkFixedLen = [5,] 
    269       ##self.fnPartsOkUnfixedLen = [6,] 
    270       ##self.checkTrangeLen = True 
    271       ##self.domainIndex = 1 
    272       ##self.freqIndex = 7 
    273290    elif self.projectV.id == 'CMIP5': 
    274291      self.fnParts = NT_fnParts( len=[5,6], fxLen=[5,],  unfLen=[6,], checkTLen=False, ixDomain=None, ixFreq=None ) 
    275       ##self.fnPartsOkLen = [5,6] 
    276       ##self.fnPartsOkFixedLen = [5,] 
    277       ##self.fnPartsOkUnfixedLen = [6,] 
    278       ##self.checkTrangeLen = False 
    279       ##self.domainIndex = None 
    280       ##self.freqIndex = None 
    281292    elif self.projectV.id == 'SPECS': 
    282       self.fnParts = NT_fnParts( len=[6,7], fxLen=[6,],  unfLen=[7,], checkTLen=False, ixDomain=None, ixFreq=1 ) 
    283       ##self.fnPartsOkLen = [6,7] 
    284       ##self.fnPartsOkFixedLen = [6,] 
    285       ##self.fnPartsOkUnfixedLen = [7,] 
    286       ##self.checkTrangeLen = False 
    287       ##self.domainIndex = None 
    288       ##self.freqIndex = 1 
     293      self.fnParts = lrdr.getEvalAssign( 'fnParts_sv0101.txt' ) 
     294     ## self.fnParts = NT_fnParts( len=[6,7], fxLen=[6,],  unfLen=[7,], checkTLen=False, ixDomain=None, ixFreq=1 ) 
     295      print self.fnParts 
     296       
    289297    elif self.projectV.id == 'CCMI': 
    290298      self.fnParts = NT_fnParts( len=[5,6], fxLen=[5,],  unfLen=[6,], checkTLen=False, ixDomain=None, ixFreq=None ) 
    291       ##self.fnPartsOkLen = [5,6] 
    292       ##self.fnPartsOkFixedLen = [5,] 
    293       ##self.fnPartsOkUnfixedLen = [6,] 
    294       ##self.checkTrangeLen = False 
    295       ##self.domainIndex = None 
    296       ##self.freqIndex = None 
    297299    elif self.projectV.id == 'ESA-CCI': 
    298300      self.fnParts = NT_fnParts( len=[7,8,9], fxLen=[0,],  unfLen=[7,8,9,], checkTLen=False, ixDomain=None, ixFreq=1 ) 
Note: See TracChangeset for help on using the changeset viewer.