Changeset 874 for cp4cds-tmp/simChk1.py


Ignore:
Timestamp:
23/11/16 12:18:27 (3 years ago)
Author:
mjuckes
Message:

updated to scan additional variables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cp4cds-tmp/simChk1.py

    r870 r874  
    88vars1 = [('Amon','tas'),('Amon','tasmin'),('Amon','tasmax'),('Amon','uas'),('Amon','vas'),('Amon','hurs'),('Amon','pr'),('Amon','ps')] 
    99vars1 = [('Amon','tas'),('Amon','tasmin'),('Amon','tasmax'),('Amon','uas'),('Amon','vas'),('Amon','pr'),('Amon','ps')] 
    10 spth = {'Amon':'mon/atmos/Amon/'} 
    1110 
     11spth = {'Amon':'mon/atmos/Amon/', 'day':'day/atmos/day/', 
     12        'Lmon':'mon/land/Lmon/', 
     13        'Omon':'mon/ocean/Omon/', 
     14        'OImon':'mon/seaIce/OImon/', 
     15        'LImon':'mon/landIce/LImon/' } 
     16 
     17mset1 = { 'info':'Selected by simChk1, based on availabiity of 7 vars in 3 experiments', 
     18          'models':[('MRI', 'MRI-CGCM3'), ('MOHC', 'HadGEM2-ES'), ('MIROC', 'MIROC-ESM'), ('CNRM-CERFACS', 'CNRM-CM5'), ('NOAA-GFDL', 'GFDL-ESM2G'), ('IPSL', 'IPSL-CM5B-LR'), ('CMCC', 'CMCC-CM'), ('NASA-GISS', 'GISS-E2-R-CC'), ('MIROC', 'MIROC5'), ('NASA-GISS', 'GISS-E2-H'), ('MPI-M', 'MPI-ESM-LR'), ('NASA-GISS', 'GISS-E2-R'), ('NOAA-GFDL', 'GFDL-ESM2M'), ('MOHC', 'HadGEM2-CC'), ('IPSL', 'IPSL-CM5A-LR'), ('CSIRO-BOM', 'ACCESS1-0'), ('MPI-M', 'MPI-ESM-MR'), ('IPSL', 'IPSL-CM5A-MR'), ('MIROC', 'MIROC4h'), ('CMCC', 'CMCC-CMS'), ('NCC', 'NorESM1-M'), ('BCC', 'bcc-csm1-1-m'), ('NOAA-GFDL', 'GFDL-CM3'), ('CSIRO-BOM', 'ACCESS1-3'), ('NASA-GISS', 'GISS-E2-H-CC'), ('BNU', 'BNU-ESM'), ('BCC', 'bcc-csm1-1'), ('MIROC', 'MIROC-ESM-CHEM'), ('INM', 'inmcm4')] 
     19         } 
     20 
     21class vtab(object): 
     22  def __init__(self,vars1,fn='CP4CDS_Projections-data-overview.csv'): 
     23    assert os.path.isfile(fn), '%s not found' % fn 
     24    self.vars1 = vars1 
     25    self.vars2 = [] 
     26    ii = open( fn, 'r' ) 
     27    for l in ii.readlines(): 
     28      if len(l) > 1 and l[0] != '#': 
     29        var, tab = l.split( '\t' )[:2] 
     30        assert tab in spth, 'Unrecignised table %s' % tab 
     31        if (tab,var) not in self.vars1: 
     32          self.vars2.append( (tab,var) ) 
    1233 
    1334class models(object): 
    14   def __init__(self, base): 
     35  def __init__(self, base, vars,force=False,mlist=None): 
    1536    assert os.path.isdir( base ), '%s not found' % base 
     37    self.vars = vars 
     38    self.force=force 
     39    self.mlist=mlist 
     40 
    1641    l10 = glob.glob( '%s/*' % base ) 
    1742    l1 = [i for i in l10 if os.path.isdir( i ) ] 
     
    2045    self.im = [] 
    2146 
    22     for i in sorted( l1 ): 
    23       self.addModels( i ) 
     47    if mlist == None: 
     48      for i in sorted( l1 ): 
     49        self.addModels( i ) 
     50    else: 
     51      self.im = mlist 
    2452 
    2553    si = set() 
     
    4169 
    4270  def filterModels(self,expts): 
    43     pths = set( [spth[t[0]] for t in vars1] ) 
     71    pths = set( [spth[t[0]] for t in self.vars] ) 
    4472    n0 = len(self.im) 
    4573    n1 = n2 = n3 = n4 = 0 
     
    6593    oo = open( 'fileList.txt', 'w' ) 
    6694    for e,i,m,rip in self.files: 
    67        if (i,m) in sok: 
     95       if (i,m) in sok or self.force: 
    6896         for f in self.files[ (e,i,m,rip) ]: 
    6997           oo.write( f + '\n' ) 
     
    87115        efl = [] 
    88116        missing = set() 
    89         for t,v in vars1: 
     117        for t,v in self.vars: 
    90118          p = spth[t] 
    91119          if os.path.isdir( '%s%s/%s/%s/%s/%s/latest/%s' % (base,inst,model,expt,p,e,v) ): 
     
    95123          else: 
    96124            missing.add( (t,v) ) 
    97         if len(missing) == 0: 
     125        if len(missing) == 0 or (self.force and len(efl) > 0): 
    98126          eok.add(e) 
    99127          self.files[ (expt,inst,model,e) ] = efl 
     
    103131        return len(eok) 
    104132           
    105  
    106 m = models(base) 
     133mode = 2 
     134if mode == 1: 
     135  m = models(base,vars1) 
     136else: 
     137  vv = vtab( vars1 ) 
     138  m = models(base,vv.vars2,force=True, mlist=mset1['models']) 
    107139 
    108140 
Note: See TracChangeset for help on using the changeset viewer.