Changeset 111


Ignore:
Timestamp:
12/01/14 18:26:14 (6 years ago)
Author:
mjuckes
Message:

more checks and unit tests implemented for SPECS

Location:
CCCC/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • CCCC/trunk/config_c4.py

    r110 r111  
    113113               'frequency':utils.listControl( 'frequency', validSpecsFrequecies ), \ 
    114114               'experiment_id':utils.patternControl( 'experiment_id', "(?P<val>.*)[0-9]{4}", list=validSpecsExptFamilies ), \ 
    115                'project_id':utils.listControl( 'project_id', ['CORDEX'] ), \ 
     115               'initialization_method':utils.patternControl( 'initialization_method', "[0-9]+" ), \ 
     116               'physics_version':utils.patternControl( 'physics_version', "[0-9]+" ), \ 
     117               'realization':utils.patternControl( 'realization', "[0-9]+" ), \ 
     118               'project_id':utils.listControl( 'project_id', ['SPECS'] ), \ 
     119               'modeling_realm':utils.listControl( 'realm', ['atmos', 'ocean', 'land', 'landIce', 'seaIce', 'aerosol', 'atmosChem', 'ocnBgchem'] ), \ 
     120               'series':utils.listControl( 'series', ['1','2'] ), \ 
    116121             } 
    117122  elif pcfg.project == 'CCMI': 
    118123    vocabs = { 'variable':utils.mipVocab(pcfg), \ 
    119                'project_id':utils.listControl( 'project_id', ['CORDEX'] ) } 
     124               'project_id':utils.listControl( 'project_id', ['CCMI'] ) } 
    120125  elif pcfg.project == '__dummy': 
    121126    vocabs = { 'variable':utils.mipVocab(pcfg,dummy=True) } 
     
    158163      self.requiredGlobalAttributes = lrdr.getSimpleList( 'globalAts.txt' ) 
    159164      self.exptFamilies = lrdr.getSimpleList( 'exptFamily.txt', bit=0 ) 
    160       self.controlledGlobalAttributes = [ ] 
    161       self.globalAttributesInFn = [None,'@mip_id','model_id','@experiment_family','series','@ensemble'] 
     165      self.controlledGlobalAttributes = [ 'project_id','experiment_id', 'series','frequency','Conventions','modeling_realm', \ 
     166                       'initialization_method','physics_version','realization'] 
     167      self.globalAttributesInFn = [None,'@mip_id','model_id','@experiment_family','@series','@ensemble'] 
    162168## mip_id derived from global attribute Table_id (CMOR convention); experiment family derived from experiment_id, ensemble derived from rip attributes. 
    163169      self.requiredVarAttributes = ['long_name', 'standard_name', 'units'] 
  • CCCC/trunk/specs_vocabs/globalAts.txt

    r88 r111  
    2121title 
    2222tracking_id 
     23series 
  • CCCC/trunk/unitTestsS1.py

    r110 r111  
    11 
    22 
    3 import logging, time 
     3import logging, time, string 
    44import utils_c4 
    55import config_c4 as config 
     
    7474  print 'OK -- detected bad file name: [%s] %s' % (module,fn) 
    7575 
    76 fn = 'zos_Omon_EC-EARTH_historical1980_series1_r1i1p1_1990-1990.nc' 
    77 testId = '#01.006' 
    78 ## switch to project = SPECS 
    79 c = utils_c4.checkFileName(parent=ps) 
    80 c.check( fn ) 
    81 if c.errorCount == 0: 
    82   print 'Passed [%s] %s: valid file name' % (module,fn) 
    83 else: 
    84   print 'Failed [%s] %s: valid file name' % (module,fn) 
    85  
    8676c = utils_c4.checkStandardDims(parent=p) 
    8777module = 'checkStandardDims' 
     
    154144else: 
    155145  print 'OK -- detected a bad grid' 
     146 
     147ii = open( 'specs_vocabs/globalAtsSample001.txt' ) 
     148fn = string.strip( ii.readline() ) 
     149res = string.strip( ii.readline() ) 
     150testId = '#04.001' 
     151## switch to project = SPECS 
     152c = utils_c4.checkFileName(parent=ps) 
     153c.check( fn ) 
     154if c.errorCount == 0: 
     155  print 'Passed [%s] %s: valid file name' % (module,fn) 
     156else: 
     157  print 'Failed [%s] %s: valid file name' % (module,fn) 
     158 
     159 
     160## note test is done on string'ed values. 
     161ga = {} 
     162for l in ii.readlines(): 
     163  bits = string.split( string.strip(l) ) 
     164  if bits[1] == '@int': 
     165    ga[bits[0]] = int( bits[2] ) 
     166  else: 
     167    ga[bits[0]] = string.join( bits[1:] ) 
     168 
     169va = { "tas":{ "_type":"float32", "standard_name":"air_temperature", 'long_name':'Air Temperature', 'units':'K', 'cell_methods':'time: mean'} } 
     170 
     171cga = utils_c4.checkGlobalAttributes( parent=ps,cls='SPECS') 
     172cga.check( ga, va, "tas", "day", ps.pcfg.vocabs, c.fnParts ) 
     173 
     174ii = open( 'specs_vocabs/globalAtsSample002.txt' ) 
     175fn = string.strip( ii.readline() ) 
     176res = string.strip( ii.readline() ) 
     177testId = '#04.002' 
     178## switch to project = SPECS 
     179c = utils_c4.checkFileName(parent=ps) 
     180c.check( fn ) 
     181if c.errorCount == 0: 
     182  print 'Passed [%s] %s: valid file name' % (module,fn) 
     183else: 
     184  print 'Failed [%s] %s: valid file name' % (module,fn) 
     185 
     186 
     187## note test is done on string'ed values. 
     188ga = {} 
     189for l in ii.readlines(): 
     190  bits = string.split( string.strip(l) ) 
     191  if bits[1] == '@int': 
     192    ga[bits[0]] = int( bits[2] ) 
     193  else: 
     194    ga[bits[0]] = string.join( bits[1:] ) 
     195 
     196va = { "tas":{ "_type":"float32", "standard_name":"air_temperature", 'long_name':'Air Temperature', 'units':'K', 'cell_methods':'time: mean'} } 
     197 
     198cga = utils_c4.checkGlobalAttributes( parent=ps,cls='SPECS') 
     199cga.check( ga, va, "tas", "day", ps.pcfg.vocabs, c.fnParts ) 
  • CCCC/trunk/utils_c4.py

    r110 r111  
    385385    for a in self.controlledGlobalAttributes: 
    386386       if not vocabs[a].check( str(globalAts[a]) ): 
    387           m.append( (a,globalAts[a]) ) 
     387          m.append( (a,globalAts[a],vocabs[a].note) ) 
    388388 
    389389    self.test( len(m)  == 0, 'Global attributes do not match constraints: %s' % str(m) ) 
     
    393393    for i in range(len(self.globalAttributesInFn)): 
    394394       if self.globalAttributesInFn[i] != None: 
     395         targVal = fnParts[i] 
    395396         if self.globalAttributesInFn[i][0] == "@": 
    396397           if self.globalAttributesInFn[i][1:] == "mip_id": 
    397              thisVal = string.split( globalAts["table_id"] )[1] 
     398               thisVal = string.split( globalAts["table_id"] )[1] 
    398399           elif self.globalAttributesInFn[i][1:] == "ensemble": 
    399              thisVal = "r%si%sp%s" % (globalAts["realization"],globalAts["initialization_method"],globalAts["physics_version"]) 
     400               thisVal = "r%si%sp%s" % (globalAts["realization"],globalAts["initialization_method"],globalAts["physics_version"]) 
     401           elif self.globalAttributesInFn[i][1:] == "series": 
     402               thisVal = 'series%s' % globalAts["series"] 
    400403           elif self.globalAttributesInFn[i][1:] == "experiment_family": 
    401404             thisVal = globalAts["experiment_id"][:-4] 
    402            elif self.globalAttributesInFn[i][1:] == "series": 
    403              thisVal = 'series%s' % globalAts["series"] 
    404405           else: 
    405              assert False, "Not coded to deal with this configuration: globalAttributesInFn[%s]=%s" % (i,self.globalAttributesInFn[i]) 
     406               assert False, "Not coded to deal with this configuration: globalAttributesInFn[%s]=%s" % (i,self.globalAttributesInFn[i]) 
     407           ##print "Generated text val: %s:: %s" % (self.globalAttributesInFn[i], thisVal) 
    406408          
    407409         else: 
    408            thisVal = globalAts[self.globalAttributesInFn[i]] 
    409  
    410          if thisVal != fnParts[i]: 
     410             thisVal = globalAts[self.globalAttributesInFn[i]] 
     411 
     412         if thisVal != targVal: 
    411413             m.append( (i,self.globalAttributesInFn[i]) ) 
    412414 
     
    742744 
    743745  def check(self,val): 
     746    self.note = '-' 
    744747    m = self.re_pat.match( val ) 
    745748    if self.list == None: 
     749      self.note = "simple test" 
    746750      return m != None 
    747751    else: 
    748752      if m == None: 
     753        self.note = "no match" 
    749754        return False 
    750755      if not m.groupdict().has_key("val"): 
     756        self.note = "no 'val' in match" 
    751757        return False 
     758      self.note = "val=%s" % m.groupdict()["val"] 
    752759      return m.groupdict()["val"] in self.list 
    753760     
     
    758765 
    759766  def check(self,val): 
     767    self.note = '-' 
     768    if len(self.list) < 4: 
     769      self.note = str( self.list ) 
    760770    return val in self.list 
    761771 
Note: See TracChangeset for help on using the changeset viewer.