def readData(simu,period,varia,level,latpolar,cps): ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat,lon,lev,future = NUDG.readExperi(varia,'AA','2030',level,'none') lat,lon,lev,historical = CONT.readControl(varia,level,'none') elif simu == 'AA-2060': lat,lon,lev,future = NUDG.readExperi(varia,'AA','2060',level,'none') lat,lon,lev,historical = CONT.readControl(varia,level,'none') elif simu == 'AA-2090': lat,lon,lev,future = NUDG.readExperi(varia,'AA','2090',level,cps) lat,lon,lev,historical = CONT.readControl(varia,level,cps) ############################################################################### elif simu == 'coupled': lat,lon,lev,future = COUP.readCOUPs(varia,'C_Fu',level) lat,lon,lev,historical = COUP.readCOUPs(varia,'C_Pd',level) ############################################################################### elif simu == 'SIT': lat,lon,lev,future = THICK.readSIT(varia,'SIT_Fu',level) lat,lon,lev,historical = THICK.readSIT(varia,'SIT_Pd',level) ############################################################################### elif simu == 'SIC': lat,lon,lev,future = CONC.readSIC(varia,'Fu',level) lat,lon,lev,historical = CONC.readSIC(varia,'Pd',level) ############################################################################### ############################################################################### ############################################################################### ### Calculate number of ensembles nens = np.shape(historical)[0] ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,-3:],axis=1) historicalm = np.nanmean(historical[:,-3:],axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,-1:],axis=1) historicalm = np.nanmean(historical[:,-1:],axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future,historical] var_mo = np.empty((2,historical.shape[0]-1,historical.shape[2],historical.shape[3],historical.shape[4])) for i in range(len(runs)): var_mo[i,:,:,:,:] = UT.calcDecJanFeb(runs[i],runs[i],lat,lon,level,17) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,0:3],axis=1) historicalm = np.nanmean(historical[:,0:3],axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,0:2],axis=1) historicalm = np.nanmean(historical[:,0:2],axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,1:4],axis=1) historicalm = np.nanmean(historical[:,1:4],axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,1:3],axis=1) historicalm = np.nanmean(historical[:,1:3],axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,0:1],axis=1) historicalm = np.nanmean(historical[:,0:1],axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,1:2],axis=1) historicalm = np.nanmean(historical[:,1:2],axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,2:3],axis=1) historicalm = np.nanmean(historical[:,2:3],axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,2:4],axis=1) historicalm = np.nanmean(historical[:,2:4],axis=1) elif period == 'annual': print('Calculating over %s months!' % period) futurem = np.nanmean(future,axis=1) historicalm = np.nanmean(historical,axis=1) elif period == 'NONE': print('Calculating over %s months!' % period) futurem = future historicalm = historical elif period == 'timemonth': print('Calculating over O,N,D,J,F,M months!') futurem = np.append(future[:,-3:,:,:,:],future[:,:3,:,:,:],axis=1) historicalm = np.append(historical[:,-3:,:,:,:],historical[:,:3,:,:,:],axis=1) else: print(ValueError('Selected wrong month period!')) ########################################################################### ########################################################################### ########################################################################### ### Calculate polar cap lon2,lat2 = np.meshgrid(lon,lat) ### Calculate SHI latq = np.where((lat >= latpolar))[0] lat2p = lat2[latq,:] futurep = futurem[:,:,:,latq,:] futuremz = UT.calc_weightedAve(futurep,lat2p) historicalp = historicalm[:,:,:,latq,:] historicalmz = UT.calc_weightedAve(historicalp,lat2p) ### Calculate anomalies [ens,level,lat] anom = futuremz - historicalmz ### Calculate ensemble mean anommean = np.nanmean(anom,axis=0) ### Calculate significance pruns = UT.calc_FDR_ttest(futuremz,historicalmz,0.05) #FDR ### Select climo climo = np.nanmean(historicalmz,axis=0) return lat,lon,lev,anommean,nens,pruns,climo
def readData(simu, period, varia, level): ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2030', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2060': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2060', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2090': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2090', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') ############################################################################### elif simu == 'coupled': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pd', level) ############################################################################### elif simu == 'SIT': lat, lon, lev, future = THICK.readSIT(varia, 'SIT_Fu', level) lat, lon, lev, historical = THICK.readSIT(varia, 'SIT_Pd', level) ############################################################################### elif simu == 'SIC_Pd': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pd', level) ############################################################################### elif simu == 'SIC_Pi': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pi', level) ############################################################################### elif simu == 'E3SIT': lat, lon, lev, future = E3SIT.readE3SM_SIT(varia, 'ESIT_Fu', level) lat, lon, lev, historical = E3SIT.readE3SM_SIT(varia, 'ESIT_Pd', level) ############################################################################### elif simu == 'E3SIC_Pd': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pd', level) elif simu == 'E3SIC_Pi': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pi', level) ############################################################################### elif simu == 'OLD': lat, lon, lev, future = OLD.readOldIceExperi(varia, 'FICT', level) lat, lon, lev, historical = OLD.readOldIceExperi(varia, 'HIT', level) ############################################################################### ############################################################################### ############################################################################### ### Calculate number of ensembles nens = np.shape(historical)[0] ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -3:], axis=1) historicalm = np.nanmean(historical[:, -3:], axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -1:], axis=1) historicalm = np.nanmean(historical[:, -1:], axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future, historical] var_mo = np.empty((2, historical.shape[0] - 1, historical.shape[2], historical.shape[3], historical.shape[4])) for i in range(len(runs)): var_mo[i, :, :, :, :] = UT.calcDecJanFeb(runs[i], runs[i], lat, lon, level, 17) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:3], axis=1) historicalm = np.nanmean(historical[:, 0:3], axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:2], axis=1) historicalm = np.nanmean(historical[:, 0:2], axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:4], axis=1) historicalm = np.nanmean(historical[:, 1:4], axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:3], axis=1) historicalm = np.nanmean(historical[:, 1:3], axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:1], axis=1) historicalm = np.nanmean(historical[:, 0:1], axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:2], axis=1) historicalm = np.nanmean(historical[:, 1:2], axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:3], axis=1) historicalm = np.nanmean(historical[:, 2:3], axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:4], axis=1) historicalm = np.nanmean(historical[:, 2:4], axis=1) else: print(ValueError('Selected wrong month period!')) ########################################################################### ########################################################################### ########################################################################### ### Calculate zonal means futuremz = np.nanmean(futurem, axis=3) historicalmz = np.nanmean(historicalm, axis=3) ### Calculate anomalies [ens,level,lat] anom = futuremz - historicalmz ### Calculate ensemble mean anommean = np.nanmean(anom, axis=0) ### Calculate significance pruns = UT.calc_FDR_ttest(futuremz, historicalmz, 0.05) #FDR ### Select climo climo = np.nanmean(historicalmz, axis=0) return lat, lon, lev, anommean, nens, pruns, climo
def PolarCap(simu,vari,level,latpolar,period): """ Script calculates average over the polar cap (set latitude) """ ### Import modules import numpy as np import calc_Utilities as UT import read_CTLNQ as CONT import read_ExpMonthly as NUDG import read_ShortCoupled as COUP import read_SIT as THICK import read_SIC as CONC import read_SIT_E3SM as E3SIT import read_SIC_E3SM as E3SIC import read_OldIceExperi as OLD import read_LongCoupled as LC if any([vari=='T700',vari=='T500']): varia = 'TEMP' level = 'profile' elif vari == 'U700': varia = 'U' level = 'profile' else: varia = vari ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat,lon,lev,future = NUDG.readExperi(varia,'AA','2030',level,'none') lat,lon,lev,historical = CONT.readControl(varia,level,'none') elif simu == 'AA-2060': lat,lon,lev,future = NUDG.readExperi(varia,'AA','2060',level,'none') lat,lon,lev,historical = CONT.readControl(varia,level,'none') elif simu == 'AA-2090': lat,lon,lev,future = NUDG.readExperi(varia,'AA','2090',level,'none') lat,lon,lev,historical = CONT.readControl(varia,level,'none') ############################################################################### elif simu == 'coupled_Pd': lat,lon,lev,future = COUP.readCOUPs(varia,'C_Fu',level) lat,lon,lev,historical = COUP.readCOUPs(varia,'C_Pd',level) ############################################################################### elif simu == 'coupled_Pi': lat,lon,lev,future = COUP.readCOUPs(varia,'C_Fu',level) lat,lon,lev,historical = COUP.readCOUPs(varia,'C_Pi',level) ############################################################################### elif simu == 'SIT': lat,lon,lev,future = THICK.readSIT(varia,'SIT_Fu',level) lat,lon,lev,historical = THICK.readSIT(varia,'SIT_Pd',level) ############################################################################### elif simu == 'SIC_Pd': lat,lon,lev,future = CONC.readSIC(varia,'Fu',level) lat,lon,lev,historical = CONC.readSIC(varia,'Pd',level) ############################################################################### elif simu == 'SIC_Pi': lat,lon,lev,future = CONC.readSIC(varia,'Fu',level) lat,lon,lev,historical = CONC.readSIC(varia,'Pi',level) ############################################################################### elif simu == 'E3SIT': lat,lon,lev,future = E3SIT.readE3SM_SIT(varia,'ESIT_Fu',level) lat,lon,lev,historical = E3SIT.readE3SM_SIT(varia,'ESIT_Pd_B',level) ############################################################################### elif simu == 'E3SIC_Pd': lat,lon,lev,future = E3SIC.readE3SM_SIC(varia,'ESIC_Fu',level) lat,lon,lev,historical = E3SIC.readE3SM_SIC(varia,'ESIC_Pd',level) elif simu == 'E3SIC_Pi': lat,lon,lev,future = E3SIC.readE3SM_SIC(varia,'ESIC_Fu',level) lat,lon,lev,historical = E3SIC.readE3SM_SIC(varia,'ESIC_Pi',level) ############################################################################### elif simu == 'OLD': lat,lon,lev,future = OLD.readOldIceExperi(varia,'FICT',level) lat,lon,lev,historical = OLD.readOldIceExperi(varia,'HIT',level) ############################################################################### elif simu == 'LONG': lat,lon,lev,future = LC.readLong(varia,'Long_Fu',level) lat,lon,lev,historical = LC.readLong(varia,'Long_Pd',level) ############################################################################### ############################################################################### ############################################################################### ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ### Check for 4D field if vari == 'T700': levq = np.where(lev == 700)[0] future = future[:,:,levq,:,:].squeeze() historical = historical[:,:,levq,:,:].squeeze() elif vari == 'T500': levq = np.where(lev == 500)[0] future = future[:,:,levq,:,:].squeeze() historical = historical[:,:,levq,:,:].squeeze() elif vari == 'U700': levq = np.where(lev == 700)[0] future = future[:,:,levq,:,:].squeeze() historical = historical[:,:,levq,:,:].squeeze() ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,-3:,:,:],axis=1) historicalm = np.nanmean(historical[:,-3:,:,:],axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,-1:,:,:],axis=1) historicalm = np.nanmean(historical[:,-1:,:,:],axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future,historical] var_mo = np.empty((2,historical.shape[0]-1,historical.shape[2],historical.shape[3])) for i in range(len(runs)): var_mo[i,:,:,:] = UT.calcDecJanFeb(runs[i],runs[i],lat,lon,'surface',1) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,0:3,:,:],axis=1) historicalm = np.nanmean(historical[:,0:3,:,:],axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,0:2,:,:],axis=1) historicalm = np.nanmean(historical[:,0:2,:,:],axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,1:4,:,:],axis=1) historicalm = np.nanmean(historical[:,1:4,:,:],axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,1:3,:,:],axis=1) historicalm = np.nanmean(historical[:,1:3,:,:],axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,0:1,:,:],axis=1) historicalm = np.nanmean(historical[:,0:1,:,:],axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,1:2,:,:],axis=1) historicalm = np.nanmean(historical[:,1:2,:,:],axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,2:3,:,:],axis=1) historicalm = np.nanmean(historical[:,2:3,:,:],axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:,2:4,:,:],axis=1) historicalm = np.nanmean(historical[:,2:4,:,:],axis=1) elif period == 'NONE': futurem = future historicalm = historical else: print(ValueError('Selected wrong month period!')) ############################################################################### ############################################################################### ############################################################################### ### Calculate anomalies anom = futurem - historicalm ### Meshgrid for lat,lon lon2,lat2 = np.meshgrid(lon,lat) ### Calculate SHI if period == 'NONE': latq = np.where((lat >= latpolar))[0] anomp = anom[:,:,latq,:] lat2p = lat2[latq,:] polarave = UT.calc_weightedAve(anomp,lat2p) else: latq = np.where((lat >= latpolar))[0] anomp = anom[:,latq,:] lat2p = lat2[latq,:] polarave = UT.calc_weightedAve(anomp,lat2p) print('\n========Calculated Polar Cap Average========\n') return polarave ### Test functions (do not use!) #ave = PolarCap('AA-2030','TEMP','profile',65,'DJF') #import matplotlib.pyplot as plt #import numpy as np #plt.figure(figsize=(11,4)) #plt.title('Monthly SIC Anomalies') #plt.plot(ave.ravel()) #plt.savefig('/home/zlabe/Desktop/' + 'monthly_SIC_anom.png',dpi=300)
def readData(simu, period, vari, level, cps): if any([vari == 'T700', vari == 'T500']): varia = 'TEMP' level = 'profile' elif vari == 'U700': varia = 'U' level = 'profile' elif any([vari == 'V925', vari == 'V700', vari == 'V1000']): varia = 'V' level = 'profile' else: varia = vari ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2030', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2060': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2060', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2090': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2090', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') ############################################################################### elif simu == 'coupled_Pd': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pd', level) ############################################################################### elif simu == 'coupled_Pi': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pi', level) ############################################################################### elif simu == 'SIT': lat, lon, lev, future = THICK.readSIT(varia, 'SIT_Fu', level) lat, lon, lev, historical = THICK.readSIT(varia, 'SIT_Pd', level) ############################################################################### elif simu == 'SIC_Pd': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pd', level) ############################################################################### elif simu == 'SIC_Pi': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pi', level) ############################################################################### elif simu == 'E3SIT': lat, lon, lev, future = E3SIT.readE3SM_SIT(varia, 'ESIT_Fu', level) lat, lon, lev, historical = E3SIT.readE3SM_SIT(varia, 'ESIT_Pd', level) ############################################################################### elif simu == 'E3SIC_Pd': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pd', level) elif simu == 'E3SIC_Pi': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pi', level) ############################################################################### elif simu == 'OLD': lat, lon, lev, future = OLD.readOldIceExperi(varia, 'FICT', level) lat, lon, lev, historical = OLD.readOldIceExperi(varia, 'HIT', level) ############################################################################### elif simu == 'LONG': lat, lon, lev, future = LC.readLong(varia, 'Long_Fu', level) lat, lon, lev, historical = LC.readLong(varia, 'Long_Pd', level) ############################################################################### ############################################################################### ############################################################################### ### Calculate number of ensembles nens = np.shape(historical)[0] ### Check for 4D field if vari == 'T700': levq = np.where(lev == 700)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'T500': levq = np.where(lev == 500)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'U700': levq = np.where(lev == 700)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'V925': levq = np.where(lev == 925)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'V700': levq = np.where(lev == 700)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'V1000': levq = np.where(lev == 1000)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -3:, :, :], axis=1) historicalm = np.nanmean(historical[:, -3:, :, :], axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -1:, :, :], axis=1) historicalm = np.nanmean(historical[:, -1:, :, :], axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future, historical] var_mo = np.empty((2, historical.shape[0] - 1, historical.shape[2], historical.shape[3])) for i in range(len(runs)): var_mo[i, :, :, :] = UT.calcDecJanFeb(runs[i], runs[i], lat, lon, 'surface', 1) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:3, :, :], axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:2, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:2, :, :], axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:4, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:4, :, :], axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:3, :, :], axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:1, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:1, :, :], axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:2, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:2, :, :], axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 2:3, :, :], axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:4, :, :], axis=1) historicalm = np.nanmean(historical[:, 2:4, :, :], axis=1) elif period == 'JJA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 5:8, :, :], axis=1) historicalm = np.nanmean(historical[:, 5:8, :, :], axis=1) else: print(ValueError('Selected wrong month period!')) ############################################################################### ############################################################################### ############################################################################### ### Calculate anomalies anom = futurem - historicalm ### Calculate ensemble mean anommean = np.nanmean(anom, axis=0) ### Calculate significance pruns = UT.calc_FDR_ttest(futurem[:, :, :], historicalm[:, :, :], 0.05) #FDR ### Select climo climo = np.nanmean(historicalm, axis=0) return lat, lon, lev, anommean, nens, pruns, climo
def SHI(simu, period): """ Script calculates the Siberian High Index """ ### Import modules import numpy as np import calc_Utilities as UT import read_CTLNQ as CONT import read_ExpMonthly as NUDG import read_ShortCoupled as COUP import read_SIT as THICK import read_SIC as CONC import read_SIT_E3SM as E3SIT import read_SIC_E3SM as E3SIC import read_OldIceExperi as OLD import read_LongCoupled as LC ### Select variable varia = 'SLP' level = 'surface' ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2030', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2060': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2060', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2090': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2090', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') ############################################################################### elif simu == 'coupled_Pd': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pd', level) ############################################################################### elif simu == 'coupled_Pi': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pi', level) ############################################################################### elif simu == 'SIT': lat, lon, lev, future = THICK.readSIT(varia, 'SIT_Fu', level) lat, lon, lev, historical = THICK.readSIT(varia, 'SIT_Pd', level) ############################################################################### elif simu == 'SIC_Pd': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pd', level) ############################################################################### elif simu == 'SIC_Pi': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pi', level) ############################################################################### elif simu == 'E3SIT': lat, lon, lev, future = E3SIT.readE3SM_SIT(varia, 'ESIT_Fu', level) lat, lon, lev, historical = E3SIT.readE3SM_SIT(varia, 'ESIT_Pd_B', level) ############################################################################### elif simu == 'E3SIC_Pd': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pd', level) elif simu == 'E3SIC_Pi': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pi', level) ############################################################################### elif simu == 'OLD': lat, lon, lev, future = OLD.readOldIceExperi(varia, 'FICT', level) lat, lon, lev, historical = OLD.readOldIceExperi(varia, 'HIT', level) ############################################################################### elif simu == 'LONG': lat, lon, lev, future = LC.readLong(varia, 'Long_Fu', level) lat, lon, lev, historical = LC.readLong(varia, 'Long_Pd', level) ############################################################################### ############################################################################### ############################################################################### ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -3:, :, :], axis=1) historicalm = np.nanmean(historical[:, -3:, :, :], axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -1:, :, :], axis=1) historicalm = np.nanmean(historical[:, -1:, :, :], axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future, historical] var_mo = np.empty((2, historical.shape[0] - 1, historical.shape[2], historical.shape[3])) for i in range(len(runs)): var_mo[i, :, :, :] = UT.calcDecJanFeb(runs[i], runs[i], lat, lon, 'surface', 1) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:3, :, :], axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:2, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:2, :, :], axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:4, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:4, :, :], axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:3, :, :], axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:1, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:1, :, :], axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:2, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:2, :, :], axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 2:3, :, :], axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:4, :, :], axis=1) historicalm = np.nanmean(historical[:, 2:4, :, :], axis=1) else: print(ValueError('Selected wrong month period!')) ############################################################################### ############################################################################### ############################################################################### ### Calculate anomalies anom = futurem - historicalm ### Meshgrid for lat,lon lon2, lat2 = np.meshgrid(lon, lat) ### Calculate SHI lonq = np.where((lon >= 80) & (lon <= 120))[0] latq = np.where((lat >= 40) & (lat <= 65))[0] anomlon = anom[:, :, lonq] anoms = anomlon[:, latq, :] lat2sq = lat2[latq, :] lat2s = lat2sq[:, lonq] shi = UT.calc_weightedAve(anoms, lat2s) print('\n========Calculated Siberian High Index========\n') return shi ### Test functions (do not use!) #shi = SHI('AA-2090','DJF')
def readData(simu, period, vari, level, latpolar): if vari == 'U700': varia = 'U' level = 'profile' else: varia = vari ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2030', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2060': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2060', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2090': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2090', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') ############################################################################### elif simu == 'coupled_Pd': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pd', level) ############################################################################### elif simu == 'coupled_Pi': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pi', level) ############################################################################### elif simu == 'SIT': lat, lon, lev, future = THICK.readSIT(varia, 'SIT_Fu', level) lat, lon, lev, historical = THICK.readSIT(varia, 'SIT_Pd', level) ############################################################################### elif simu == 'SIC_Pd': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pd', level) ############################################################################### elif simu == 'SIC_Pi': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pi', level) ############################################################################### elif simu == 'E3SIT': lat, lon, lev, future = E3SIT.readE3SM_SIT(varia, 'ESIT_Fu', level) lat, lon, lev, historical = E3SIT.readE3SM_SIT(varia, 'ESIT_Pd', level) ############################################################################### elif simu == 'E3SIC_Pd': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pd', level) elif simu == 'E3SIC_Pi': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pi', level) ############################################################################### elif simu == 'OLD': lat, lon, lev, future = OLD.readOldIceExperi(varia, 'FICT', level) lat, lon, lev, historical = OLD.readOldIceExperi(varia, 'HIT', level) ############################################################################### elif simu == 'LONG': lat, lon, lev, future = LC.readLong(varia, 'Long_Fu', level) lat, lon, lev, historical = LC.readLong(varia, 'Long_Pd', level) ############################################################################### ############################################################################### ############################################################################### ### Calculate number of ensembles nens = np.shape(historical)[0] ### Check for 4D field if vari == 'T700': levq = np.where(lev == 700)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'T500': levq = np.where(lev == 500)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() elif vari == 'U700': levq = np.where(lev == 700)[0] future = future[:, :, levq, :, :].squeeze() historical = historical[:, :, levq, :, :].squeeze() ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -3:], axis=1) historicalm = np.nanmean(historical[:, -3:], axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -1:], axis=1) historicalm = np.nanmean(historical[:, -1:], axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future, historical] var_mo = np.empty((2, historical.shape[0] - 1, historical.shape[2], historical.shape[3], historical.shape[4])) for i in range(len(runs)): var_mo[i, :, :, :, :] = UT.calcDecJanFeb(runs[i], runs[i], lat, lon, level, 17) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:3], axis=1) historicalm = np.nanmean(historical[:, 0:3], axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:2], axis=1) historicalm = np.nanmean(historical[:, 0:2], axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:4], axis=1) historicalm = np.nanmean(historical[:, 1:4], axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:3], axis=1) historicalm = np.nanmean(historical[:, 1:3], axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:1], axis=1) historicalm = np.nanmean(historical[:, 0:1], axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:2], axis=1) historicalm = np.nanmean(historical[:, 1:2], axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:3], axis=1) historicalm = np.nanmean(historical[:, 2:3], axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:4], axis=1) historicalm = np.nanmean(historical[:, 2:4], axis=1) elif period == 'annual': print('Calculating over %s months!' % period) futurem = np.nanmean(future, axis=1) historicalm = np.nanmean(historical, axis=1) elif period == 'NONE': print('Calculating over %s months!' % period) futurem = future historicalm = historical elif period == 'timemonth': print('Calculating over O,N,D,J,F,M months!') futurem = np.append(future[:, -3:, :, :], future[:, :3, :, :], axis=1) historicalm = np.append(historical[:, -3:, :, :], historical[:, :3, :, :], axis=1) else: print(ValueError('Selected wrong month period!')) ########################################################################### ########################################################################### ########################################################################### ### Calculate polar cap lon2, lat2 = np.meshgrid(lon, lat) ### Calculate zonal means futuremz = np.nanmean(futurem, axis=3) historicalmz = np.nanmean(historicalm, axis=3) ### Calculate anomalies [ens,level,lat] anom = futuremz - historicalmz ### Calculate ensemble mean anommean = np.nanmean(anom, axis=0) ### Calculate significance pruns = UT.calc_FDR_ttest(futuremz, historicalmz, 0.05) #FDR ### Select climo climo = np.nanmean(historicalmz, axis=0) return lat, lon, lev, anommean, nens, pruns, climo
def PolarCapVert(simu, varia, level, latpolar, period, levelVert): ############################################################################### ############################################################################### ############################################################################### if simu == 'AA-2030': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2030', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2060': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2060', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') elif simu == 'AA-2090': lat, lon, lev, future = NUDG.readExperi(varia, 'AA', '2090', level, 'none') lat, lon, lev, historical = CONT.readControl(varia, level, 'none') ############################################################################### elif simu == 'coupled_Pd': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pd', level) ############################################################################### elif simu == 'coupled_Pi': lat, lon, lev, future = COUP.readCOUPs(varia, 'C_Fu', level) lat, lon, lev, historical = COUP.readCOUPs(varia, 'C_Pi', level) ############################################################################### elif simu == 'SIT': lat, lon, lev, future = THICK.readSIT(varia, 'SIT_Fu', level) lat, lon, lev, historical = THICK.readSIT(varia, 'SIT_Pd', level) ############################################################################### elif simu == 'SIC_Pd': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pd', level) ############################################################################### elif simu == 'SIC_Pi': lat, lon, lev, future = CONC.readSIC(varia, 'Fu', level) lat, lon, lev, historical = CONC.readSIC(varia, 'Pi', level) ############################################################################### elif simu == 'E3SIT': lat, lon, lev, future = E3SIT.readE3SM_SIT(varia, 'ESIT_Fu', level) lat, lon, lev, historical = E3SIT.readE3SM_SIT(varia, 'ESIT_Pd_B', level) ############################################################################### elif simu == 'E3SIC_Pd': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pd', level) elif simu == 'E3SIC_Pi': lat, lon, lev, future = E3SIC.readE3SM_SIC(varia, 'ESIC_Fu', level) lat, lon, lev, historical = E3SIC.readE3SM_SIC(varia, 'ESIC_Pi', level) ############################################################################### elif simu == 'OLD': lat, lon, lev, future = OLD.readOldIceExperi(varia, 'FICT', level) lat, lon, lev, historical = OLD.readOldIceExperi(varia, 'HIT', level) ############################################################################### elif simu == 'LONG': lat, lon, lev, future = LC.readLong(varia, 'Long_Fu', level) lat, lon, lev, historical = LC.readLong(varia, 'Long_Pd', level) ############################################################################### ############################################################################### ############################################################################### ### Check for missing data [ensembles,months,lat,lon] future[np.where(future <= -1e10)] = np.nan historical[np.where(historical <= -1e10)] = np.nan ############################################################################### ############################################################################### ############################################################################### ### Calculate over period if period == 'OND': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -3:, :, :], axis=1) historicalm = np.nanmean(historical[:, -3:, :, :], axis=1) elif period == 'D': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, -1:, :, :], axis=1) historicalm = np.nanmean(historical[:, -1:, :, :], axis=1) elif period == 'DJF': print('Calculating over %s months!' % period) runs = [future, historical] var_mo = np.empty((2, historical.shape[0] - 1, historical.shape[2], historical.shape[3], historical.shape[4])) for i in range(len(runs)): var_mo[i, :, :, :, :] = UT.calcDecJanFeb(runs[i], runs[i], lat, lon, level, 17) futurem = var_mo[0] historicalm = var_mo[1] elif period == 'JFM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:3, :, :], axis=1) elif period == 'JF': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:2, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:2, :, :], axis=1) elif period == 'FMA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:4, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:4, :, :], axis=1) elif period == 'FM': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:3, :, :], axis=1) elif period == 'J': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 0:1, :, :], axis=1) historicalm = np.nanmean(historical[:, 0:1, :, :], axis=1) elif period == 'F': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 1:2, :, :], axis=1) historicalm = np.nanmean(historical[:, 1:2, :, :], axis=1) elif period == 'M': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:3, :, :], axis=1) historicalm = np.nanmean(historical[:, 2:3, :, :], axis=1) elif period == 'MA': print('Calculating over %s months!' % period) futurem = np.nanmean(future[:, 2:4, :, :], axis=1) historicalm = np.nanmean(historical[:, 2:4, :, :], axis=1) elif period == 'NONE': futurem = future historicalm = historical else: print(ValueError('Selected wrong month period!')) ############################################################################### ############################################################################### ############################################################################### ### Calculate anomalies anom = futurem - historicalm ### Meshgrid for lat,lon lon2, lat2 = np.meshgrid(lon, lat) ### Calculate SHI latq = np.where((lat >= latpolar))[0] anomp = anom[:, :, latq, :] lat2p = lat2[latq, :] polarave = UT.calc_weightedAve(anomp, lat2p) ### Calculate ensemble mean polaraveMean = np.nanmean(polarave, axis=0) ############################################################################### ############################################################################### ############################################################################### ### Calculate vertical levels and save file levqq = np.where((lev >= levelVert))[0] levvv = lev[levqq] polaraveMeanvvv = polaraveMean[levqq] ### Save file np.savetxt(directorydata + '%s_1000-%s_%s.txt' % (simu, levelVert, varia), polaraveMeanvvv, delimiter=',', fmt='%.3f') np.savetxt(directorydata + 'Levels_1000-%s_%s.txt' % (levelVert, varia), levvv, delimiter=',', fmt='%.1f') print('\n========Calculated Polar Cap Average========\n') return polaraveMeanvvv, levvv ############################################################################### ############################################################################### ############################################################################### ### Test functions (do not use!) #aveAA30,lev = PolarCapVert('AA-2030','TEMP','profile',65,'DJF',500) #aveAA60,lev = PolarCapVert('AA-2060','TEMP','profile',65,'DJF',500) #aveAA90,lev = PolarCapVert('AA-2090','TEMP','profile',65,'DJF',500) ################################################################################ #ave_coupPd,lev = PolarCapVert('coupled_Pd','TEMP','profile',65,'DJF',500) #ave_coupPi,lev = PolarCapVert('coupled_Pi','TEMP','profile',65,'DJF',500) ################################################################################ #ave_SIT,lev = PolarCapVert('SIT','TEMP','profile',65,'DJF',500) #ave_SICPd,lev = PolarCapVert('SIC_Pd','TEMP','profile',65,'DJF',500) #ave_SICPi,lev = PolarCapVert('SIC_Pi','TEMP','profile',65,'DJF',500) ############################################################################### #ave_NET,lev = PolarCapVert('OLD','TEMP','profile',65,'DJF',500) ############################################################################### #ave_ESICPd,lev = PolarCapVert('E3SIC_Pd','TEMP','profile',65,'DJF',500) #ave_ESICPi,lev = PolarCapVert('E3SIC_Pi','TEMP','profile',65,'DJF',500)