def plt_spatial_seasonal_mean(variable, variable_id, add_colorbar=None, title=None):
    fig, axsm = plt.subplots(
        2, 2, figsize=[10, 7], subplot_kw={"projection": ccrs.PlateCarree()}
    )
    fig.suptitle(title, fontsize=16, fontweight="bold")
    axs = axsm.flatten()
    for ax, i in zip(axs, variable.season):
        im = variable.sel(season=i,).plot.contourf(
            ax=ax,
            transform=ccrs.PlateCarree(),
            cmap=cm.devon_r,
            robust=True,
            vmin=plt_dict[variable_id][plt_dict["header"].index("vmin")],
            vmax=plt_dict[variable_id][plt_dict["header"].index("vmax")],
            levels=plt_dict[variable_id][plt_dict["header"].index("levels")],
            extend="max",
            add_colorbar=add_colorbar,
        )

        ax.coastlines()
        gl = ax.gridlines()
        ax.add_feature(cy.feature.BORDERS)
        gl.top_labels = False
        ax.set_title("season: {}".format(i.values))

    plt.tight_layout()
    fig.subplots_adjust(top=0.88)

    return (
        fig,
        axs,
        im,
    )
def plt_diff_seasonal(
    true_var, estimated_var, cbar_label, vmin=None, vmax=None, levels=None, title=None
):

    fig, axsm = plt.subplots(
        2, 2, figsize=[10, 7], subplot_kw={"projection": ccrs.PlateCarree()}
    )
    fig.suptitle(title, fontsize=16, fontweight="bold")

    axs = axsm.flatten()
    for ax, i in zip(axs, true_var.season):
        im = (
            (true_var - estimated_var)
            .sel(season=i)
            .plot.contourf(
                ax=ax,
                transform=ccrs.PlateCarree(),
                cmap=cm.bam,
                robust=True,
                add_colorbar=False,
                extend="both",
                vmin=vmin,
                vmax=vmax,
                levels=levels,
            )
        )
        # Plot cosmetics
        ax.coastlines()
        gl = ax.gridlines()
        ax.add_feature(cy.feature.BORDERS)
        gl.top_labels = False
        ax.set_title("season: {}".format(i.values))

    # colorbar
    fig.subplots_adjust(right=0.8)
    cbar_ax = fig.add_axes([1, 0.15, 0.025, 0.7])
    cb = fig.colorbar(im, cax=cbar_ax, orientation="vertical", fraction=0.046, pad=0.04)
    # set cbar label
    cb.set_label(label=cbar_label, weight="bold")

    plt.tight_layout()
    fig.subplots_adjust(top=1)

    return axs
Ejemplo n.º 3
0
def plt_mean_std_var_skew_kurt(var):
    """Plots the mean, standard deviation, variance, skewness and kurtosis for a given variable.
    
    Parameters:
    -----------
    var         : xarray variable to be plotted
    """
    f, axsm = sp_map(3, 2, figsize=[18, 8])
    axs = axsm.flatten()

    stat = ['Mean', 'Std', 'Variance', 'Skewness', 'Kurtosis']
    # Mean
    var.mean('time', keep_attrs=True).plot(ax=axs[0],
                                           transform=ccrs.PlateCarree(),
                                           robust=True)

    # STD
    var.std('time', keep_attrs=True).plot(ax=axs[1],
                                          transform=ccrs.PlateCarree(),
                                          robust=True)

    # Var
    var.var('time', keep_attrs=True).plot(ax=axs[2],
                                          transform=ccrs.PlateCarree(),
                                          robust=True)

    # skewness
    var.reduce(stats.skew, dim=('time'),
               keep_attrs=True).plot(ax=axs[3],
                                     transform=ccrs.PlateCarree(),
                                     robust=True)

    # kurtosis
    var.reduce(stats.kurtosis, dim=('time'),
               keep_attrs=True).plot(ax=axs[4],
                                     transform=ccrs.PlateCarree(),
                                     robust=True)

    axs[5].axis('off')
    for ax, i in zip(axs, range(len(stat))):
        ax.coastlines()
        ax.set_title(stat[i])

    plt.tight_layout()
Ejemplo n.º 4
0
def plotaodobs():
    dpi = 100
    resolution = '50m'
    plt.figure(figsize=(4,4))
    ortho = ccrs.Orthographic(central_longitude=-40, central_latitude=74)
    ax = plt.axes(projection=ortho)
    ax.coastlines(resolution='50m')
    ax.stock_img()
    ax.gridlines(color='white')
    x = [0,0,10,10]
    y = [78,74,74,78]
    geo = ccrs.Geodetic()
    ax.set_extent([-180, 360, 45, 90])
    ax.fill(x, y, color='orange', transform=geo, alpha=1)
    ax.annotate('Swath', xy=(-20,83), xycoords=ccrs.PlateCarree()._as_mpl_transform(ax), fontsize=18, color='orange')
    ax.scatter(16.1, 69.28, marker='o', c='r', transform=geo)
    ax.annotate('Andenes \n$69.28^{\circ}$ N \n$16.10^{\circ}$ W',xy=(-30,60),xycoords=ccrs.PlateCarree()._as_mpl_transform(ax),fontsize=16,color='red')
