def plotTimeSerie30YVariability_hiExt(ax=None, plotXLabel=True, plotYLabel=True, warmingLev=2.0): yrs, rpR8Srs, rpR4Srs, models = loadWlVsScenChange.loadRetPerAllYears(nmodels=nmodels, excludedModels=excludedModels) rpR8 = getRelChng(yrs, rpR8Srs) rpR4 = getRelChng(yrs, rpR4Srs) wlyR8 = getWarmingLevels('rcp85', warmingLev) r8srs = getNYrsTimeSeriesAroundWl(yrs, rpR8, wlyR8, models) r8meanWl, r8sigmaWl = getMeanAndSigma(r8srs) cndPosi = r8meanWl > 0 cndNega = r8meanWl < 0 cnd = cndPosi if positiveChanges else cndNega cndMtx = np.tile(cnd, [r8srs.shape[0], r8srs.shape[1], 1, 1]) r8srs[~cndMtx] = np.nan r8mean_ = np.nanmean(r8srs, 0) r8mean = r8mean_.reshape(r8mean_.shape[0], r8mean_.shape[1]*r8mean_.shape[2]) #r8mean = np.nanmedian(r8mean, 1) r8mean = np.nanmean(r8mean, 1) r8spmean = r8srs.reshape(r8srs.shape[0], r8srs.shape[1], r8srs.shape[2]*r8srs.shape[3]) r8spmean = np.nanmean(r8spmean, 2) #r8spmean = np.nanmean(r8spmean, 2) r8skew = stats.skew(r8spmean[:, 3]) r8sigma = np.std(r8spmean[:, 3]) r8mean = np.nanmean(r8spmean, 0) wlyR4 = getWarmingLevels('rcp45', warmingLev) r4srs = getNYrsTimeSeriesAroundWl(yrs, rpR4, wlyR4, models) r4meanWl, r4sigmaWl = getMeanAndSigma(r4srs) cndPosi = r4meanWl > 0 cndNega = r8meanWl < 0 cnd = cndPosi if positiveChanges else cndNega cndMtx = np.tile(cnd, [r4srs.shape[0], r4srs.shape[1], 1, 1]) r4srs[~cndMtx] = np.nan r4mean_ = np.nanmean(r4srs, 0) r4mean = r4mean_.reshape(r4mean_.shape[0], r4mean_.shape[1]*r4mean_.shape[2]) #r4mean = np.nanmedian(r4mean, 1) r4mean = np.nanmean(r4mean, 1) r4spmean = r4srs.reshape(r4srs.shape[0], r4srs.shape[1], r4srs.shape[2]*r4srs.shape[3]) r4spmean = np.nanmean(r4spmean, 2) #r4spmean = np.nanmean(r4spmean, 2) r4skew = stats.skew(r4spmean[:, 3]) r4sigma = np.std(r4spmean[:, 3]) r4mean = np.nanmean(r4spmean, 0) ensTot = np.concatenate([r8spmean, r4spmean], 0) stdDevTot = np.std(ensTot, 0)*100. meanTot = (r4mean + r8mean)/2.*100. yr = [-15, -10, -5, 0, 5, 10, 15] if ax is None: fg = plt.figure(figsize=[8.46, 4.98]) pstdDev = plt.fill_between(yr, meanTot+stdDevTot, meanTot-stdDevTot, color='gainsboro', label='$\sigma={sgm:1.0f}\%$'.format(sgm=stdDevTot[int(np.floor(len(stdDevTot)/2))])) #pmdlr8 = plt.plot(yr, r8spmean.transpose()*100, 'sandybrown', label='RCP8.5 models ($\sigma={sgm:1.2f}\%, skw.={s:1.2f}$)'.format(sgm=r8sigma*100, s=r8skew)); #pmdlr4 = plt.plot(yr, r4spmean.transpose()*100, 'skyblue', label='RCP4.5 models ($\sigma={sgm:1.2f}\%, skw.={s:1.2f})$'.format(sgm=r4sigma*100, s=r4skew)); #pmdlr8 = plt.plot(yr, r8spmean.transpose()*100, 'sandybrown', label='RCP8.5 models ($\sigma_{{RCP8.5}}={sgm:1.0f}\%$)'.format(sgm=r8sigma*100, s=r8skew)); #pmdlr4 = plt.plot(yr, r4spmean.transpose()*100, 'skyblue', label='RCP4.5 models ($\sigma_{{RCP4.5}}={sgm:1.0f}\%$)'.format(sgm=r4sigma*100, s=r4skew)); pmdlr8 = plt.plot(yr, r8spmean.transpose()*100, 'sandybrown', label='RCP8.5 models'); pmdlr4 = plt.plot(yr, r4spmean.transpose()*100, 'skyblue', label='RCP4.5 models'); #pmedr8 = plt.plot(yr, r8mean*100, 'firebrick', linewidth=6, label='RCP8.5 mean'); #pmedr4 = plt.plot(yr, r4mean*100, 'royalblue', linewidth=6, label='RCP4.5 mean'); pmn = plt.plot(yr, (r4mean+r8mean)/2.*100, 'k', linewidth=6, label='ens. mean'); plt.grid('on') lgndLoc = 2 if positiveChanges else 3 #plt.legend(handles=[pmdlr8[0], pmedr8[0], pmdlr4[0], pmedr4[0], pstdDev], fontsize=12, loc=lgndLoc) plt.legend(handles=[pmdlr8[0], pmdlr4[0], pmn[0], pstdDev], fontsize=12, loc=lgndLoc) if plotXLabel: plt.xlabel('years to $' + str(warmingLev) + '^\circ$C w.l.', fontsize=18) else: ax.set_xticklabels([]) if plotYLabel: plt.ylabel('$Q_{H100}$ % change', fontsize=17) else: ax.set_yticklabels([]) ax.tick_params(axis="x", labelsize=axFontSize) ax.tick_params(axis="y", labelsize=axFontSize) ylm = ax.get_ylim() dlt = max(ylm) - min(ylm) pzr = plt.plot([0, 0], [min(ylm)-dlt*4, max(ylm)+dlt*4], 'k', linewidth=2) pzr[0].set_zorder(1) ax.set_ylim(ylm) plt.tight_layout() if ax is None: fg.savefig('./ensemblesVariabilityAround2deg.png', dpi=400)
def plotTimeSerieVariabilityAtWl_lowExt(ax=None, axmap=None, plotXLabel=True, plotYLabel=True, warmingLev=2.0, bsmp=None): yrs, rpR8Srs, rpR4Srs, models = loadWlVsScenChange.loadRetPerAllYears(rlVarName='rl_min', nmodels=nmodels, excludedModels=excludedModels) rpR8 = getRelChng(yrs, rpR8Srs) rpR4 = getRelChng(yrs, rpR4Srs) wlyR8 = getWarmingLevels('rcp85', warmingLev) r8srs = getNYrsTimeSeriesAroundWl(yrs, rpR8, wlyR8, models) r8srs[r8srs == np.inf] = np.nan wlyR4 = getWarmingLevels('rcp45', warmingLev) r4srs = getNYrsTimeSeriesAroundWl(yrs, rpR4, wlyR4, models) r4srs[r4srs == np.inf] = np.nan srstot = np.concatenate([r8srs, r4srs], 0) rallmeanWl, rallsigmaWl = getMeanAndSigma(r8srs) cndPosi = rallmeanWl > 0 cndNega = rallmeanWl < 0 cnd = cndPosi if positiveChanges else cndNega r8meanWl, r8sigmaWl = getMeanAndSigma(r8srs) cndMtx = np.tile(cnd, [r8srs.shape[0], r8srs.shape[1], 1, 1]) r8srs[~cndMtx] = np.nan r8mean_ = np.nanmean(r8srs, 0) r8mean = r8mean_.reshape(r8mean_.shape[0], r8mean_.shape[1]*r8mean_.shape[2]) r8mean = np.nanmedian(r8mean, 1) #r8mean = np.nanmean(r8mean, 1) r8spmean = r8srs.reshape(r8srs.shape[0], r8srs.shape[1], r8srs.shape[2]*r8srs.shape[3]) r8spmean = np.nanmedian(r8spmean, 2) #r8spmean = np.nanmean(r8spmean, 2) r8skew = stats.skew(r8spmean[:, 0]) r8sigma = np.std(r8spmean[:, 0]) r8mean = np.nanmean(r8spmean, 0) r4meanWl, r4sigmaWl = getMeanAndSigma(r4srs) cndMtx = np.tile(cnd, [r4srs.shape[0], r4srs.shape[1], 1, 1]) r4srs[~cndMtx] = np.nan r4mean_ = np.nanmean(r4srs, 0) r4mean = r4mean_.reshape(r4mean_.shape[0], r4mean_.shape[1]*r4mean_.shape[2]) r4mean = np.nanmedian(r4mean, 1) #r4mean = np.nanmean(r4mean, 1) r4spmean = r4srs.reshape(r4srs.shape[0], r4srs.shape[1], r4srs.shape[2]*r4srs.shape[3]) r4spmean = np.nanmedian(r4spmean, 2) #r4spmean = np.nanmean(r4spmean, 2) r4skew = stats.skew(r4spmean[:, 0]) r4sigma = np.std(r4spmean[:, 0]) r4mean = np.nanmean(r4spmean, 0) ensTot = np.concatenate([r8spmean, r4spmean], 0) stdDevTot = np.std(ensTot, 0)*100. meanTot = (r4mean + r8mean)/2.*100. yr = [-15, -10, -5, 0, 5, 10, 15] if ax is None: fg = plt.figure(figsize=[8.46, 4.98]) ax = fg.gca() doPlotChanges(ax, warmingLev, meanTot, stdDevTot, r8spmean, r4spmean, r8mean, r4mean, plotXLabel, plotYLabel) if not axmap is None: bsmp = doPlotAreaMap(axmap, cnd, bsmp) plt.tight_layout() if ax is None: fg.savefig('./ensemblesVariabilityAround2deg_lowExt.png', dpi=400) return bsmp
def plotTimeSerie30YVariability_hiExt(ax=None, plotXLabel=True, warmingLev=2.0): yrs, rpR8Srs, rpR4Srs, models = loadWlVsScenChange.loadRetPerAllYears( nmodels=nmodels) rpR8 = getRelChng(yrs, rpR8Srs) rpR4 = getRelChng(yrs, rpR4Srs) wlyR8 = getWarmingLevels('rcp85', warmingLev) r8srs = getNYrsTimeSeriesAroundWl(yrs, rpR8, wlyR8, models) r8medianWl, r8sigmaWl = getMeanAndSigma(r8srs) cndSignR8 = np.abs(r8medianWl) > r8sigmaWl cndPosi = r8medianWl > 0 #cnd = np.logical_and(cndSignR8, cndPosi) cnd = cndPosi cndMtx = np.tile(cnd, [r8srs.shape[0], r8srs.shape[1], 1, 1]) r8srs[~cndMtx] = np.nan r8median_ = np.median(r8srs, 0) r8median = r8median_.reshape(r8median_.shape[0], r8median_.shape[1] * r8median_.shape[2]) r8median = np.nanmedian(r8median, 1) #r8median = np.nanmean(r8median, 1) r8spmean = r8srs.reshape(r8srs.shape[0], r8srs.shape[1], r8srs.shape[2] * r8srs.shape[3]) r8spmean = np.nanmedian(r8spmean, 2) #r8spmean = np.nanmean(r8spmean, 2) r8skew = stats.skew(r8spmean[:, 3]) r8sigma = np.std(r8spmean[:, 3]) r8median = np.nanmedian(r8spmean, 0) wlyR4 = getWarmingLevels('rcp45', 2.0) r4srs = getNYrsTimeSeriesAroundWl(yrs, rpR4, wlyR4, models) r4medianWl, r4sigmaWl = getMeanAndSigma(r4srs) cndSignR4 = np.abs(r4medianWl) > r4sigmaWl cndPosi = r4medianWl > 0 cnd = cndPosi cndMtx = np.tile(cnd, [r4srs.shape[0], r4srs.shape[1], 1, 1]) r4srs[~cndMtx] = np.nan r4median_ = np.median(r4srs, 0) r4median = r4median_.reshape(r4median_.shape[0], r4median_.shape[1] * r4median_.shape[2]) r4median = np.nanmedian(r4median, 1) #r4median = np.nanmean(r4median, 1) r4spmean = r4srs.reshape(r4srs.shape[0], r4srs.shape[1], r4srs.shape[2] * r4srs.shape[3]) r4spmean = np.nanmedian(r4spmean, 2) #r4spmean = np.nanmean(r4spmean, 2) r4skew = stats.skew(r4spmean[:, 3]) r4sigma = np.std(r4spmean[:, 3]) r4median = np.nanmedian(r4spmean, 0) yr = [-15, -10, -5, 0, 5, 10, 15] if ax is None: fg = plt.figure(figsize=[8.46, 4.98]) #pmdlr8 = plt.plot(yr, r8spmean.transpose()*100, 'peachpuff', label='RCP8.5 models ($\sigma={sgm:1.2f}\%, skw.={s:1.2f}$)'.format(sgm=r8sigma*100, s=r8skew)); #pmdlr4 = plt.plot(yr, r4spmean.transpose()*100, 'skyblue', label='RCP4.5 models ($\sigma={sgm:1.2f}\%, skw.={s:1.2f})$'.format(sgm=r4sigma*100, s=r4skew)); pmdlr8 = plt.plot(yr, r8spmean.transpose() * 100, 'peachpuff', label='RCP8.5 models ($\sigma={sgm:1.2f}\%$'.format( sgm=r8sigma * 100, s=r8skew)) pmdlr4 = plt.plot(yr, r4spmean.transpose() * 100, 'skyblue', label='RCP4.5 models ($\sigma={sgm:1.2f}\%$'.format( sgm=r4sigma * 100, s=r4skew)) pmedr8 = plt.plot(yr, r8median * 100, 'firebrick', linewidth=6, label='RCP8.5 mean') pmedr4 = plt.plot(yr, r4median * 100, 'royalblue', linewidth=6, label='RCP4.5 mean') plt.grid('on') plt.legend(handles=[pmdlr8[0], pmedr8[0], pmdlr4[0], pmedr4[0]]) if plotXLabel: plt.xlabel('years to $2^\circ C w.l.$', fontsize=14) plt.ylabel('$Q_{H100}$ % change', fontsize=14) plt.tight_layout() if ax is None: fg.savefig('./ensemblesVariabilityAround2deg.png', dpi=400)