Ignore:
Timestamp:
15/02/19 14:37:03 (8 months ago)
Author:
mjuckes
Message:

01.00.30beta

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMIP6dreq/trunk/dreqPy/extensions/collect.py

    r1259 r1309  
    33import collections 
    44 
     5class GenIsUsed(object): 
     6  def __init__(self,parent,callers=[]): 
     7    self.c = callers 
     8    self.pa = parent._inx.iref_by_sect[parent.uid].a 
     9  def __call__(self): 
     10    if len(self.c ) == 0: 
     11       return True 
     12    for c in self.c: 
     13      if c in self.pa and len( self.pa[c] ) > 0: 
     14        return True 
     15    return False 
     16     
     17def _count(self,sect=None): 
     18  if sect != None: 
     19    if sect in self.coll.keys(): 
     20      return len( self.coll[sect].items ) 
     21    else: 
     22      print ("INVALID SECTION: %s" % ', '.join( sorted( self.coll.keys() ) ) ) 
     23  for k in sorted( self.coll.keys() ): 
     24     print ("%16s:: %s" % (k,len( self.coll[k].items ) ) ) 
     25 
     26def _isLinked(self): 
     27  """Return True if another record links to this record""" 
     28  if len( self._inx.iref_by_sect[self.uid].a.keys() ) == 0: 
     29    return False 
     30  for k in self._inx.iref_by_sect[self.uid].a.keys(): 
     31    if len( self._inx.iref_by_sect[self.uid].a[k] ) > 0: 
     32      return True 
     33  return False 
     34 
     35def _var__mips(self): 
     36    """Return set of mip item identifiers for MIPs requesting this var""" 
     37    mips = set() 
     38    for i in self._inx.iref_by_sect[self.uid].a['CMORvar']: 
     39      cmv = self._inx.uid[i] 
     40      mips = mips.union( cmv._get__mips() ) 
     41    return mips 
     42 
     43def _CMORvar__mips(self): 
     44    """Return set of mip item identifiers for MIPs requesting this CMORvar""" 
     45    mips = set() 
     46    for i in self._inx.iref_by_sect[self.uid].a['requestVar']: 
     47      rqv = self._inx.uid[i] 
     48      mips = mips.union( rqv._get__mips() ) 
     49    return mips 
     50 
     51def _rqv__mips(self): 
     52    """Return set of mip item identifiers for MIPs requesting this requestVar""" 
     53    mips = set() 
     54    for i in self._inx.iref_by_sect[self.vgid].a['requestLink']: 
     55      rql = self._inx.uid[i] 
     56      mips.add(rql.mip) 
     57    return mips 
    558 
    659def _expt__CMORvar(self): 
     
    2477    return s 
    2578     
    26  
    2779def _requestItem__expt(self,tierMax=None,esid=None): 
    2880    """Return set of experiment item identifiers for experiments linked directly or indirectly to this requestItem: 
     
    120172 
    121173def _mip__CMORvar(self,mips=None,pmax=None): 
    122     """Return set of CMORvar item identifiers for CMORvar linked to this mip: 
     174    """Return set of CMORvar item identifiers for CMORvar requested by this mip: 
    123175          pmax: maximum variable priority: if set, only return variables requested with priority <= pmax; 
    124176          mips: set of mip uid values: if set, return variables for specified set.""" 
     
    260312   dq.coll['requestLink'].items[0].__class__._get__expt = _requestLink__expt 
    261313   dq.coll['requestLink'].items[0].__class__._get__CMORvar = _requestLink__CMORvar 
     314   dq.coll['var'].items[0].__class__._get__mips = _var__mips 
     315   dq.coll['CMORvar'].items[0].__class__._get__mips = _CMORvar__mips 
     316   dq.coll['requestVar'].items[0].__class__._get__mips = _rqv__mips 
    262317   dq.coll['mip'].items[0].__class__._get__CMORvar = _mip__CMORvar 
    263318   dq.coll['timeSlice'].items[0].__class__.__compare__ = _timeSlice__compare 
     319 
     320   dq.__class__._count = _count 
     321 
    264322   for k in dq.coll.keys(): 
    265323     if len( dq.coll[k].items ) > 0: 
     
    267325       dq.coll[k].items[0].__class__._sectionObj = dq.coll[k] 
    268326       dq.coll[k].items[0].__class__._append = _append_to_item_list 
    269  
    270    for k in ['var','experiment','timeSlice','mip','spatialShape','structure','grids']: 
     327       dq.coll[k].items[0].__class__._isLinked = _isLinked 
     328 
     329   for i in dq.coll['cellMethods'].items: 
     330     i._isUsed = GenIsUsed(i,['structure',]) 
     331 
     332   for k in ['var','experiment','timeSlice','mip','spatialShape','structure','grids','__sect__']: 
    271333     dq.coll[k].items[0].__class__._labelDict = dict() 
    272334     for i in dq.coll[k].items: 
Note: See TracChangeset for help on using the changeset viewer.