Changeset 491 for CMIP6dreqbuild
- Timestamp:
- 19/11/15 09:59:58 (7 years ago)
- Location:
- CMIP6dreqbuild/trunk/src/framework/dreqPy
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CMIP6dreqbuild/trunk/src/framework/dreqPy/dreq.py
r470 r491 17 17 ll = [] 18 18 for l in ii: 19 ll.append( [x[1:-1] for x in string.strip(l).split('\t') ] ) 19 ##ll.append( [x[1:-1] for x in string.strip(l).split('\t') ] ) 20 ll.append( [x[1:-1] for x in l.strip().split('\t') ] ) 20 21 cc = collections.defaultdict( dict ) 21 22 for l in ll[3:]: … … 31 32 def isIntStr( self, tv ): 32 33 """Check whether a string is a valid representation of an integer.""" 33 if type( tv ) not in {type(''),type(u'')}:34 if type( tv ) not in [type(''),type(u'')]: 34 35 self.reason = 'NOT STRING' 35 36 return False … … 49 50 _linkAttrStyle = {} 50 51 51 def __init__(self, dict=None,xmlMiniDom=None,id='defaultId',etree=False):52 dictMode = dict != None52 def __init__(self,idict=None,xmlMiniDom=None,id='defaultId',etree=False): 53 dictMode = idict != None 53 54 mdMode = xmlMiniDom != None 54 55 assert not( dictMode and mdMode), 'Mode must be either dictionary of minidom: both assigned' … … 59 60 self._greenIcon = '<img height="12pt" src="/images/154g.png" alt="[i]"/>' 60 61 if dictMode: 61 self.dictInit( dict )62 self.dictInit( idict ) 62 63 elif mdMode: 63 64 self.mdInit( xmlMiniDom, etree=etree ) … … 88 89 89 90 def __href__(self,odir="",label=None): 90 igns = {'','__unset__'}91 igns = ['','__unset__'] 91 92 if 'description' in self.__dict__ and self.description != None and string.strip( self.description ) not in igns: 92 93 ttl = self.description … … 170 171 171 172 172 def dictInit( self, dict ):173 def dictInit( self, idict ): 173 174 __doc__ = """Initialise from a dictionary.""" 174 175 for a in self._a.keys(): 175 if a in dict:176 self.__dict__[a] =dict[a]176 if a in idict: 177 val = idict[a] 177 178 else: 178 self.__dict__[a] = self._d.defaults.get( a, self._d.glob ) 179 val = self._d.defaults.get( a, self._d.glob ) 180 setattr( self, a, val ) 179 181 self._contentInitialised = True 180 182 … … 213 215 v = string.strip(v) 214 216 thissect = '%s [%s]' % (self._h.title,self._h.tag) 215 if v in { '',u'',' ', u' '}:217 if v in [ '',u'',' ', u' ']: 216 218 if nw1 < 20: 217 219 print ( 'WARN.050.0001: input integer non-compliant: %s: %s: "%s" -- set to zero' % (thissect,a,v) ) … … 226 228 deferredHandling=True 227 229 elif self._a[a].type == u'xs:boolean': 228 v = v in {'true','1'}230 v = v in ['true','1'] 229 231 self.__dict__[a] = v 230 232 else: 231 if a in {'uid'}:233 if a in ['uid',]: 232 234 thissect = '%s [%s]' % (self._h.title,self._h.tag) 233 235 print ( 'ERROR.020.0001: missing uid: %s' % thissect ) … … 305 307 self.tt0 = {} 306 308 for k in self.bscc: 307 self.tt0[k] = self._tableClass0( dict=self.bscc[k])309 self.tt0[k] = self._tableClass0(idict=self.bscc[k]) 308 310 if k in self._t0.attributes: 309 311 setattr( self._tableClass0, '%s' % k, self.tt0[k] ) … … 328 330 self.tableClasses[t[0].label] = self.itemClassFact( t, ns=self.ns ) 329 331 thisc = self.tableClasses[t[0].label] 330 self.tt1[t[0].label] = self._sectClass0( dict=t.header.__dict__)332 self.tt1[t[0].label] = self._sectClass0( idict=t.header._asdict() ) 331 333 self.tt1[t[0].label].maxOccurs = t.header.maxOccurs 332 334 self.tt1[t[0].label].labUnique = t.header.labUnique … … 483 485 returnClass = True 484 486 if returnClass: 485 return self._tableClass0( dict=ee )487 return self._tableClass0( idict=ee ) 486 488 else: 487 489 return self.nti( i.nodeName, l,t,ty,cls,tn ) -
CMIP6dreqbuild/trunk/src/framework/dreqPy/scope.py
r463 r491 9 9 10 10 python2 = True 11 if sys.version_info .major== 3:11 if sys.version_info[0] == 3: 12 12 python2 = False 13 13 from functools import reduce … … 74 74 self.cmvFilter = cmvFilter( self ) 75 75 self.tierMax = tierMax 76 self.mips = { i.mip for i in self.dq.coll['requestItem'].items} 76 77 self.mips = set() 78 for i in self.dq.coll['requestItem'].items: 79 self.mips.add(i.mip) 77 80 self.mipls = sorted( list( self.mips ) ) 78 81 79 82 self.default_mcfg = nt_mcfg._make( [259200,60,64800,40,20,5,100] ) 80 self.mcfg = {}81 for k in self.default_mcfg.__dict__.keys():82 self.mcfg[k] = self.default_mcfg.__dict__[k]83 self.mcfg = self.default_mcfg._asdict() 84 ##for k in self.default_mcfg.__dict__.keys(): 85 ##self.mcfg[k] = self.default_mcfg.__dict__[k] 83 86 self.szcfg() 84 87 self.requestItemExpAll( ) … … 131 134 if type(mipSel) == type(''): 132 135 t1 = lambda x: x == mipSel 133 elif type(mipSel) == type( {1,2}):136 elif type(mipSel) == type(set()): 134 137 t1 = lambda x: x in mipSel 135 self.rqs = list({self.dq.inx.uid[i.rid] for i in self.dq.coll['objectiveLink'].items if t1(i.label) }) 138 139 s = set() 140 for i in self.dq.coll['objectiveLink'].items: 141 if t1(i.label): 142 s.add( self.dq.inx.uid[i.rid] ) 143 ##self.rqs = list({self.dq.inx.uid[i.rid] for i in self.dq.coll['objectiveLink'].items if t1(i.label) }) 144 self.rqs = list( s ) 136 145 return self.rqs 137 146 … … 140 149 if type(objSel) == type(''): 141 150 t1 = lambda x: x == self.rlu[objSel] 142 elif type(objSel) == type({1,2}): 143 t1 = lambda x: x in {self.rlu[i] for i in objSel} 144 145 self.rqs = list({self.dq.inx.uid[i.rid] for i in self.dq.coll['objectiveLink'].items if t1(i.oid) }) 151 elif type(objSel) == type(set()): 152 t1 = lambda x: x in [self.rlu[i] for i in objSel] 153 154 s = set() 155 for i in self.dq.coll['objectiveLink'].items: 156 if t1(i.label): 157 s.add( self.dq.inx.uid[i.oid] ) 158 ## 159 self.rqs = list( s ) 160 ##self.rqs = list({self.dq.inx.uid[i.rid] for i in self.dq.coll['objectiveLink'].items if t1(i.oid) }) 146 161 return self.rqs 147 162 … … 149 164 """For a list of request links, return a list of variable group IDs for each experiment""" 150 165 self.cc = collections.defaultdict( list ) 151 dummy = {self.cc[i.expt].append(i.rlid) for i in self.dq.coll['requestItem'].items if i.rlid in {j.uid for j in rqList} }166 ## dummy = {self.cc[i.expt].append(i.rlid) for i in self.dq.coll['requestItem'].items if i.rlid in {j.uid for j in rqList} } 152 167 return self.cc 153 168 … … 163 178 ## 164 179 inx = self.dq.inx 165 imips = {i.mip for i in l1} 180 imips = set() 181 for i in l1: 182 imips.add(i.mip) 183 ##imips = {i.mip for i in l1} 166 184 ## 167 185 ## rql is the set of all request links which are associated with a request item for this experiment set 168 186 ## 169 l1p = {i for i in l1 if (i.esid == ex) and (i.preset < 0 or i.preset <= pmax) } 170 171 rql0 = {i.rlid for i in l1p} 172 173 rqlInv = {u for u in rql0 if inx.uid[u]._h.label == 'remarks' } 187 l1p = set() 188 for i in l1: 189 if (i.esid == ex) and (i.preset < 0 or i.preset <= pmax): 190 l1p.add(i) 191 192 rql0 = set() 193 for i in l1p: 194 rql0.add(i.rlid) 195 196 rqlInv = set() 197 for u in rql0: 198 if inx.uid[u]._h.label == 'remarks': 199 rqlInv.add( u ) 174 200 if len(rqlInv) != 0: 175 201 print ( 'WARNING.001.00002: %s invalid request links from request items ...' % len(rqlInv) ) 176 rql = {u for u in rql0 if inx.uid[u]._h.label != 'remarks' } 202 rql = set() 203 for u in rql0: 204 if inx.uid[u]._h.label != 'remarks': 205 rql.add( u ) 206 177 207 if len( rql ) == 0: 178 208 self.vars = set() … … 182 212 tm = 1 183 213 if tm == 0: 184 rqvg = list({inx.uid[i].refid for i in rql}) 214 s = set() 215 for i in rql: 216 s.add( inx.uid[i].refid ) 217 rqvg = list( s ) 185 218 else: 186 219 cc1 = collections.defaultdict( set ) … … 195 228 for k in cc1: 196 229 thisc = reduce( operator.or_, [set( inx.iref_by_sect[vg].a['requestVar'] ) for vg in cc1[k] ] ) 197 ccv[k] = {inx.uid[l].vid for l in list(thisc) if inx.uid[l].priority <= pmax} 230 s = set() 231 for l in list(thisc): 232 if inx.uid[l].priority <= pmax: 233 s.add( inx.uid[l].vid ) 234 ccv[k] = s 198 235 199 236 if len( ccv.keys() ) < len( list(imips) ): … … 209 246 210 247 ###The collector col1 here accumulates all the record uids, resulting in a single collection. These are request variables, to get a set of CMOR variables at priority <= pmax: 211 vars = {inx.uid[l].vid for l in list(col1) if inx.uid[l].priority <= pmax} 248 vars = set() 249 for l in list(col1): 250 if inx.uid[l].priority <= pmax: 251 vars.add(inx.uid[l].vid) 212 252 ## 213 253 ## if looking for the union, would have to do a filter here ... after looking up which vars are requested by each MIP ... … … 218 258 ### filter out cases where the request does not point to a CMOR variable. 219 259 ##vars = {vid for vid in vars if inx.uid[vid][0] == u'CMORvar'} 220 vars = {vid for vid in vars if inx.uid[vid]._h.label == u'CMORvar'} 260 thisvars = set() 261 for vid in vars: 262 if inx.uid[vid]._h.label == u'CMORvar': 263 thisvars.add(vid) 264 vars = thisvars 221 265 ## 222 266 ## filter by configuration option and rank … … 234 278 ### for request variables which reference the variable group attached to the link, add the associate CMOR variables, subject to priority 235 279 i = inx.uid[u] 236 e[i.uid] = { inx.uid[x].vid for x in inx.iref_by_sect[i.refid].a['requestVar'] if inx.uid[x].priority <= pmax} 280 e[i.uid] = set() 281 for x in inx.iref_by_sect[i.refid].a['requestVar']: 282 if inx.uid[x].priority <= pmax: 283 e[i.uid].add( inx.uid[x].vid ) 237 284 # 238 285 # for each variable, calculate the maximum number of years across all the request links which reference that variable. … … 242 289 nym = {} 243 290 for v in vars: 244 nym[v] = max( {self.rqiExp[i.uid][2] for i in l1p if i.esid == ex and v in e[i.rlid]} ) 291 s = set() 292 for i in l1p: 293 if i.esid == ex and v in e[i.rlid]: 294 s.add( self.rqiExp[i.uid][2] ) 295 ##nym[v] = max( {self.rqiExp[i.uid][2] for i in l1p if i.esid == ex and v in e[i.rlid]} ) 296 nym[v] = max( s ) 245 297 246 298 szv = {} … … 336 388 def volByMip( self, mip, pmax=2, retainRedundantRank=False): 337 389 338 if type(mip) in {type( '' ),type( u'') }:390 if type(mip) in [type( '' ),type( u'') ]: 339 391 if mip not in self.mips: 340 392 print ( self.mips ) … … 350 402 351 403 #### The set of experiments/experiment groups: 352 exps = {i.esid for i in l1} 404 exps = set() 405 for i in l1: 406 exps.add( i.esid ) 353 407 self.volByE = {} 354 408 vtot = 0 … … 436 490 self.adict['m'] = set(self.adict['m'].split(',') ) 437 491 438 integerArgs = {'p','t','plm'}492 integerArgs = set( ['p','t','plm'] ) 439 493 for i in integerArgs.intersection( self.adict ): 440 494 self.adict[i] = int( self.adict[i] ) -
CMIP6dreqbuild/trunk/src/framework/dreqPy/simpleCheck.py
r470 r491 115 115 self._clear_ch03() 116 116 return 117 if string.find(ii[0],'validates') != -1:117 if ii[0].find('validates') != -1: 118 118 print ( 'Sample XML validated' ) 119 119 self.ok = True
Note: See TracChangeset
for help on using the changeset viewer.