Changeset 766 for CMIP6dreqbuild/trunk/src/framework/dreqPy/scope.py
 Timestamp:
 27/09/16 10:49:49 (4 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

CMIP6dreqbuild/trunk/src/framework/dreqPy/scope.py
r761 r766 36 36 37 37 NT_txtopts = collections.namedtuple( 'txtopts', ['mode'] ) 38 39 def vfmt(ss): 40 stb = ss*1.e12 41 if stb < .099: 42 return '%7.2fGb' % (stb*100) 43 else: 44 return '%7.2fTb' % stb 38 45 39 46 class baseException(Exception): … … 487 494 thisny = this[2] 488 495 thisne = this[1] 496 ## 497 ### aggregate year count for each experiment and output grid 489 498 cc2s[grd].a[u].add( filter1( thisns*thisny*thisne, i.nymax) ) 490 499 … … 614 623 expts = [] 615 624 else: 616 # print ( 'WARNING: request link not associated with valid experiment group' )617 ##rqi.__info__()618 ##raise619 625 return (None, None, None, None) 620 626 … … 636 642 for i in e: 637 643 dat2[i.uid] = (i.ntot, i.yps, i.ensz, i.tier, i.nstart, filter1(i.yps,rqi.nymax), filter2(i.ensz,rqi.nenmax,i.tier,self.tierMax) ) 638 ##print i.label, rqi.title, dat2[i.uid] 639 ### number of 644 640 645 nytot = sum( [dat2[x][2]*dat2[x][3] for x in dat2 ] ) 641 646 netot = sum( [dat2[x][1] for x in dat2 ] ) 642 ##print 'debug1:: ',dat, nytot, netot643 647 else: 644 648 dat2 = {} … … 646 650 netot = 0 647 651 652 ## 653 ## to get list of years per expt for each requestLink ... expts is union of all dat2 keys, 654 ## and want max of dat2[x][0] for each experiment x. 655 ## 648 656 return (expts, dat2, nytot, netot ) 649 657 … … 660 668 mlg.prnt ( '%12.12s: %6.2fTb' % (m,v*bytesPerFloat*1.e12) ) 661 669 670 def rqlByMip( self, mip): 671 if mip == 'TOTAL': 672 mip = self.mips 673 674 if type(mip) in [type( '' ),type( u'') ]: 675 if mip not in self.mips: 676 mlg.prnt ( self.mips ) 677 raise baseException( 'rqiByMip: Name of mip not recognised: %s' % mip ) 678 l1 = [i for i in self.dq.coll['requestLink'].items if i.mip == mip] 679 elif type(mip) in [ type( set()), type( [] ) ]: 680 nf = [ m for m in mip if m not in self.mips] 681 if len(nf) > 0: 682 raise baseException( 'rqlByMip: Name of mip(s) not recognised: %s' % str(nf) ) 683 l1 = [i for i in self.dq.coll['requestLink'].items if i.mip in mip] 684 elif type(mip) == type( dict()): 685 nf = [ m for m in mip if m not in self.mips] 686 if len(nf) > 0: 687 raise baseException( 'rqlByMip: Name of mip(s) not recognised: %s' % str(nf) ) 688 l1 = [] 689 for i in self.dq.coll['requestLink'].items: 690 if i.mip in mip: 691 ok = False 692 if len( mip[i.mip] ) == 0: 693 ok = True 694 else: 695 for ol in self.dq.inx.iref_by_sect[i.uid].a['objectiveLink']: 696 o = self.dq.inx.uid[ol] 697 if self.dq.inx.uid[o.oid].label in mip[i.mip]: 698 ok = True 699 if ok: 700 l1.append( i ) 701 else: 702 raise baseException( 'rqiByMip: "mip" (1st explicit argument) should be type string or set: %s  %s' % (mip, type(mip)) ) 703 704 return l1 705 662 706 def rqiByMip( self, mip): 707 l1 = self.rqlByMip( mip ) 708 if len(l1) == 0: 709 return [] 710 l2 = [] 711 for i in l1: 712 if 'requestItem' in self.dq.inx.iref_by_sect[i.uid].a: 713 for u in self.dq.inx.iref_by_sect[i.uid].a['requestItem']: 714 l2.append( self.dq.inx.uid[u] ) 715 716 l20 = self.rqiByMip0( mip ) 717 for i in l20: 718 assert i in l2 719 return l2 720 721 722 def rqiByMip0( self, mip): 663 723 664 724 if mip == 'TOTAL': … … 717 777 mxls.run( m, mlab=mlab ) 718 778 719 779 def cmvByMip( self, mip,pmax=1 ): 780 l1 = self.rvgByMip( mip ) 781 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 ) 789 return l2 790 791 792 def cmvByFreqStr(self,cmv): 793 cc = collections.defaultdict( list ) 794 for i in cmv: 795 st = self.dq.inx.uid[ i.stid ] 796 cc[ (st.spid,i.frequency) ].append( i.label ) 797 c2 = collections.defaultdict( dict ) 798 sf = set() 799 for s,f in cc.keys(): 800 c2[s][f] = cc[ (s,f) ] 801 sf.add( f ) 802 lf = sorted( list(sf) ) 803 print ' ::' + ' ; '.join( [ '%8s' % x for x in lf ] ) 804 for s in sorted( c2.keys() ): 805 i = self.dq.inx.uid[ s ] 806 msg = '%48.48s::' % i.title 807 for f in lf: 808 if f in c2[s]: 809 msg += '%8s ; ' % len(c2[s][f] ) 810 else: 811 msg += ' ; ' 812 print msg 813 814 def rvgByMip( self, mip, years=False ): 815 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 819 720 820 def volByMip( self, mip, pmax=2, retainRedundantRank=False, intersection=False, adsCount=False, exptid=None): 721 821 … … 724 824 #### The set of experiments/experiment groups: 725 825 if exptid == None: 726 ##exps = self.mips727 826 exps = self.experiments 728 827 else: 729 828 exps = set( [exptid,] ) 730 ##print exptid, exps731 829 732 830 self.volByE = {} … … 1037 1135 1038 1136 for v in vl[:mx]: 1039 mlg.prnt ( '%s.%s: % 7.2fTb' % (self.dq.inx.uid[v].mipTable,self.dq.inx.uid[v].label, cc[v]*2.*1.e12) )1137 mlg.prnt ( '%s.%s: %s' % (self.dq.inx.uid[v].mipTable[0],self.dq.inx.uid[v].label, makeTables.vfmt( cc[v]*2. ) ) ) 1040 1138 if mx < len(vl): 1041 1139 mlg.prnt ( '%s variables not listed (use printLinesMax to print more)' % (len(vl)mx) )
Note: See TracChangeset
for help on using the changeset viewer.