Changeset 408 for CMIP6dreqbuild/trunk/src
- Timestamp:
- 13/10/15 11:53:22 (7 years ago)
- Location:
- CMIP6dreqbuild/trunk/src/framework
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
CMIP6dreqbuild/trunk/src/framework/Makefile
r393 r408 64 64 cp vocabDemo.py /data/tmp/svn3/exarch/CMIP6dreq/trunk/src 65 65 cp annotated_20150731.xml /data/tmp/svn3/exarch/CMIP6dreq/trunk/docs/dreq.xml 66 cp tables/test.xlsx /data/tmp/svn3/exarch/CMIP6dreq/trunk/docs/CMIP6_MIP_tables.xlsx 67 cp out/dc1.xsd out/xlink.xsd out/xml.xsd /data/tmp/svn3/exarch/CMIP6dreq/trunk/docs/ 66 68 echo "source copied to /data/tmp/svn3/exarch/CMIP6dreq/trunk/src" 67 69 -
CMIP6dreqbuild/trunk/src/framework/dreq.py
r397 r408 8 8 import xml.dom.minidom 9 9 import re, shelve 10 import sets11 10 12 11 class rechecks(object): … … 55 54 """Print a summary of the data held in the object as a list of key/value pairs""" 56 55 if self._contentInitialised: 57 print 'Item <%s>: [%s] %s' % (self._h.title,self.label,self.title)56 print ( 'Item <%s>: [%s] %s' % (self._h.title,self.label,self.title) ) 58 57 for a in self.__dict__.keys(): 59 58 if a[0] != '_' or full: 60 59 if self._a[a].rClass == 'internalLink' and self._base._indexInitialised: 61 targ = self._base._inx.uid[ self.__dict__[a] ] 62 print ' %s: [%s]%s [%s]' % ( a, targ._h.label, targ.label, self.__dict__[a] ) 60 if self.__dict__[a] in self._base._inx.uid: 61 targ = self._base._inx.uid[ self.__dict__[a] ] 62 print ( ' %s: [%s]%s [%s]' % ( a, targ._h.label, targ.label, self.__dict__[a] ) ) 63 else: 64 print ( ' %s: [ERROR: key not found] [%s]' % ( a, self.__dict__[a] ) ) 63 65 else: 64 print ' %s: %s' % ( a, self.__dict__[a])66 print ( ' %s: %s' % ( a, self.__dict__[a] ) ) 65 67 else: 66 print 'Item <%s>: uninitialised' % self.sectionLabel68 print ( 'Item <%s>: uninitialised' % self.sectionLabel ) 67 69 68 70 def __href__(self,odir=""): 69 71 igns = {'','__unset__'} 70 if self.__dict__.has_key( 'description' )and string.strip( self.description ) not in igns:72 if 'description' in self.__dict__ and string.strip( self.description ) not in igns: 71 73 ttl = self.description 72 elif self.__dict__.has_key( 'title' )and string.strip( self.title ) not in igns:74 elif 'title' in self.__dict__ and string.strip( self.title ) not in igns: 73 75 ttl = self.title 74 76 else: … … 110 112 am = [] 111 113 for t in tl: 112 if self._inx.iref_by_sect[self.uid].a.has_key(t):114 if t in self._inx.iref_by_sect[self.uid].a: 113 115 am.append( '<h3>%s</h3>' % t ) 114 116 am.append( '<ul>' ) … … 132 134 __doc__ = """Initialise from a dictionary.""" 133 135 for a in self._a.keys(): 134 if dict.has_key(a):136 if a in dict: 135 137 self.__dict__[a] = dict[a] 136 138 else: … … 144 146 tvtl = [] 145 147 if etree: 146 ks = set s.Set( el.keys() )148 ks = set( el.keys() ) 147 149 for a in self._a.keys(): 148 150 if a in ks: … … 164 166 v = float(v) 165 167 except: 166 print 'Failed to convert real number: %s' % v168 print ( 'Failed to convert real number: %s' % v ) 167 169 raise 168 170 elif self._a[a].type == u'xs:integer': … … 174 176 if v in { '',u'',' ', u' '}: 175 177 if nw1 < 20: 176 print 'WARN.050.0001: input integer non-compliant: %s: %s: "%s" -- set to zero' % (thissect,a,v)178 print ( 'WARN.050.0001: input integer non-compliant: %s: %s: "%s" -- set to zero' % (thissect,a,v) ) 177 179 nw1 += 1 178 180 v = 0 … … 180 182 try: 181 183 v = int(float(v)) 182 print 'WARN: input integer non-compliant: %s: %s: %s' % (thissect,a,v)184 print ( 'WARN: input integer non-compliant: %s: %s: %s' % (thissect,a,v) ) 183 185 except: 184 186 msg = 'ERROR: failed to convert integer: %s: %s: %s' % (thissect,a,v) … … 190 192 if a in {'uid'}: 191 193 thissect = '%s [%s]' % (self._h.title,self._h.tag) 192 print 'ERROR.020.0001: missing uid: %s' % thissect194 print ( 'ERROR.020.0001: missing uid: %s' % thissect ) 193 195 if etree: 194 print ks196 print ( ks ) 195 197 import sys 196 198 sys.exit(0) … … 201 203 ##raise 202 204 if deferredHandling: 203 print msg205 print ( msg ) 204 206 205 207 self._contentInitialised = True … … 232 234 self.contentDoc = cel.parse( self.vsamp ) 233 235 root = self.contentDoc.getroot() 234 bs = string.split( root.tag, '}' ) 236 ##bs = string.split( root.tag, '}' ) 237 bs = root.tag.split( '}' ) 235 238 if len( bs ) > 1: 236 239 self.ns = bs[0] + '}' … … 304 307 def info(self,ss): 305 308 if not self.silent: 306 print ss309 print ( ss ) 307 310 308 311 def get(self): … … 384 387 self.uid2 = collections.defaultdict( list ) 385 388 nativeAtts = ['uid','iref_by_uid','iref_by_sect','missingIds'] 386 naok = map( lambda x: not dreq.has_key(x), nativeAtts )389 naok = map( lambda x: not x in dreq, nativeAtts ) 387 390 assert all(naok), 'This version cannot index collections containing sections with names: %s' % str( nativeAtts ) 388 391 self.var_uid = {} … … 392 395 irefdict = collections.defaultdict( list ) 393 396 for k in dreq.keys(): 394 if dreq[k].attDefn.has_key('sn'):397 if 'sn' in dreq[k].attDefn: 395 398 self.__dict__[k] = container( ['label','sn'] ) 396 399 else: … … 405 408 for k in dreq.keys(): 406 409 for i in dreq[k].items: 407 assert i.__dict__.has_key('uid'), 'uid not found::\n%s\n%s' % (str(i._h),str(i.__dict__) )408 if self.uid.has_key(i.uid):409 print 'ERROR.100.0001: Duplicate uid: %s [%s]' % (i.uid,i._h.title)410 assert 'uid' in i.__dict__, 'uid not found::\n%s\n%s' % (str(i._h),str(i.__dict__) ) 411 if 'uid' in self.uid: 412 print ( 'ERROR.100.0001: Duplicate uid: %s [%s]' % (i.uid,i._h.title) ) 410 413 self.uid2[i.uid].append( (k,i) ) 411 414 else: … … 426 429 self.iref_by_uid[ id2 ].append( (k2,i.uid) ) 427 430 self.iref_by_sect[ id2 ].a[sect].append( i.uid ) 428 if self.uid.has_key( id2 ):431 if id2 in self.uid: 429 432 n1 += 1 430 433 else: … … 437 440 self.__dict__[k].uid[i.uid] = i 438 441 self.__dict__[k].label[i.label].append( i.uid ) 439 if dreq[k].attDefn.has_key('sn'):442 if 'sn' in dreq[k].attDefn: 440 443 self.__dict__[k].sn[i.sn].append( i.uid ) 441 444 442 445 def info(self,ss): 443 446 if not self.silent: 444 print ss447 print ( ss ) 445 448 446 449 class ds(object): -
CMIP6dreqbuild/trunk/src/framework/example.py
r389 r408 7 7 8 8 priorityMax = 3 9 ll = ['C4MIP','CFMIP','LUMIP'] 10 ee = {} 11 ss = 0. 12 for l in ll: 13 x = sc.volByMip( l, pmax=priorityMax )*1.e-12*bytesPerFloat 14 print '%9s %5.1fTb' % ( l,x ) 15 ss += x 16 z = sc.volByMip( set(ll), pmax=priorityMax )*1.e-12*bytesPerFloat 9 def runExample( priorityMax ): 10 ll = ['C4MIP','CFMIP','LUMIP'] 11 ee = {} 12 ss = 0. 13 for l in ll: 14 x = sc.volByMip( l, pmax=priorityMax )*1.e-12*bytesPerFloat 15 print ( '%9s %5.1fTb' % ( l,x ) ) 16 ss += x 17 z = sc.volByMip( set(ll), pmax=priorityMax )*1.e-12*bytesPerFloat 17 18 19 print ( 'Combined: %5.1fTb' % z ) 20 print ( 'Overlap: %5.1fTb' % (ss-z) ) 18 21 19 print 'Combined: %5.1fTb' % z 20 print 'Overlap: %5.1fTb' % (ss-z) 22 sc.setTierMax( 1 ) 23 z1 = sc.volByMip( set(ll), pmax=priorityMax )*1.e-12*bytesPerFloat 24 sc.setTierMax( 2 ) 25 z2 = sc.volByMip( set(ll), pmax=priorityMax )*1.e-12*bytesPerFloat 26 print ( '' ) 27 print ( 'Combined, tier 1 only: %5.1fTb' % z1 ) 28 print ( 'Combined, tier 1+2 only: %5.1fTb' % z2 ) 29 30 print ( '######### All variables ###########' ) 31 priorityMax = 3 32 runExample( priorityMax ) 33 print ( '######### Top priority variables ###########' ) 34 priorityMax = 1 35 runExample( priorityMax ) -
CMIP6dreqbuild/trunk/src/framework/ptxt.py
r397 r408 23 23 ## 24 24 samplePrologue="""<prologue> 25 <dc:title>Draft CMIP6 Data Request</dc:title> 25 <dc:title>Draft CMIP6 Data Request [01.beta.04]</dc:title> 26 <dc:description>The CMIP6 Data Request will specify the variables requested for the CMIP6 archive, and the detail the experiments and time slices for which they are required.</dc:description> 26 27 <dc:creator>Martin Juckes</dc:creator> 27 28 <dc:date>%s</dc:date> -
CMIP6dreqbuild/trunk/src/framework/scope.py
r397 r408 47 47 class dreqQuery(object): 48 48 __doc__ = """Methods to analyse the data request, including data volume estimates""" 49 def __init__(self,dq=None ):49 def __init__(self,dq=None,tierMax=-1): 50 50 if dq == None: 51 51 self.dq = dreq.loadDreq() … … 55 55 for i in self.dq.coll['objective'].items: 56 56 k = '%s.%s' % (i.mip,i.label) 57 assert not self.rlu.has_key(k), 'Duplicate label in objectives: %s' % k57 assert not k in self.rlu, 'Duplicate label in objectives: %s' % k 58 58 self.rlu[k] = i.uid 59 59 60 self.tierMax = tierMax 60 61 self.mips = { i.mip for i in self.dq.coll['requestItem'].items} 61 62 self.mipls = sorted( list( self.mips ) ) … … 74 75 type = 'a' 75 76 if i.levelFlag == 'false': 76 ds = string.split( i.dimensions,'|' )77 ds = i.dimensions.split( '|' ) 77 78 if ds[-1] in ['site', 'basin']: 78 79 vd = ds[-2] … … 90 91 nz = self.mcfg['nlas'] 91 92 else: 92 print 'Failed to parse dimensions %s' % i.dimensions93 print ( 'Failed to parse dimensions %s' % i.dimensions ) 93 94 raise 94 95 else: 95 96 nz = i.levels 96 97 97 dims = set( string.split( i.dimensions,'|' ) )98 dims = set( i.dimensions.split( '|' ) ) 98 99 if 'latitude' in dims and 'longitude' in dims: 99 100 if type == 'o': … … 153 154 rqlInv = {u for u in rql0 if inx.uid[u]._h.label == 'remarks' } 154 155 if len(rqlInv) != 0: 155 print 'WARNING.001.00002: %s invalid request links from request items ...' % len(rqlInv)156 print ( 'WARNING.001.00002: %s invalid request links from request items ...' % len(rqlInv) ) 156 157 rql = {u for u in rql0 if inx.uid[u]._h.label != 'remarks' } 157 158 … … 194 195 195 196 def esid_to_exptList(self,esid,deref=False): 196 if not self.dq.inx.uid.has_key(esid):197 print 'Attempt to dereferece invalid uid: %s' % esid197 if not esid in self.dq.inx.uid: 198 print ( 'Attempt to dereferece invalid uid: %s' % esid ) 198 199 raise 199 200 … … 201 202 expts = [esid,] 202 203 elif self.dq.inx.uid[esid]._h.label != 'remarks': 203 if self.dq.inx.iref_by_sect.has_key(esid) and self.dq.inx.iref_by_sect[esid].a.has_key( 'experiment' ):204 if esid in self.dq.inx.iref_by_sect and 'experiment' in self.dq.inx.iref_by_sect[esid].a: 204 205 expts = self.dq.inx.iref_by_sect[esid].a['experiment'] 205 206 else: 206 207 expts = [] 207 208 else: 208 print 'WARNING: request link not associated with valid experiment group'209 print ( 'WARNING: request link not associated with valid experiment group' ) 209 210 raise 211 212 if self.tierMax > 0: 213 expts = [i for i in expts if self.dq.inx.uid[i].tier <= self.tierMax] 210 214 211 215 if deref: … … 230 234 expts = [u,] 231 235 elif self.dq.inx.uid[u]._h.label != 'remarks': 232 if self.dq.inx.iref_by_sect.has_key(u) and self.dq.inx.iref_by_sect[u].a.has_key( 'experiment' ):236 if u in self.dq.inx.iref_by_sect and 'experiment' in self.dq.inx.iref_by_sect[u].a: 233 237 expts = self.dq.inx.iref_by_sect[u].a['experiment'] 234 238 else: 235 239 expts = [] 236 240 else: 237 print 'WARNING: request link not associated with valid experiment group'241 print ( 'WARNING: request link not associated with valid experiment group' ) 238 242 i.__info__() 239 243 raise 244 245 if self.tierMax > 0: 246 expts = [i for i in expts if self.dq.inx.uid[i].tier <= self.tierMax] 240 247 241 248 if len(expts) > 0: 242 249 e = [self.dq.inx.uid[i] for i in expts] 243 250 dat = [ (i.ntot, i.yps, i.ensz, i.nstart, filter1(i.yps,rqi.nymax), filter1(i.ensz,rqi.nenmax) ) for i in e] 251 nytot = sum( [x[-2]*x[-1] for x in dat ] ) 252 else: 253 dat = [ (0,0,0,0,0) ] 254 nytot = 0 244 255 245 nytot = sum( [x[-2]*x[-1] for x in dat ] )246 256 return (expts, dat, nytot ) 247 257 258 259 def setTierMax( self, tierMax ): 260 """Set the maxium tier and recompute request sizes""" 261 if tierMax != self.tierMax: 262 self.tierMax = tierMax 263 self.requestItemExpAll( ) 248 264 249 265 def summaryByMip( self, pmax=1 ): … … 251 267 for m in self.mipls: 252 268 v = self.volByMip( m, pmax=pmax ) 253 print '%12.12s: %6.2fTb' % (m,v*bytesPerFloat*1.e-12)269 print ( '%12.12s: %6.2fTb' % (m,v*bytesPerFloat*1.e-12) ) 254 270 255 271 def volByMip( self, mip, pmax=2): … … 257 273 if type(mip) in {type( '' ),type( u'') }: 258 274 if mip not in self.mips: 259 print self.mips275 print ( self.mips ) 260 276 raise baseException( 'volByMip: Name of mip not recognised: %s' % mip ) 261 277 l1 = [i for i in self.dq.coll['requestItem'].items if i.mip == mip]
Note: See TracChangeset
for help on using the changeset viewer.