Ejemplo n.º 5
0
def plotbcobs():
    ## Define geolocations for the two stations
    ## Summit
    sumlat = 72.58
    sumlon = -38.48
    ## Alert
    alelat = 82.5
    alelon = -62.34
    dpi = 100
    resolution = '50m'
    plt.figure(figsize=(4,4))
    ortho = ccrs.Orthographic(central_longitude=sumlon, central_latitude=sumlat)
    ax = plt.axes(projection=ortho)
    ax.coastlines(resolution='50m')
    ax.stock_img()
    ax.gridlines(color='white')
    lons = [sumlon,alelon]
    lats = [sumlat,alelat]
    geo = ccrs.Geodetic()
    ax.set_extent([-180, 360, 45, 90])
    ax.scatter(lons, lats, marker='o', c='r', transform=geo)
    ax.annotate('Summit \n$72.58^{\circ}$ N, \n$38.48^{\circ}$ W', xy=(sumlon+4,sumlat-6), xycoords=ccrs.PlateCarree()._as_mpl_transform(ax), fontsize=16, color='red')
    ax.annotate('Alert \n$82.50^{\circ}$ N, \n$62.34^{\circ}$ W', xy=(alelon+0.5,alelat+1.1), xycoords=ccrs.PlateCarree()._as_mpl_transform(ax), fontsize=16, color='red')
Ejemplo n.º 6
0
def plot_pibc_aod():
    ##NorESM
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/NorESM2_diff_od550aer.nc'
    nor_diff = xr.open_dataset(path)
    ##UKESM
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/UKESM1_diff_od550aer.nc'
    uk_diff = xr.open_dataset(path)
    ##CNRM
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/CNRM_diff_od550aer.nc'
    cnrm_diff = xr.open_dataset(path)
    
    ## Define some variable names so that calling them is easier
    lat = 'lat'
    lon = 'lon'
    time = 'time'
    aod = 'od550aer' #aerosol optical depth
    
    ## We can choose different seasons to visualize:
    _nor_sum = nor_diff[aod][{time:2}]
    _uk_sum = uk_diff[aod][{time:2}]
    _cnrm_sum = cnrm_diff[aod][{time:2}]
    _nor_win = nor_diff[aod][{time:0}]
    _uk_win = uk_diff[aod][{time:0}]
    _cnrm_win = cnrm_diff[aod][{time:0}]
    
    ## Plot the fields
    f = plt.figure(figsize=(10,7))
    
    ax1 = plt.subplot(231,projection=cy.crs.NorthPolarStereo())
    ax1.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax1.gridlines()
    ax1.coastlines()
    ax1.set_title('NorESM2-LM (DJF)')
    cb = _nor_win.plot(ax=ax1,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-0.025,vmax=0.025,cmap='bwr')
    
    ax2 = plt.subplot(232,projection=cy.crs.NorthPolarStereo())
    ax2.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax2.gridlines()
    ax2.coastlines()
    ax2.set_title('UKESM1-0-LL (DJF)')
    _uk_win.plot(ax=ax2,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-0.025,vmax=0.025,cmap='bwr')
    
    ax3 = plt.subplot(233,projection=cy.crs.NorthPolarStereo())
    ax3.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax3.gridlines()
    ax3.coastlines()
    ax3.set_title('CNRM-ESM2 (DJF)')
    _cnrm_win.plot(ax=ax3,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-0.025,vmax=0.025,cmap='bwr')
    
    ax4 = plt.subplot(234,projection=cy.crs.NorthPolarStereo())
    ax4.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax4.gridlines()
    ax4.coastlines()
    ax4.set_title('NorESM2-LM (JJA)')
    _nor_sum.plot(ax=ax4,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-0.025,vmax=0.025,cmap='bwr')
    
    ax5 = plt.subplot(235,projection=cy.crs.NorthPolarStereo())
    ax5.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax5.gridlines()
    ax5.coastlines()
    ax5.set_title('UKESM1-0-LL (JJA)')
    _uk_sum.plot(ax=ax5,transform=ccrs.PlateCarree(),add_colorbar=False,add_labels=False,vmin=-0.025,vmax=0.025,cmap='bwr')
    
    ax6 = plt.subplot(236,projection=cy.crs.NorthPolarStereo())
    ax6.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax6.gridlines()
    ax6.coastlines()
    ax6.set_title('CNRM-ESM2 (JJA)')
    _cnrm_sum.plot(ax=ax6,transform=ccrs.PlateCarree(),add_colorbar=False,add_labels=False,vmin=-0.025,vmax=0.025,cmap='bwr')
    
    f.subplots_adjust(right=0.88)
    cbar_ax = f.add_axes([0.9, 0.15, 0.01, 0.7])
    f.colorbar(cb, cax=cbar_ax)
    cbar_ax.set_ylabel('$\Delta AOD$')
