1 | import collections, string |
---|
2 | try: |
---|
3 | import makeTables |
---|
4 | except: |
---|
5 | import dreqPy.makeTables as makeTables |
---|
6 | |
---|
7 | ##NT_txtopts = collections.namedtuple( 'txtopts', ['mode'] ) |
---|
8 | |
---|
9 | class xlsTabs(object): |
---|
10 | """used in scope.py; uses makeTables.py""" |
---|
11 | def __init__(self,sc,tiermax=1,pmax=1,xls=True, txt=False, txtOpts=None, odir='xls'): |
---|
12 | self.pmax=pmax |
---|
13 | self.tiermax=tiermax |
---|
14 | self.sc = sc |
---|
15 | sc.setTierMax( tiermax ) |
---|
16 | self.cc = collections.defaultdict( c1 ) |
---|
17 | self.dq = sc.dq |
---|
18 | self.doXls = xls |
---|
19 | self.doTxt = txt |
---|
20 | |
---|
21 | self.mips = ['AerChemMIP', 'C4MIP', 'CFMIP', 'DAMIP', 'DCPP', 'FAFMIP', 'GeoMIP', 'GMMIP', 'HighResMIP', 'ISMIP6', 'LS3MIP', 'LUMIP', 'OMIP', 'PMIP', 'RFMIP', 'ScenarioMIP', 'VolMIP', 'CORDEX', 'DynVar', 'SIMIP', 'VIACSAB'] |
---|
22 | self.mipsp = ['DECK','CMIP6',] + self.mips[:-4] |
---|
23 | |
---|
24 | self.tabs = makeTables.tables( sc, self.mips, xls=xls, txt=txt, txtOpts=txtOpts, odir=odir ) |
---|
25 | |
---|
26 | def run(self,m,colCallback=None,verb=False,mlab=None,exid=None): |
---|
27 | if m == 'TOTAL': |
---|
28 | l1 = self.sc.rqiByMip( set( self.mips ) ) |
---|
29 | else: |
---|
30 | l1 = self.sc.rqiByMip( m ) |
---|
31 | |
---|
32 | if mlab == None: |
---|
33 | mlab = m |
---|
34 | |
---|
35 | verb = False |
---|
36 | if verb: |
---|
37 | print ( 'r1: m=%s, len(l1)=%s' % (mlab,len(l1)) ) |
---|
38 | |
---|
39 | self.cc[mlab].dd = {} |
---|
40 | self.cc[mlab].ee = {} |
---|
41 | self.tabs.accReset() |
---|
42 | vcc = collections.defaultdict( int ) |
---|
43 | for m2 in self.mipsp + ['TOTAL',]: |
---|
44 | if m2 == 'TOTAL': |
---|
45 | xx = self.dq.coll['experiment'].items |
---|
46 | else: |
---|
47 | xx = [i for i in self.dq.coll['experiment'].items if i.mip == m2] |
---|
48 | if exid != None: |
---|
49 | xxx = [i for i in xx if i.uid == exid] |
---|
50 | if len(xxx) == 0: |
---|
51 | break |
---|
52 | xx = xxx |
---|
53 | self.cc[mlab].ee[m2] = xx |
---|
54 | xxi = set( [i.label for i in xx] ) |
---|
55 | ## |
---|
56 | ## need to check this option, and add a template for a view summarising the experiments for each mip-mip combinations |
---|
57 | ## |
---|
58 | if m2 != 'TOTAL': |
---|
59 | for i in xx: |
---|
60 | self.tabs.doTable(m,l1,i.uid,self.pmax,self.cc,acc=False,cc=vcc,exptids=xxi,mlab=None) |
---|
61 | |
---|
62 | self.tabs.doTable(m,l1,m2,self.pmax,self.cc,cc=vcc,exptids=xxi,mlab=None) |
---|
63 | |
---|
64 | if verb: |
---|
65 | print ( 'r1: mlab=%s,m2=%s, len(l1)=%s, len(xxi)=%s' % (mlab,m2,len(l1),len(xxi)) ) |
---|
66 | |
---|
67 | if colCallback != None: |
---|
68 | colCallback( m,m2,mlab=mlab ) |
---|
69 | |
---|
70 | |
---|