Changeset 894
- Timestamp:
- 09/12/16 15:34:37 (4 years ago)
- Location:
- CMIP6dreqbuild/trunk/src/framework/dreqPy
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
CMIP6dreqbuild/trunk/src/framework/dreqPy/dreq.py
r782 r894 10 10 try: 11 11 from __init__ import DOC_DIR, version, PACKAGE_DIR 12 import utilities 12 13 except: 13 14 from dreqPy.__init__ import DOC_DIR, version, PACKAGE_DIR 15 from dreqPy import utilities 14 16 15 17 python2 = True … … 168 170 elif mdMode: 169 171 self.mdInit( xmlMiniDom, etree=etree ) 172 173 def hasattr(self,tag): 174 """Return True id the argument passed is the name of an attribute of this instance.""" 175 return tag in self.__dict__ 170 176 171 177 def __repr__(self): … … 469 475 self.coll = {} 470 476 471 self.nts = collections.namedtuple( 'sectdef', ['tag','label','title','id','itemLabelMode','level','maxOccurs','labUnique','uid' ] )477 self.nts = collections.namedtuple( 'sectdef', ['tag','label','title','id','itemLabelMode','level','maxOccurs','labUnique','uid','description'] ) 472 478 self.nti = collections.namedtuple( 'itemdef', ['tag','label','title','type','useClass','techNote','required'] ) 473 479 self.ntt = collections.namedtuple( 'sectinit', ['header','attributes','defaults'] ) … … 702 708 'type':'xs:string', 'uid':'__core__:description', 'label':'label', 'required':'required' } 703 709 if v == None: 704 vtt = self.nts( '__core__', 'CoreAttributes', 'X.1 Core Attributes', '00000000', 'def', '0', '0', 'false', '__core__' )710 vtt = self.nts( '__core__', 'CoreAttributes', 'X.1 Core Attributes', '00000000', 'def', '0', '0', 'false', '__core__', 'The core attributes, used in defining sections and attributes' ) 705 711 else: 706 vtt = self.nts( '__main__', 'DataRequestAttributes', 'X.2 Data Request Attributes', '00000001', 'def', '0', '0', 'false', '__main__' )712 vtt = self.nts( '__main__', 'DataRequestAttributes', 'X.2 Data Request Attributes', '00000001', 'def', '0', '0', 'false', '__main__' , 'The attributes used to define data request records') 707 713 elif v == '__sect__': 708 714 idict = {'title':'Record Description', \ 709 715 'uid':'__core__:description', 'label':'label', 'useClass':'text', 'id':'id', 'maxOccurs':'', 'itemLabelMode':'', 'level':'', 'labUnique':'' } 710 vtt = self.nts( '__sect__', 'sectionAttributes', 'X.3 Section Attributes', '00000000', 'def', '0', '0', 'false', '__sect__' )716 vtt = self.nts( '__sect__', 'sectionAttributes', 'X.3 Section Attributes', '00000000', 'def', '0', '0', 'false', '__sect__', 'The attributes used to define data request sections' ) 711 717 ##<var label="var" uid="SECTION:var" useClass="vocab" title="MIP Variable" id="cmip.drv.001"> 712 718 else: … … 719 725 maxo = v.getAttribute( 'maxOccurs' ) 720 726 labu = v.getAttribute( 'labUnique' ) 727 des = v.getAttribute( 'description' ) 721 728 il = v.getElementsByTagName( 'rowAttribute' ) 722 729 ##vtt = self.nts( v.nodeName, l,t,i,ilm,lev, maxo, labu, 's__%s' % v.nodeName ) 723 vtt = self.nts( v.nodeName, l,t,i,ilm,lev, maxo, labu, u )730 vtt = self.nts( v.nodeName, l,t,i,ilm,lev, maxo, labu, u, des ) 724 731 idict = {} 725 732 for i in il: … … 874 881 defaultDreqPath = '%s/%s' % (DOC_DIR, defaultDreq ) 875 882 defaultConfigPath = '%s/%s' % (DOC_DIR, defaultConfig ) 883 defaultManifestPath = '%s/dreqManifest.txt' % DOC_DIR 876 884 877 885 class loadDreq(object): … … 883 891 """ 884 892 885 def __init__(self,dreqXML= defaultDreqPath, configdoc=defaultConfigPath, useShelve=False, htmlStyles=None, strings=False, manifest=None, configOnly=False):893 def __init__(self,dreqXML=None, configdoc=None, useShelve=False, htmlStyles=None, strings=False, manifest=defaultManifestPath , configOnly=False): 886 894 self.c = config( thisdoc=dreqXML, configdoc=configdoc, useShelve=useShelve,strings=strings,manifest=manifest,configOnly=configOnly) 887 895 self.coll = self.c.coll … … 1023 1031 odir: directory for html files; 1024 1032 ttl0: Title for main index (in odir/index.html)""" 1033 markup = utilities.markupHtml( '' ) 1025 1034 1026 1035 ks = self.inx.uid.keys() … … 1062 1071 msg = ['<h1>%s</h1>\n' % ttl, '<ul>',] 1063 1072 msg.append( '<a href="../index.html">Home</a><br/>\n' ) 1073 msg.append( '<p>%s</p>\n' % markup.parse( self.coll[k].header.description ) ) 1064 1074 lst = self.getHtmlItemStyle(k) 1065 1075 -
CMIP6dreqbuild/trunk/src/framework/dreqPy/makeTables.py
r885 r894 398 398 dims += strc.coords.split( '|' ) 399 399 dims = ' '.join( dims ) 400 if "qcranges" in dq.inx.iref_by_sect[v.uid].a: 401 u = dq.inx.iref_by_sect[v.uid].a['qcranges'][0] 402 qc = dq.inx.uid[u] 403 ll = [] 404 for k in ['valid_min', 'valid_max', 'ok_min_mean_abs', 'ok_max_mean_abs']: 405 if qc.hasattr(k): 406 ll.append( '%s %s' % (qc.__dict__[k],qc.__dict__['%s_status' % k][0]) ) 407 else: 408 ll.append( '' ) 409 valid_min, valid_max, ok_min_mean_abs, ok_max_mean_abs = tuple( ll ) 410 else: 411 valid_min, valid_max, ok_min_mean_abs, ok_max_mean_abs = ('','','','') 412 400 413 if mode == 'c': 401 414 orec = [str(v.defaultPriority),cv.title, cv.units, cv.description, v.description, cv.label, cv.sn, strc.cell_methods, v.positive, v.type, dims, v.label, v.modeling_realm, v.frequency, strc.cell_measures, v.prov,v.provNote,str(v.rowIndex),v.uid,v.vid,v.stid,strc.title] -
CMIP6dreqbuild/trunk/src/framework/dreqPy/packageConfig.py
r885 r894 15 15 16 16 __versionComment__ = "Updates to AerChemMIP experiment names; removed some variable duplication; cleaned uid strings" 17 __version__ = "01.beta.4 4"17 __version__ = "01.beta.45" 18 18 __title__ = "dreqPy" 19 19 __description__ = "CMIP6 Data Request Python API" -
CMIP6dreqbuild/trunk/src/framework/dreqPy/scope.py
r885 r894 132 132 u'monClim':12, u'Timestep':100, u'6hr':4*365, u'day':365, u'1day':365, u'mon':12, u'yr':1, 133 133 u'1mon':12, 'month':12, 'year':1, 'monthly':12, 'hr':24*365, 'other':24*365, 134 'subhr':24*365, 'Day':365, '6h':4*365, '3 hourly':8*365, '':1 }134 'subhr':24*365, 'Day':365, '6h':4*365, '3 hourly':8*365, '':1, 'dec':0.1 } 135 135 136 136 ## There are 4 cmor variables with blank frequency .... … … 172 172 self.gridOceanStructured = True 173 173 self.gridPolicyForce = None 174 self.retainRedundantRank = True 174 175 self.gridPolicyTopOnly = True 175 176 self.exptFilter = None … … 559 560 return ff 560 561 561 def volByExpt( self, l1, ex, pmax=1, cc=None, retainRedundantRank=False,intersection=False,expFullEx=False, adsCount=False ):562 def volByExpt( self, l1, ex, pmax=1, cc=None, intersection=False,expFullEx=False, adsCount=False ): 562 563 """volByExpt: calculates the total data volume associated with an experiment/experiment group and a list of request items. 563 564 The calculation has some approximations concerning the number of years in each experiment group. … … 591 592 ## filter by configuration option and rank 592 593 ## 593 if not retainRedundantRank:594 if not self.retainRedundantRank: 594 595 len1 = len(vars.keys()) 595 596 cmv = self.cmvFilter.filterByChoiceRank(cmv=vars.keys()) … … 1124 1125 cmv2, cmvts2 = self.cmvByMip('TOTAL',pmax=pmax,includeYears=True,exptFilter=self.exptFilter,exptFilterBlack=self.exptFilterBlack) 1125 1126 cmv = self.differenceSelectedCmvDict( cmv1, cmv2 ) 1127 1128 if not self.retainRedundantRank: 1129 len1 = len(cmv) 1130 self.cmvFilter.filterByChoiceRank(cmv=cmv,asDict=True) 1131 len2 = len(cmv) 1132 print 'INFO.redundant.0001: length %s --> %s' % (len1,len2) 1133 else: 1134 print 'INFO.redundant.0002' 1126 1135 1127 1136 self.selectedCmv = cmv … … 1353 1362 return l2 1354 1363 1355 def volByMip( self, mip, pmax=2, retainRedundantRank=False,intersection=False, adsCount=False, exptid=None):1364 def volByMip( self, mip, pmax=2, intersection=False, adsCount=False, exptid=None): 1356 1365 1357 1366 l1 = self.rqiByMip( mip ) … … 1374 1383 if expts not in [None,[]]: 1375 1384 for ei in expts: 1376 self.volByE[ei.label] = self.volByExpt( l1, ei.uid, pmax=pmax, cc=cc, retainRedundantRank=retainRedundantRank,intersection=intersection, adsCount=adsCount )1385 self.volByE[ei.label] = self.volByExpt( l1, ei.uid, pmax=pmax, cc=cc, intersection=intersection, adsCount=adsCount ) 1377 1386 vtot += self.volByE[ei.label][0] 1378 1387 self.allVars = self.allVars.union( self.vars ) … … 1637 1646 ##doSf = 'SF' in self.adict or 'sf' in self.adict 1638 1647 doSf = 'legacy' not in self.adict 1648 if doSf: 1649 self.adict['sf'] = True 1639 1650 assert not ('legacy' in self.adict and 'sf' in self.adict), "Conflicting command line argument, 'legacy' and 'sf': use only one of these" 1640 1651 if makeXls or makeTxt or doSf: -
CMIP6dreqbuild/trunk/src/framework/dreqPy/utilities.py
r885 r894 1 import re 2 3 class markupHtml(object): 4 def __init__(self,base): 5 self.resect = re.compile( '(\{[a-zA-Z]*\})' ) 6 self.relink = re.compile( '(\[http\S*.*\])' ) 7 self.base = base 8 9 def parse(self,ss): 10 print 'INFO.parsing: ',ss 11 for x in self.resect.findall( ss ): 12 print 'INFO.parsing.0001: ',x 13 ss = ss.replace( x, self.sectionlink(x) ) 14 for x in self.relink.findall( ss ): 15 print 'INFO.parsing.0001: ',x 16 ss = ss.replace( x, self.linklink(x) ) 17 return ss 18 19 def sectionlink( self, x ): 20 x1 = x[1:-1] 21 return '<a href=%s%s.html>%s</a>' % (self.base,x1,x1) 22 def linklink( self, x ): 23 a,b = x[1:-1].split( None, 1 ) 24 return '<a href=%s>%s</a>' % (a,b) 25 1 26 2 27 class gridOptionSort(object): … … 109 134 110 135 return cmv 111 def filterByChoiceRank(self,cmv=None): 136 137 def filterByChoiceRank(self,cmv=None,asDict=False): 112 138 """Filter a set of CMOR variable identifiers by rank as specified in varChoiceLinkR section of the data request. 113 139 cmv: set of CMOR variable identifiers. 114 140 115 141 Returns the filetered set. The items removed are available in self.rejected.""" 142 if asDict: 143 assert cmv != None, 'Cannot have empty cmv argument if asDict is True' 116 144 ## 117 145 ## cmv is a set of CMORvar ids … … 128 156 if len(v1) == 0: 129 157 ## print 'Nothing to do' 130 return cmv 158 if asDict: 159 return 160 else: 161 return cmv 131 162 132 163 ## set of "rank" choice groups relevant to current selection … … 145 176 if i.rank < mr: 146 177 l1 = len(cmv) 147 cmv.remove( i.vid ) 178 if asDict: 179 cmv.pop( i.vid ) 180 else: 181 cmv.remove( i.vid ) 148 182 if len(cmv) == l1: 149 183 print ( 'Failed to remove i.vid=%s' % i.vid ) … … 156 190 pass 157 191 158 return cmv 192 if asDict: 193 return 194 else: 195 return cmv 159 196 160 197
Note: See TracChangeset
for help on using the changeset viewer.