Ejemplo n.º 7
0
def plot_pibc_tas():
    ##NorESM
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/NorESM2_pi-bc_tas.nc'
    ds_nor = xr.open_dataset(path)
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/NorESM2_picontrol_tas.nc'
    dsc_nor = xr.open_dataset(path)
    ##UKESM
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/UKESM1_pi-bc_tas.nc'
    ds_uk = xr.open_dataset(path)
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/UKESM1_picontrol_tas.nc'
    dsc_uk = xr.open_dataset(path)
    ##CNRM
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/CNRM_picontrol_tas.nc'
    dsc_cnrm = xr.open_dataset(path)
    path = '~/shared-ns1000k/dataporten-home/8dec3597-2d9337-2d41e5-2d9a21-2d71ca64bb7a8c/PIBC_experiment/CNRM_pi-bc_tas.nc'
    ds_cnrm = xr.open_dataset(path)
    
    ## Define some variable names so that calling them is easier
    lat = 'lat'
    lon = 'lon'
    time = 'time'
    tas = 'tas' #temperature at surface
    
    ## Calculate the differences between the experiment and the control run:
    nor_diff = ds_nor - dsc_nor
    uk_diff = ds_uk - dsc_uk
    cnrm_diff = ds_cnrm - dsc_cnrm
    
    ## We can choose different seasons to visualize:
    _nor_sum = nor_diff[tas][{time:2}]
    _uk_sum = uk_diff[tas][{time:2}]
    _cnrm_sum = cnrm_diff[tas][{time:2}]
    _nor_win = nor_diff[tas][{time:0}]
    _uk_win = uk_diff[tas][{time:0}]
    _cnrm_win = cnrm_diff[tas][{time:0}]
    
    ## Plot the fields
    f = plt.figure(figsize=(10,7))
    
    ax1 = plt.subplot(231,projection=cy.crs.NorthPolarStereo())
    ax1.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax1.gridlines()
    ax1.coastlines()
    ax1.set_title('NorESM2-LM (DJF)')
    cb = _nor_win.plot(ax=ax1,transform=ccrs.PlateCarree(),clim=(-0.1,0.01),add_colorbar=False,add_labels=False,vmin=-2.5,vmax=2.5,cmap='bwr')
    
    ax2 = plt.subplot(232,projection=cy.crs.NorthPolarStereo())
    ax2.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax2.gridlines()
    ax2.coastlines()
    ax2.set_title('UKESM1-0-LL (DJF)')
    _uk_win.plot(ax=ax2,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-2.5,vmax=2.5,cmap='bwr')
    
    ax3 = plt.subplot(233,projection=cy.crs.NorthPolarStereo())
    ax3.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax3.gridlines()
    ax3.coastlines()
    ax3.set_title('CNRM-ESM2 (DJF)')
    _cnrm_win.plot(ax=ax3,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-2.5,vmax=2.5,cmap='bwr')
    
    ax4 = plt.subplot(234,projection=cy.crs.NorthPolarStereo())
    ax4.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax4.gridlines()
    ax4.coastlines()
    ax4.set_title('NorESM2-LM (JJA)')
    _nor_sum.plot(ax=ax4,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-2.5,vmax=2.5,cmap='bwr')
    
    ax5 = plt.subplot(235,projection=cy.crs.NorthPolarStereo())
    ax5.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax5.gridlines()
    ax5.coastlines()
    ax5.set_title('UKESM1-0-LL (JJA)')
    _uk_sum.plot(ax=ax5,transform=ccrs.PlateCarree(),clim=(-0.01,0.01),add_colorbar=False,add_labels=False,vmin=-2.5,vmax=2.5,cmap='bwr')
    
    ax6 = plt.subplot(236,projection=cy.crs.NorthPolarStereo())
    ax6.set_extent((-180, 180, 60, 90), crs=cy.crs.PlateCarree())
    ax6.gridlines()
    ax6.coastlines()
    ax6.set_title('CNRM-ESM2 (JJA)')
    _cnrm_sum.plot(ax=ax6,transform=ccrs.PlateCarree(),clim=(-0.1,0.1),add_colorbar=False,add_labels=False,vmin=-2.5,vmax=2.5,cmap='bwr')
    
    f.subplots_adjust(right=0.88)
    cbar_ax = f.add_axes([0.9, 0.15, 0.01, 0.7])
    f.colorbar(cb, cax=cbar_ax)
    cbar_ax.set_ylabel('$\Delta T$ [K]')
