def ptype_lat_z(fg, ax, lat, HT): ''' NOTE: HT needs to be given in meter ''' ax.set_xlim(lat[85], 90) ax.set_ylim(6000,0) xl(ax,'Latitude'); yl(ax,'Depth [m]'); utils_plt.plot_topo(ax, lat, HT)
def plot_BSF(var, TorUgrid, nlevels=100, mappingtoolbox='basemap', proj='ortho', min = [], max = []): ''' uses utils_plt.emptyBasemapFig()''' # colormap if min == []: min = np.floor(np.nanmin(var)) # minimum value of varin if max == []: max = np.ceil(np.nanmax(var)) # maximum value of varin #cmap, norm = utils_plt.get_cmap(min, max, nlevels, scheme=utils_plt.get_viridis()) # viridis cmap = utils_plt.shiftCMap(ml.cm.seismic, midpoint=1-max/(max-min), name='shifted') # shifted blue white red # add cyclic border (to prevent gap in pcolor plot) var = utils_conv.add_cyclic(var) # choose U or T grid if TorUgrid == 'U': xvar = var.ULONG.values yvar = var.ULAT.values elif TorUgrid == 'T': xvar = var.TLONG.values yvar = var.TLAT.values # draw plot in new figure if mappingtoolbox == 'basemap': fig, map = utils_plt.emptyBasemapFig(proj) c1 = map.pcolor(xvar,yvar,var.values,latlon=True, cmap=cmap, rasterized=True) map.colorbar() elif mappingtoolbox == 'cartopy': fig, map = True, True#TODO return(fig, map)
def ptype_lat_z(fg, ax, lat, HT): ''' NOTE: HT needs to be given in meter ''' ax.set_xlim(lat[85], 90) ax.set_ylim(6000, 0) xl(ax, 'Latitude') yl(ax, 'Depth [m]') utils_plt.plot_topo(ax, lat, HT)
def plot_BSF(var, TorUgrid, nlevels=100, mappingtoolbox='basemap', proj='ortho', min=[], max=[]): ''' uses utils_plt.emptyBasemapFig()''' # colormap if min == []: min = np.floor(np.nanmin(var)) # minimum value of varin if max == []: max = np.ceil(np.nanmax(var)) # maximum value of varin #cmap, norm = utils_plt.get_cmap(min, max, nlevels, scheme=utils_plt.get_viridis()) # viridis cmap = utils_plt.shiftCMap(ml.cm.seismic, midpoint=1 - max / (max - min), name='shifted') # shifted blue white red # add cyclic border (to prevent gap in pcolor plot) var = utils_conv.add_cyclic(var) # choose U or T grid if TorUgrid == 'U': xvar = var.ULONG.values yvar = var.ULAT.values elif TorUgrid == 'T': xvar = var.TLONG.values yvar = var.TLAT.values # draw plot in new figure if mappingtoolbox == 'basemap': fig, map = utils_plt.emptyBasemapFig(proj) c1 = map.pcolor(xvar, yvar, var.values, latlon=True, cmap=cmap, rasterized=True) map.colorbar() elif mappingtoolbox == 'cartopy': fig, map = True, True #TODO return (fig, map)
''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # CCSM4 representations # ======================================================================================= # ----------------------------------------------------------------------------------------- # BSF on geographical grid calculated by model BSF_model = utils_mask.mask_ATLANTIC(ncdat.BSF.isel(time=0), ncdat.REGION_MASK) fig, map = utils_plt.plot_BSF(BSF_model, 'T', nlevels=10) plt.title('BSF model on T grid') utils_plt.print2pdf(fig, path_fig + 'BSF_model_T') # ----------------------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOC_model = ncdat.MOC.isel(time=0, transport_reg=1, moc_comp=0) #MOC_model = MOC_model - MOC_model[:,-1] # normalisation fig, ax = utils_plt.plot_MOC(MOC_model.lat_aux_grid, MOC_model.moc_z, MOC_model, nlevels=10, plttype='pcolor+contour') plt.plot(lat_auxgrd, HT_auxgrd_xmax) # plot seafloor plt.title('MOC model') plt.xlim([-36, 90]) utils_plt.print2pdf(fig, path_fig + 'MOC_model')
# x-axes lat_mgrd = ncdat.TLAT.isel( nlon=0) # mean of LAT for each j #! very inappropriate ax_long = np.arange(len(lat_mgrd)) # lat_mgrd # y-axes ax_vol = ax_vol_glob ticks_vol = ticks_vol_glob # dMOC_mgrd_V (in Sv) # --stretch--------------------------------------- fig, ax = utils_plt.plot_MOC(ax_long, ax_vol, dMOCm, min, max, nlevels_col, levels_cont, plttype='pcolor+contour', to_subplot=[2, 2, 1]) #plt.xlim([-36,73]) plt.title('dMOC mgrd (stretch)') plt.xlim([81, 383]) plt.yticks(ticks_vol) plt.gca().set_yticklabels(ticks_dens_rd) # --linear---------------------------------------- fig, ax = utils_plt.plot_MOC(ax_long, DBc, dMOCm, min, max,
'HU_mgrd_xmax') # load from file except: HU_mgrd_xmax = utils_mask.calc_H_mgrd_xmax(ncdat, 'U', path_mgrd) # ####################################################################################### # PLOTTING # ####################################################################################### plt.ion() # enable interactive mode path_fig = 'figures_Jun16/' # ======================================================================================= # CCSM4 representations # ======================================================================================= # ----------------------------------------------------------------------------------------- # BSF on geographical grid calculated by model BSF_model = utils_mask.mask_ATLANTIC(ncdat.BSF.isel(time=0), ncdat.REGION_MASK) fig, map = utils_plt.plot_BSF(BSF_model, 'T', nlevels=10) plt.title('BSF model on T grid') #utils_plt.print2pdf(fig, 'testfigures/BSF_model_T') # ----------------------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOC_model = ncdat.MOC.isel(time=0, transport_reg=1, moc_comp=0) MOC_model = MOC_model - MOC_model[:, -1] # normalisation fig, ax = utils_plt.plot_MOC(MOC_model.lat_aux_grid, MOC_model.moc_z, MOC_model, nlevels=40, plttype='pcolor+contour') plt.plot(lat_auxgrd, HT_auxgrd_xmax) # plot seafloor plt.title('MOC model') plt.xlim([-36, 90]) #utils_plt.print2pdf(fig, 'testfigures/MOC_model')
''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # Calculated on model grid # ======================================================================================= # ----------------------------------------------------------------------------------------- # MOC_mgrd_W fig, ax = utils_plt.plot_MOC(lat_mgrd, ncdat.z_w_top, MOC_mgrd_W, nlevels=10, plttype='pcolor+contour') plt.plot(lat_mgrd, HT_mgrd_xmax) # plot seafloor #! it's the T-grid!!! plt.title('MOC mgrd W') plt.xlim([-36, 90]) utils_plt.print2pdf(fig, path_fig + 'MOC_mgrd_W') # ----------------------------------------------------------------------------------------- # dMOC_mgrid_W(in Sv) fig, ax = utils_plt.plot_MOC(lat_mgrd, db, dMOC_mgrd_W, nlevels=10, plttype='pcolor+contour') plt.title('dMOC mgrd W (sigma2)')
TODO: add '.values' where possible to speed up code. ''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # Calculated on model grid # ======================================================================================= # ----------------------------------------------------------------------------------------- # MOC_mgrd_W fig, ax = utils_plt.plot_MOC(lat_mgrd, ncdat.z_w_top, MOC_mgrd_W, nlevels=10, plttype='pcolor+contour') plt.plot(lat_mgrd,HT_mgrd_xmax) # plot seafloor #! it's the T-grid!!! plt.title('MOC mgrd W') plt.xlim([-36,90]) utils_plt.print2pdf(fig, path_fig+'MOC_mgrd_W') # ----------------------------------------------------------------------------------------- # dMOC_mgrid_W(in Sv) fig, ax = utils_plt.plot_MOC(lat_mgrd, db, dMOC_mgrd_W, nlevels=10, plttype='pcolor+contour') plt.title('dMOC mgrd W (sigma2)') plt.suptitle('density binning from {} to {} in {} steps'.format(dbc.min(), dbc.max(), len(dbc))) plt.xlim([-36,73]) plt.yticks(ticks_vol) plt.gca().set_yticklabels(ticks_dens) #utils_plt.print2pdf(fig, path_fig+'dMOC_mgrd_W_sig2')
''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # Calculated on model grid # ======================================================================================= # ----------------------------------------------------------------------------------------- # MOC_mgrd_V fig, ax = utils_plt.plot_MOC(lat_mgrd, ncdat.z_t, MOC_mgrd_V, nlevels=100, plttype='pcolor+contour') plt.plot(lat_mgrd,HT_mgrd_xmax) # plot seafloor plt.title('MOC mgrd V') plt.xlim([-36,90]) #utils_plt.print2pdf(fig, path_fig+'MOC_mgrd_V') # ----------------------------------------------------------------------------------------- # dMOC_mgrid_V (in Sv) fig, ax = utils_plt.plot_MOC(lat_mgrd, dbc, dMOC_mgrd_V, nlevels=10, plttype='pcolor+contour') plt.title('dMOC mgrd W (sigma2)') plt.suptitle('density binning from {} to {} in {} steps'.format(dbc.min(), dbc.max(), len(dbc))) plt.xlim([-36,73]) plt.yticks(ticks_vol_glob) plt.gca().set_yticklabels(ticks_dens) #utils_plt.print2pdf(fig, path_fig+'dMOC_mgrd_V_sig2') # =======================================================================================
except: HU_auxgrd_xmax = utils_mask.calc_H_auxgrd_xmax(lat_auxgrd, ncdat, 'U', path_auxgrd) try: HU_mgrd_xmax = utils_misc.loadvar(path_mgrd+'HU_mgrd_xmax') # load from file except: HU_mgrd_xmax = utils_mask.calc_H_mgrd_xmax(ncdat, 'U', path_mgrd) # ####################################################################################### # PLOTTING # ####################################################################################### plt.ion() # enable interactive mode path_fig = 'figures_Jun16/' # ======================================================================================= # CCSM4 representations # ======================================================================================= # ----------------------------------------------------------------------------------------- # BSF on geographical grid calculated by model BSF_model = utils_mask.mask_ATLANTIC(ncdat.BSF.isel(time=0), ncdat.REGION_MASK) fig, map = utils_plt.plot_BSF(BSF_model, 'T', nlevels = 10) plt.title('BSF model on T grid') #utils_plt.print2pdf(fig, 'testfigures/BSF_model_T') # ----------------------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOC_model = ncdat.MOC.isel(time=0, transport_reg=1, moc_comp=0) MOC_model = MOC_model - MOC_model[:,-1] # normalisation fig, ax = utils_plt.plot_MOC(MOC_model.lat_aux_grid, MOC_model.moc_z, MOC_model, nlevels=40, plttype='pcolor+contour') plt.plot(lat_auxgrd,HT_auxgrd_xmax) # plot seafloor plt.title('MOC model') plt.xlim([-36,90]) #utils_plt.print2pdf(fig, 'testfigures/MOC_model') # ======================================================================================= # Calculated on model grid # =======================================================================================
''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # BSF / MOC # ======================================================================================= var = MV[0,:,:] var[190:300,-65:-45] = np.zeros_like(var[190:300,-65:-45]) fig, map = utils_plt.plot_BSF(var, 'T', nlevels = 10) # ----------------------------------------------------------------------------------------- # BSF on geographical grid calculated by model BSF_model = utils_mask.mask_ATLANTIC(ncdat.BSF.isel(time=0), ncdat.REGION_MASK) fig, map = utils_plt.plot_BSF(BSF_model, 'T', nlevels = 10) plt.title('BSF model on T grid') utils_plt.print2pdf(fig, path_fig+'BSF_model_T') # ----------------------------------------------------------------------------------------- # BSF on model grid fig, map = utils_plt.plot_BSF(BSF_mmgrd, 'U', nlevels=100) plt.title('BSF mgrd on U grid') utils_plt.print2pdf(fig, 'testfigures/BSF_mgrd_U') # ----------------------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOC_model = ncdat.MOC.isel(time=0, transport_reg=1, moc_comp=0)
TODO: add '.values' where possible to speed up code. ''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # BSF / MOC # ======================================================================================= var = MV[0, :, :] var[190:300, -65:-45] = np.zeros_like(var[190:300, -65:-45]) fig, map = utils_plt.plot_BSF(var, 'T', nlevels=10) # ----------------------------------------------------------------------------------------- # BSF on geographical grid calculated by model BSF_model = utils_mask.mask_ATLANTIC(ncdat.BSF.isel(time=0), ncdat.REGION_MASK) fig, map = utils_plt.plot_BSF(BSF_model, 'T', nlevels=10) plt.title('BSF model on T grid') utils_plt.print2pdf(fig, path_fig + 'BSF_model_T') # ----------------------------------------------------------------------------------------- # BSF on model grid fig, map = utils_plt.plot_BSF(BSF_mmgrd, 'U', nlevels=100) plt.title('BSF mgrd on U grid') utils_plt.print2pdf(fig, 'testfigures/BSF_mgrd_U') # ----------------------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOC_model = ncdat.MOC.isel(time=0, transport_reg=1, moc_comp=0)
import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ----------------------------------------------------------------------------------------- # COMBINATION of MWxint_auxgrd and MOC_auxgrd fig = plt.figure() plt.suptitle('density binning from {} to {} in {} steps'.format( dbc.min(), dbc.max(), len(dbc))) plt.subplot(3, 1, 1) plt.title('MOC on depth axis on auxgrd') ax = utils_plt.plot_MOC(lat_auxgrd, z_w_auxgrd, MOC_auxgrd_W, nlevels=10, plttype='pcolor+contour', to_newfigure=False) plt.plot(lat_auxgrd, HT_auxgrd_xmax) # plot seafloor plt.xlim([-36, 90]) plt.subplot(3, 1, 2) plt.title('MW on depth axis longitudinally integrated on auxgrd (in Sv)') plt.ylabel('depth') ax = utils_plt.plot_MOC(lat_auxgrd, z_w_auxgrd, MWxint_auxgrd, nlevels=10, plttype='pcolor+contour', to_newfigure=False) plt.plot(lat_auxgrd, HT_auxgrd_xmax) # plot seafloor
''' import matplotlib.pyplot as plt import matplotlib as ml import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ======================================================================================= # CCSM4 representations # ======================================================================================= # ----------------------------------------------------------------------------------------- # BSF on geographical grid calculated by model BSF_model = utils_mask.mask_ATLANTIC(ncdat.BSF.isel(time=0), ncdat.REGION_MASK) fig, map = utils_plt.plot_BSF(BSF_model, 'T', nlevels = 10) plt.title('BSF model on T grid') utils_plt.print2pdf(fig, path_fig+'BSF_model_T') # ----------------------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOC_model = ncdat.MOC.isel(time=0, transport_reg=1, moc_comp=0) #MOC_model = MOC_model - MOC_model[:,-1] # normalisation fig, ax = utils_plt.plot_MOC(MOC_model.lat_aux_grid, MOC_model.moc_z, MOC_model, nlevels=10, plttype='pcolor+contour') plt.plot(lat_auxgrd,HT_auxgrd_xmax) # plot seafloor plt.title('MOC model') plt.xlim([-36,90]) utils_plt.print2pdf(fig, path_fig+'MOC_model') # ======================================================================================= # Calculated on model grid # =======================================================================================
try: HU_mgrd_xmax = utils_misc.loadvar(path_grd + 'HU_mgrd_xmax') # load from file except: HU_mgrd_xmax = utils_mask.calc_H_mgrd_xmax(ncdat, 'U', path_grd) # ============================================================================= # Streamfunctions # ============================================================================= lat_mgrd = ncdat.TLAT.isel( nlon=0) # mean of LAT for each j #! very inappropriate # ----------------------------------------------------------------------------- # BSF on geographical grid calculated by model fig, map = utils_plt.plot_BSF(BSF.isel(time=0), 'T', nlevels=10) plt.title('BSF model on T grid') #utils_plt.print2pdf(fig, 'testfigures/BSF_model_T') # ----------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOCsel = MOC.isel(time=0) fig, ax = utils_plt.plot_MOC(MOCsel.lat_aux_grid, MOCsel.moc_z, MOCsel, nlevels=40, plttype='pcolor+contour') plt.plot(lat_mgrd, HT_auxgrd_xmax) # plot seafloor plt.title('MOC model') plt.xlim([-36, 90]) #utils_plt.print2pdf(fig, path_figs+'MOC_model')
method = '0' dMOCm = dMOC_mgrd_V_0 dMOCaux = dMOC_auxgrd_V_0 # x-axes lat_mgrd = ncdat.TLAT.isel(nlon=0) # mean of LAT for each j #! very inappropriate ax_long = np.arange(len(lat_mgrd)) # lat_mgrd # y-axes ax_vol = ax_vol_glob ticks_vol = ticks_vol_glob # dMOC_mgrd_V (in Sv) # --stretch--------------------------------------- fig, ax = utils_plt.plot_MOC(ax_long, ax_vol, dMOCm, min, max, nlevels_col, levels_cont, plttype='pcolor+contour', to_subplot=[2,2,1]) #plt.xlim([-36,73]) plt.title('dMOC mgrd (stretch)') plt.xlim([81,383]) plt.yticks(ticks_vol) plt.gca().set_yticklabels(ticks_dens_rd) # --linear---------------------------------------- fig, ax = utils_plt.plot_MOC(ax_long, DBc, dMOCm, min, max, nlevels_col, levels_cont, plttype='pcolor+contour', to_newfig=False, to_subplot=[2,2,2]) plt.title('dMOC mgrd (linear)') plt.xlim([81,383]) plt.ylim([38,30]) # dMOCaux (in Sv) # --stretch--------------------------------------- fig, ax = utils_plt.plot_MOC(lat_auxgrd, ax_vol, dMOCaux, min, max, nlevels_col, levels_cont, plttype='pcolor+contour', to_newfig=False, to_subplot=[2,2,3]) plt.title('dMOC auxgrd (stretch)')
import CESM_utils_plt as utils_plt plt.ion() # enable interactive mode path_fig = '../figures/160711/' # ----------------------------------------------------------------------------------------- # COMBINATION of MWxint_auxgrd and MOC_auxgrd fig = plt.figure() plt.suptitle('density binning from {} to {} in {} steps'.format(dbc.min(), dbc.max(), len(dbc))) plt.subplot(3,1,1) plt.title('MOC on depth axis on auxgrd') ax = utils_plt.plot_MOC(lat_auxgrd, z_w_auxgrd, MOC_auxgrd_W, nlevels=10, plttype='pcolor+contour', to_newfigure=False) plt.plot(lat_auxgrd,HT_auxgrd_xmax) # plot seafloor plt.xlim([-36,90]) plt.subplot(3,1,2) plt.title('MW on depth axis longitudinally integrated on auxgrd (in Sv)') plt.ylabel('depth') ax = utils_plt.plot_MOC(lat_auxgrd, z_w_auxgrd, MWxint_auxgrd, nlevels=10, plttype='pcolor+contour', to_newfigure=False) plt.plot(lat_auxgrd,HT_auxgrd_xmax) # plot seafloor plt.xlim([-36,90]) plt.subplot(3,1,3) plt.plot(lat_auxgrd, np.nansum(MWxint_auxgrd,axis=0), '.-k') plt.colorbar() plt.xlim([-36,90]) plt.ylabel('sum over whole density-axis (in Sv)')
# ============================================================================= try: HT_mgrd_xmax = utils_misc.loadvar(path_grd+'HT_mgrd_xmax') # load from file except: HT_mgrd_xmax = utils_mask.calc_H_mgrd_xmax(ncdat, 'T', path_grd) try: HU_mgrd_xmax = utils_misc.loadvar(path_grd+'HU_mgrd_xmax') # load from file except: HU_mgrd_xmax = utils_mask.calc_H_mgrd_xmax(ncdat, 'U', path_grd) # ============================================================================= # Streamfunctions # ============================================================================= lat_mgrd = ncdat.TLAT.isel(nlon=0) # mean of LAT for each j #! very inappropriate # ----------------------------------------------------------------------------- # BSF on geographical grid calculated by model fig, map = utils_plt.plot_BSF(BSF.isel(time=0), 'T', nlevels = 10) plt.title('BSF model on T grid') #utils_plt.print2pdf(fig, 'testfigures/BSF_model_T') # ----------------------------------------------------------------------------- # MOC on geographical grid calculated by model MOCsel = MOC.isel(time=0) fig, ax = utils_plt.plot_MOC(MOCsel.lat_aux_grid, MOCsel.moc_z, MOCsel, nlevels=40, plttype='pcolor+contour') plt.plot(lat_mgrd, HT_auxgrd_xmax) # plot seafloor plt.title('MOC model') plt.xlim([-36,90]) #utils_plt.print2pdf(fig, path_figs+'MOC_model') # ============================================================================= # Streamfunction Indices # =============================================================================