Changeset 768
- Timestamp:
- 30/09/16 15:41:36 (5 years ago)
- Location:
- CMIP6dreqbuild/trunk/src/framework/dreqPy
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
CMIP6dreqbuild/trunk/src/framework/dreqPy/dreq.py
r766 r768 817 817 sect = i._h.label 818 818 ## append attribute name and target -- item i.uid, attribute k2 reference item id2 819 if type(id2) != type( [] ):819 if type(id2) not in [type( [] ),type(())]: 820 820 id2 = [id2,] 821 821 for u in id2: -
CMIP6dreqbuild/trunk/src/framework/dreqPy/makeTables.py
r766 r768 325 325 326 326 j = 0 327 thiscmv = sorted( [v for v in cmv if v.mipTable == t], cmp=cmpdn(['prov','rowIndex','label']).cmp )327 thiscmv = sorted( [v for v in cmv if v.mipTable[0] == t], cmp=cmpdn(['prov','rowIndex','label']).cmp ) 328 328 329 329 for v in thiscmv: … … 331 331 strc = dq.inx.uid[ v.stid ] 332 332 if strc._h.label == 'remarks': 333 print ( 'ERROR: structure not found for %s: %s .. %s (%s)' % (v.uid,v.label,v.title,v.mipTable ) )333 print ( 'ERROR: structure not found for %s: %s .. %s (%s)' % (v.uid,v.label,v.title,v.mipTable[0]) ) 334 334 ok = False 335 335 else: … … 549 549 else: 550 550 nrq = 'unused' 551 return '<li>%s {%s}: %s [%s: %s] (%s)</li>' % ( targ.__href__(odir='../u/', label=targ.label), targ.mipTable , targ.title, targ.frequency, t2.title, nrq )551 return '<li>%s {%s}: %s [%s: %s] (%s)</li>' % ( targ.__href__(odir='../u/', label=targ.label), targ.mipTable[0], targ.title, targ.frequency, t2.title, nrq ) 552 552 553 553 def objLink(self,targ,frm='',ann=''): … … 741 741 htmlStyle['spatialShape'] = {'getIrefs':['__all__']} 742 742 htmlStyle['temporalShape'] = {'getIrefs':['__all__']} 743 htmlStyle['structure'] = {'getIrefs':['__all__']}744 htmlStyle['cellMethods'] = {'getIrefs':['__all__']}743 htmlStyle['structure'] = {'getIrefs':['__all__']} 744 htmlStyle['cellMethods'] = {'getIrefs':['__all__']} 745 745 htmlStyle['standardname'] = {'getIrefs':['__all__']} 746 746 htmlStyle['varRelations'] = {'getIrefs':['__all__']} 747 htmlStyle['varRelLnk'] = {'getIrefs':['__all__']} 748 htmlStyle['units'] = {'getIrefs':['__all__']} 747 htmlStyle['varRelLnk'] = {'getIrefs':['__all__']} 748 htmlStyle['units'] = {'getIrefs':['__all__']} 749 htmlStyle['timeSlice'] = {'getIrefs':['__all__']} 749 750 750 751 if __name__ == "__main__": … … 778 779 779 780 dreq.dreqItemBase._extraHtml['requestVarGroup'] = rvgExtraTable.vgx1(dq).mxoGet 780 781 781 dreq.dreqItemBase.__charmeEnable__['var'] = nt__charmeEnable( 'test','http://clipc-services.ceda.ac.uk/dreq' ) 782 782 -
CMIP6dreqbuild/trunk/src/framework/dreqPy/scope.py
r766 r768 1 1 """Date Request Scoping module 2 --------------------------- 2 ------------------------------ 3 3 The scope.py module contains the dreqQuery class and a set of ancilliary functions. The dreqQuery class contains methods for analysing the data request. 4 4 """ 5 5 6 try: 6 7 import dreq … … 14 15 import collections, string, operator 15 16 import sys, os 17 18 odsz = {'tau':7, 'scatratio':15, 'effectRadLi|tau':(28,'query pending'), 'vegtype':(8,'free'), 'sza5':5, 'site':(119,'73 for aquaplanet .. '), 'iceband':(5,'free'), 'dbze':15, 'spectband':(10,'free'), 'misrBands':(7,'query pending'), 'effectRadIc|tau':(28,'query pending')} 16 19 17 20 python2 = True … … 157 160 self.szgss = collections.defaultdict( dict ) 158 161 for i in self.dq.coll['spatialShape'].items: 159 type = 'a'162 gtype = 'a' 160 163 if i.levelFlag == False: 161 164 ds = i.dimensions.split( '|' ) … … 166 169 167 170 if vd[:4] == 'olev' or vd == 'rho': 168 type = 'o'171 gtype = 'o' 169 172 nz = self.mcfg['nlo'] 170 173 elif vd[:4] == 'alev': … … 182 185 dims = set( i.dimensions.split( '|' ) ) 183 186 if 'latitude' in dims and 'longitude' in dims: 184 if type == 'o':187 if gtype == 'o': 185 188 nh = self.mcfg['nho'] 186 189 else: … … 196 199 s = 1 197 200 if i.odims != '': 198 s = s*5 201 if i.odims in odsz: 202 sf = odsz[i.odims] 203 else: 204 print 'SEVERE.odims.00001: no information on dimension size: %s' % i.odims 205 sf = 5 206 if type( sf ) == type( () ): 207 sf = sf[0] 208 s = s*sf 199 209 if i.spid in self.szss: 200 210 self.sz[i.uid] = self.szss[i.spid]*s … … 384 394 return thisvars 385 395 396 def exptYears( self, rqll, ex=None): 397 """Parse a set of request links, and get years requested for each (varGroup, expt, grid) tuple """ 398 399 cc = collections.defaultdict( set ) 400 for rl in rqll: 401 if 'requestItem' not in self.dq.inx.iref_by_sect[rl.uid].a: 402 print 'WARN.001.00001: no request items for: ',rl.uid, rl.title 403 else: 404 405 if rl.grid == '100km': 406 grd = '1deg' 407 if rl.grid in ['1deg','2deg']: 408 grd = rl.grid 409 else: 410 grd = 'native' 411 412 for iu in self.dq.inx.iref_by_sect[rl.uid].a['requestItem']: 413 i = self.dq.inx.uid[iu] 414 if iu in self.rqiExp: 415 for e in self.rqiExp[iu][1]: 416 if ex == None or e in ex: 417 this = self.rqiExp[iu][1][e] 418 if this != None: 419 thisns = this[-3] 420 thisny = this[-2] 421 thisne = this[-1] 422 cc[ (rl.refid,e,grd) ].add( filter1( thisns*thisny*thisne, i.nymax) ) 423 ee = collections.defaultdict( dict ) 424 for g,e,grd in cc: 425 ee[g][(e,grd)] = max( cc[( g,e,grd) ] ) 426 return ee 427 386 428 def volByExpt( self, l1, ex, pmax=1, cc=None, retainRedundantRank=False, intersection=False,expFullEx=False, adsCount=False ): 387 429 """volByExpt: calculates the total data volume associated with an experiment/experiment group and a list of request items. … … 496 538 ## 497 539 ### aggregate year count for each experiment and output grid 540 ## clarify definition and usage of nymax -- should be redundant ... could be replaced by inward references from "timeSlice" 498 541 cc2s[grd].a[u].add( filter1( thisns*thisny*thisne, i.nymax) ) 499 542 … … 772 815 import scope_utils 773 816 mxls = scope_utils.xlsTabs(self,tiermax=self.tierMax,pmax=pmax,xls=xls, txt=txt, txtOpts=txtOpts,odir=odir) 774 775 817 mlab = makeTables.setMlab( m ) 776 777 818 mxls.run( m, mlab=mlab ) 778 819 779 def cmvByMip( self, mip,pmax=1 ): 780 l1 = self.rvgByMip( mip ) 820 def cmvByMip( self, mip,pmax=1,includeYears=False ): 821 l1,ee = self.rvgByMip( mip, includePreset=True, returnLinks=True ) 822 if includeYears: 823 expys = self.exptYears( l1 ) 824 cc = collections.defaultdict( set ) 781 825 ss = set() 782 for i in l1: 783 if 'requestVar' in self.dq.inx.iref_by_sect[i.uid].a: 784 for x in self.dq.inx.iref_by_sect[i.uid].a['requestVar']: 785 i1 = self.dq.inx.uid[x] 786 if i1.priority <= pmax: 787 ss.add( i1.vid ) 788 l2 = sorted( [i for i in [self.dq.inx.uid[i] for i in ss] if i._h.label != 'remarks'], key=lambda x: x.label ) 826 for pr in ee: 827 if pr != -1: 828 print 'INFO.preset.00101: ',pr,len(ee[pr]) 829 for i in ee[pr]: 830 if 'requestVar' in self.dq.inx.iref_by_sect[i.uid].a: 831 for x in self.dq.inx.iref_by_sect[i.uid].a['requestVar']: 832 i1 = self.dq.inx.uid[x] 833 if (pr == -1 and i1.priority <= pmax) or (pr > 0 and pr <= pmax): 834 if includeYears: 835 assert i.uid in expys, 'No experiment info found for requestVarGroup: %s' % i.uid 836 for e,g in expys[i.uid]: 837 cc[(i1.vid,e,g)].add( expys[i.uid][e,g] ) 838 else: 839 ss.add( i1.vid ) 840 if includeYears: 841 l2 = collections.defaultdict( dict ) 842 for v,e,g in cc: 843 l2[v][(e,g)] = max( list( cc[(v,e,g)] ) ) 844 else: 845 l2 = sorted( [i for i in [self.dq.inx.uid[i] for i in ss] if i._h.label != 'remarks'], key=lambda x: x.label ) 789 846 return l2 790 847 791 792 def cmvByFreqStr(self,cmv): 848 def getFreqStrSummary(self,mip,pmax=1): 849 cmv = self.cmvByMip(mip,pmax=pmax,includeYears=True) 850 ### need to pass request link list to expt years ... should be from cmv?? 851 ##eys = self.exptYears( ----- ) 852 return self.cmvByFreqStr( cmv ) 853 854 def cmvByFreqStr(self,cmv,asDict=True): 793 855 cc = collections.defaultdict( list ) 794 856 for i in cmv: 795 st = self.dq.inx.uid[ i.stid ] 796 cc[ (st.spid,i.frequency) ].append( i.label ) 857 if asDict: 858 ii = self.dq.inx.uid[i] 859 if ii._h.label != 'remarks': 860 st = self.dq.inx.uid[ ii.stid ] 861 cc0 = collections.defaultdict( float ) 862 cc1 = collections.defaultdict( int ) 863 se = set() 864 for e,g in cmv[i]: 865 cc0[g] += cmv[i][(e,g)] 866 cc1[g] += 1 867 se.add(e) 868 for g in cc0: 869 cc[ (st.spid,st.odims,ii.frequency,g) ].append( (ii.label,cc0[g],cc1[g],se) ) 870 else: 871 st = self.dq.inx.uid[ i.stid ] 872 cc[ (st.spid,st.odims,i.frequency) ].append( i.label ) 873 797 874 c2 = collections.defaultdict( dict ) 798 875 sf = set() 799 for s,f in cc.keys(): 800 c2[s][f] = cc[ (s,f) ] 801 sf.add( f ) 876 if asDict: 877 for s,o,f,g in cc.keys(): 878 c2[(s,o,g)][f] = cc[ (s,o,f,g) ] 879 sf.add( f ) 880 else: 881 for s,o,f in cc.keys(): 882 c2[(s,o)][f] = cc[ (s,o,f) ] 883 sf.add( f ) 802 884 lf = sorted( list(sf) ) 885 c3 = collections.defaultdict( dict ) 803 886 print ' ::' + ' ; '.join( [ '%8s' % x for x in lf ] ) 804 for s in sorted( c2.keys() ): 887 for tt in sorted( c2.keys() ): 888 if asDict: 889 s,o,g = tt 890 else: 891 s,o = tt 892 g = 'native' 805 893 i = self.dq.inx.uid[ s ] 806 msg = '%48.48s::' % i.title 894 if o != '': 895 msg = '%s [%s]' % (i.title,o) 896 else: 897 msg = i.title 898 if g != 'native': 899 msg += '{%s}' % g 900 msg += '::' 901 807 902 for f in lf: 808 if f in c2[s]: 809 msg += '%8s ; ' % len(c2[s][f] ) 903 if f in c2[tt]: 904 if asDict: 905 nn = len(c2[tt][f] ) 906 ny = 0 907 expts = set() 908 for lab, ny1, ne, eset in c2[tt][f]: 909 ny += ny1 910 for e in eset: 911 expts.add(e) 912 ne = len( expts ) 913 ny = ny/nn 914 msg += '%4s|%5.1f|%3s ; ' % (nn,ny,ne) 915 c3[tt][f] = (nn,ny,ne) 916 else: 917 msg += '%8s ; ' % len(c2[tt][f] ) 810 918 else: 811 919 msg += ' ; ' 812 920 print msg 813 814 def rvgByMip( self, mip, years=False ): 921 return (sf,c3) 922 923 def csvFreqStrSummary(self,mip,records=False): 924 sf, c3 = self.getFreqStrSummary(mip) 925 lf = sorted( list(sf) ) 926 hdr = ['','',''] 927 for f in lf: 928 hdr += [f,'','',str( npy.get( f, '****') )] 929 orecs = [hdr,] 930 for tt in sorted( c3.keys() ): 931 s,o,g = tt 932 i = self.dq.inx.uid[ s ] 933 if o != '': 934 msg = '%48.48s [%s]' % (i.title,o) 935 if o in odsz: 936 sf = odsz[o] 937 else: 938 print 'SEVERE.odims.00005: no information on dimension size: %s' % o 939 sf = 5 940 if type( sf ) == type( () ): 941 sf = sf[0] 942 else: 943 sf = 1 944 msg = '%48.48s' % i.title 945 if g != 'native': 946 msg += '{%s}' % g 947 szg = self.szgss[g][s] 948 else: 949 szg = self.szss[s] 950 szg = szg * sf 951 952 rec = [msg,szg,2] 953 for f in lf: 954 if f in c3[tt]: 955 nn,ny,ne = c3[tt][f] 956 rec += [nn,ny,ne,''] 957 else: 958 rec += ['','','',''] 959 orecs.append( rec ) 960 961 if records: 962 return orecs 963 oo = open( 'text.csv', 'w' ) 964 for rec in orecs: 965 oo.write( '\t'.join( [str(x) for x in rec] ) + '\n' ) 966 oo.close() 967 968 def rvgByMip( self, mip, years=False, includePreset=False, returnLinks=False ): 815 969 l1 = self.rqlByMip( mip ) 816 ss = set( [i.refid for i in l1] ) 817 l2 = sorted( [self.dq.inx.uid[i] for i in ss], key=lambda x: x.label ) 818 return l2 970 if includePreset: 971 cc = collections.defaultdict( set ) 972 ss = set() 973 for i in l1: 974 if 'requestItem' in self.dq.inx.iref_by_sect[i.uid].a: 975 prs = {self.dq.inx.uid[x].preset for x in self.dq.inx.iref_by_sect[i.uid].a['requestItem']} 976 for p in prs: 977 assert p in {-1,1,2,3}, 'Bad preset value' 978 cc[p].add( i.refid ) 979 ee = {} 980 for p in cc: 981 l2 = sorted( [self.dq.inx.uid[i] for i in cc[p]], key=lambda x: x.label ) 982 ee[p] = l2 983 if returnLinks: 984 return (l1,ee) 985 else: 986 return ee 987 else: 988 ss = set( [i.refid for i in l1] ) 989 l2 = sorted( [self.dq.inx.uid[i] for i in ss], key=lambda x: x.label ) 990 if returnLinks: 991 return (l1,l2) 992 else: 993 return l2 819 994 820 995 def volByMip( self, mip, pmax=2, retainRedundantRank=False, intersection=False, adsCount=False, exptid=None): … … 906 1081 -p <priority> maximum priority; 907 1082 --xls : Create Excel file with requested variables; 1083 --sf : Print summary of variable count by structure and frequency; 908 1084 --txt : Create text file with requested variables; 909 1085 --mcfg : Model configuration: 7 integers, comma separated, 'nho','nlo','nha','nla','nlas','nls','nh1' … … 932 1108 '--count':('count',False), \ 933 1109 '--txt':('txt',False), \ 1110 '--sf':('sf',False), \ 934 1111 '--mcfg':('mcfg',True), \ 935 1112 '--txtOpts':('txtOpts',True), \ … … 1063 1240 mlg.prnt ( 'NOT FOUND: %s' % i ) 1064 1241 1242 if 'sf' in self.adict: 1243 self.sc.getFreqStrSummary( self.adict['m'] ) 1244 return 1245 1246 1065 1247 eid = None 1066 1248 ex = None
Note: See TracChangeset
for help on using the changeset viewer.