def calc_runstats(datablob,sims, seas=None,siglevel=0.05): """ datablob: 'ctl','pert','diff' should be timeseries of regional means sims: a tuple of sim names in the datablob. (prob unnecessary) seas: 2 or 3 month seasons return allstats: dictionary of 'tpvals', 'fpvals' for sim key and then sea key """ ctldt = datablob['ctl'] pertdt = datablob['pert'] diffdt = datablob['diff'] simspdt = con.get_simpairsdict() if seas==None: seasons=('SON','DJF','MAM','JJA') else: seasons=seas allstats={}; alltpval={}; allfpval={} for sim in sims: ctlsim=ctldt[sim] pertsim=pertdt[sim] seatpval={}; seafpval={} for sea in seasons: thestats={} print sim + ' ' + sea ctl=ctlsim[sea] pert=pertsim[sea] (tstat,tpval,lstat,lpval) = cutl.calc_pvals(pert,ctl) ## print ' DIFF: ' + str(pert.mean()-ctl.mean()) + ', CTL mean: ' + str(ctl.mean()) + ', PERT mean: ' + str(pert.mean()) ## tstat, tpval = sp.stats.ttest_ind(pert,ctl) # add autocorr @@ ## print ' TSTAT: ' + str(tstat) + ' PVAL: ' + str(tpval) ## if tpval<=siglevel: ## print ' **The ensemble means are significantly different (' + str(1-siglevel) + ')' ## #thestats['tpval'] = pval ## #fstat, fpval = sp.stats.f_oneway(pert,ctl) # same as t statistic ## #print ' FSTAT: ' + str(fstat) + ' PVAL: ' + str(fpval) ## #if fpval<=siglevel: ## # print ' **The ensemble means are significantly different (' + str(1-siglevel) + ')' ## print ' CTL std: ' + str(ctl.std()) + ', PERT std: ' + str(pert.std()) ## lstat, lpval = sp.stats.levene(pert,ctl) ## print ' LSTAT: ' + str(lstat) + ' PVAL: ' + str(lpval) ## if lpval<=siglevel: ## print ' **The ensemble variances are significantly different (' + str(1-siglevel) + ')' seatpval[sea]=tpval seafpval[sea]=lpval alltpval[sim]=seatpval allfpval[sim]=seafpval allstats['tpval']=alltpval allstats['fpval']=allfpval return allstats
ax.plot(tpxx,tppdf_fitted,'r') ax.set_xlabel(label) ax.set_title('TOT') ax.legend(('CTL','PERT')) print label print 'TOT CTL (mean,std): ' + str(tcnormed) print 'TOT PERT (mean,std): ' + str(tpnormed) if printtofile: fig.savefig('histpdf_' + label + '_ANTTOTsbplt.pdf') printtofile=False plot_anttotanom_histpdf(allantr2,alltotr2, label=(field2 + region2 + '_' + str(sea2)),printtofile=printtofile) cutl.calc_pvals(allantr2,alltotr2) print '-------------------------' plot_anttotanom_histpdf(allantr1,alltotr1, label=(field1 + region1 + '_' + str(sea1)),printtofile=printtofile) cutl.calc_pvals(allantr1,alltotr1) plot_anttotsbplt_histpdf((allantcr2,allantpr2),(alltotcr2,alltotpr2), label=(field2 + region2 + '_' + str(sea2)),printtofile=printtofile) print 'ANT: ' + field2, region2 cutl.calc_pvals(allantpr2,allantcr2) print 'TOT: ' + field2, region2 cutl.calc_pvals(alltotpr2,alltotcr2) plot_anttotsbplt_histpdf((allantcr1,allantpr1),(alltotcr1,alltotpr1),