Ejemplo n.º 8
0
def sp_map(*nrs, projection=ccrs.PlateCarree(), **kwargs):
    """This creates a plot in PlateCarree"""

    return plt.subplots(*nrs, subplot_kw={'projection': projection}, **kwargs)
Ejemplo n.º 9
0
def plt_stat_season(variable, stat, starty, endy):
    """Plots the seasonal statistics of the chosen statistic
    
    Parameters:
    -----------
    variable    : xarray variable to be plotted
    stat        : defines the statistics to plot,
                  must be: 'mean', 'st', 'var', 'skew', 'kur' 
    starty      : string of analysis begin
    endy        : string of analysis end
    """

    f, axsm = sp_map(2, 2, figsize=[18, 8])
    axs = axsm.flatten()

    for sea, ax in zip(
            variable.groupby('time.season').sum('time').season, axs.flatten()):
        if stat == 'mean':
            _title = 'Mean'
            im = variable.sel(time=(variable['time.season'] == sea), ).mean(
                'time', keep_attrs=True).plot(ax=ax,
                                              transform=ccrs.PlateCarree(),
                                              robust=True,
                                              add_colorbar=False)
        if stat == 'std':
            _title = 'Standard deviation'
            im = variable.sel(time=(variable['time.season'] == sea), ).std(
                'time', keep_attrs=True).plot(ax=ax,
                                              transform=ccrs.PlateCarree(),
                                              robust=True,
                                              add_colorbar=False)

        if stat == 'var':
            _title = 'Variance'
            im = variable.sel(time=(variable['time.season'] == sea), ).var(
                'time', keep_attrs=True).plot(ax=ax,
                                              transform=ccrs.PlateCarree(),
                                              robust=True,
                                              add_colorbar=False)
        if stat == 'skew':
            _title = 'Skewness'
            im = variable.sel(time=(variable['time.season'] == sea), ).reduce(
                stats.skew, dim=('time'),
                keep_attrs=True).plot(ax=ax,
                                      transform=ccrs.PlateCarree(),
                                      robust=True,
                                      add_colorbar=False)

        if stat == 'kur':
            _title = 'Kurtosis'
            im = variable.sel(time=(variable['time.season'] == sea), ).reduce(
                stats.kurtosis, dim=('time'),
                keep_attrs=True).plot(ax=ax,
                                      transform=ccrs.PlateCarree(),
                                      robust=True,
                                      add_colorbar=False)

        ax.coastlines()

    f.subplots_adjust(right=0.8, top=0.9)
    f.suptitle('%s %s - %s' % (_title, starty, endy), fontweight='bold')
    cbar_ax = f.add_axes([0.85, 0.15, 0.025, 0.7])
    f.colorbar(im, cax=cbar_ax, extend='both',
               format='%.0e').ax.set_ylabel(variable.attrs['long_name'] +
                                            ' [' + variable.attrs['units'] +
                                            ']')
    plt.tight_layout()
print('Coordinates:', fn['clw'].coords)

# I see from the coordinate 'time', that it is only in the middle of the month. This means my data must have monthly averages. 

print('Variables:',  fn['clw'].var)

# ## Cloud water content
# Show attributes! Keep track of what is in my dataset (especially 'units' and 'standard_name'/'long_name').

fn['clw'].clw.attrs

# Let's plot clw at time step 0 in the middle of the atmosphere (lev = 0.5 -> 32/2)

f, ax = fct.sp_map(1, figsize = [8,5])
fn['clw'].clw.isel(time = 0, lev = 16).plot.pcolormesh(ax = ax, 
                                                transform = ccrs.PlateCarree(),
                                                )
ax.coastlines();

# I see the mass fraction of CLW is small (10$^{-8}$ kg kg$^{-1}$). Only one dot over Australia in the middle atmosphere for January 1980. 
#
# Let's have a look how the CLW mean looks for the year 1990.

f, ax = fct.sp_map(1, figsize = [8,5])
fn['clw'].clw.sel(time = slice('1990-01', '1990-12')).isel(lev = 16).mean(['time'], keep_attrs = True).plot.pcolormesh(ax = ax, 
                                                transform = ccrs.PlateCarree(),
                                                )
ax.coastlines();


# The appearance of CLW increased. I see more dots in the Southern Pacific and some more over China and India for the middle of the atmosphere. It might be useful to sum up the CLW over the column and see if I get more CLW, since it is still 10$^{-8}$ kg kg$^{-1}$.