示例#1
0
def three_plot(ax, t2m, u10m, v10m, prmsl):
    ax.set_xlim(-180, 180)
    ax.set_ylim(-90, 90)
    ax.set_aspect('auto')
    ax.set_axis_off()  # Don't want surrounding x and y axis
    ax.add_patch(
        Rectangle((0, 0),
                  1,
                  1,
                  facecolor=(0.6, 0.6, 0.6, 1),
                  fill=True,
                  zorder=1))
    # Draw lines of latitude and longitude
    draw_lat_lon(ax)
    # Add the continents
    mask_pc = plot_cube(0.05)
    lsmask = iris.load_cube("%s/fixed_fields/land_mask/opfc_global_2019.nc" %
                            os.getenv('SCRATCH'))
    lsmask = lsmask.regrid(mask_pc, iris.analysis.Linear())
    lats = lsmask.coord('latitude').points
    lons = lsmask.coord('longitude').points
    mask_img = ax.pcolorfast(lons,
                             lats,
                             lsmask.data,
                             cmap=matplotlib.colors.ListedColormap(
                                 ((0.4, 0.4, 0.4, 0), (0.4, 0.4, 0.4, 1))),
                             vmin=0,
                             vmax=1,
                             alpha=1.0,
                             zorder=20)

    # Calculate the wind noise
    wind_pc = plot_cube(0.5)
    cs = iris.coord_systems.RotatedGeogCS(90, 180, 0)
    rw = iris.analysis.cartography.rotate_winds(u10m, v10m, cs)
    u10m = rw[0].regrid(wind_pc, iris.analysis.Linear())
    v10m = rw[1].regrid(wind_pc, iris.analysis.Linear())
    wind_noise_field = wind_field(u10m, v10m, z, sequence=None, epsilon=0.01)

    # Plot the temperature
    t2m_pc = plot_cube(0.05)
    t2m = t2m.regrid(t2m_pc, iris.analysis.Linear())
    t2m = quantile_normalise_t2m(t2m)
    # Adjust to show the wind
    wscale = 200
    s = wind_noise_field.data.shape
    wind_noise_field.data = qcut(
        wind_noise_field.data.flatten(),
        wscale,
        labels=False,
        duplicates='drop').reshape(s) - (wscale - 1) / 2

    # Plot as a colour map
    wnf = wind_noise_field.regrid(t2m, iris.analysis.Linear())
    t2m_img = ax.pcolorfast(lons,
                            lats,
                            t2m.data * 200 + wnf.data,
                            cmap='RdYlBu_r',
                            alpha=0.8,
                            zorder=100)

    # Plot the prmsl
    prmsl_pc = plot_cube(0.25)
    prmsl = prmsl.regrid(prmsl_pc, iris.analysis.Linear())
    lats = prmsl.coord('latitude').points
    lons = prmsl.coord('longitude').points
    lons, lats = numpy.meshgrid(lons, lats)
    CS = ax.contour(lons,
                    lats,
                    prmsl.data * 0.01,
                    colors='black',
                    linewidths=0.5,
                    alpha=1.0,
                    levels=numpy.arange(870, 1050, 10),
                    zorder=200)
示例#2
0
parser.add_argument("--opdir", help="Directory for output files",
                    default="%s/images/20CRv2c_global_4var" % \
                                           os.getenv('SCRATCH'),
                    type=str,required=False)

args = parser.parse_args()
if not os.path.isdir(args.opdir):
    os.makedirs(args.opdir)

dte = datetime.datetime(args.year, args.month, args.day, int(args.hour),
                        int(args.hour % 1 * 60))

# Load the model data - dealing sensibly with missing fields
t2m = twcr.load('air.2m', dte, version='2c')
t2m = t2m.extract(iris.Constraint(member=1))
t2m = quantile_normalise_t2m(t2m)

u10m = twcr.load('uwnd.10m', dte, version='2c')
u10m = u10m.extract(iris.Constraint(member=1))
v10m = twcr.load('vwnd.10m', dte, version='2c')
v10m = v10m.extract(iris.Constraint(member=1))
prmsl = twcr.load('prmsl', dte, version='2c')
prmsl = prmsl.extract(iris.Constraint(member=1))

mask = iris.load_cube("%s/fixed_fields/land_mask/opfc_global_2019.nc" %
                      os.getenv('SCRATCH'))

# Define the figure (page size, background color, resolution, ...
fig = Figure(
    figsize=(19.2, 10.8),  # Width, Height (inches)
    dpi=100,
示例#3
0
def three_plot(ax,t2m,u10m,v10m,prmsl,ls):
    ax.set_xlim(-180,180)
    ax.set_ylim(-90,90)
    ax.set_aspect('auto')
    ax.set_axis_off() # Don't want surrounding x and y axis
    ax.add_patch(Rectangle((0,0),1,1,facecolor=(0.6,0.6,0.6,1),
                                               fill=True,zorder=1))
    # Draw lines of latitude and longitude
    draw_lat_lon(ax)
    # Add the continents
    mask_pc = plot_cube(0.05)   
    lsmask = iris.load_cube("%s/fixed_fields/land_mask/opfc_global_2019.nc" % os.getenv('SCRATCH'))
    lsmask = lsmask.regrid(mask_pc,iris.analysis.Linear())
    lats = lsmask.coord('latitude').points
    lons = lsmask.coord('longitude').points
    mask_img = ax.pcolorfast(lons, lats, lsmask.data,
                             cmap=matplotlib.colors.ListedColormap(
                                    ((0.4,0.4,0.4,0),
                                     (0.4,0.4,0.4,1))),
                             vmin=0,
                             vmax=1,
                             alpha=1.0,
                             zorder=20)
    
    # Calculate the wind noise
    wind_pc=plot_cube(0.2)   
    cs=iris.coord_systems.RotatedGeogCS(90,180,0)
    rw=iris.analysis.cartography.rotate_winds(u10m,v10m,cs)
    u10m = rw[0].regrid(wind_pc,iris.analysis.Linear())
    v10m = rw[1].regrid(wind_pc,iris.analysis.Linear())
    seq=(dte-datetime.datetime(2000,1,1)).total_seconds()/3600
    wind_noise_field=wind_field(u10m,v10m,z,sequence=int(seq*5),epsilon=0.01)

    # Plot the temperature
    t2m=quantile_normalise_t2m(t2m)
    t2m_pc=plot_cube(0.05)   
    t2m = t2m.regrid(t2m_pc,iris.analysis.Linear())
    # Adjust to show the wind
    wscale=200
    s=wind_noise_field.data.shape
    wind_noise_field.data=qcut(wind_noise_field.data.flatten(),wscale,
                                 labels=False,
                                 duplicates='drop').reshape(s)-(wscale-1)/2

    # Plot as a colour map
    wnf=wind_noise_field.regrid(t2m,iris.analysis.Linear())
    t2m_img = ax.pcolorfast(lons, lats, t2m.data*1000+wnf.data,
                            cmap='RdYlBu_r',
                            alpha=0.8,
                            vmin=-100,
                            vmax=1100,
                            zorder=100)

    # Plot the prmsl
    prmsl_pc=plot_cube(0.25)   
    prmsl = prmsl.regrid(prmsl_pc,iris.analysis.Linear())
    lats = prmsl.coord('latitude').points
    lons = prmsl.coord('longitude').points
    lons,lats = numpy.meshgrid(lons,lats)
    CS=ax.contour(lons, lats, prmsl.data*0.01,
                               colors='black',
                               linewidths=0.5,
                               alpha=1.0,
                               levels=numpy.arange(870,1050,10),
                               zorder=200)

    # Overlay the latent-space representation in the SE Pacific
    x=numpy.linspace(-160,-120,10)
    y=numpy.linspace(-75,-75+(40*16/18),10)
    latent_img = ax.pcolorfast(x,y,ls.reshape(10,10),
                               cmap='viridis',
                                 alpha=1.0,
                                 vmin=-3,
                                 vmax=3,
                                 zorder=1000)
    # Label with the date
    ax.text(180/args.zoom-(360/args.zoom)*0.009,
            90/args.zoom-(180/args.zoom)*0.016,
            "%04d-%02d-%02d" % (args.year,args.month,args.day),
            horizontalalignment='right',
            verticalalignment='top',
            color='black',
            bbox=dict(facecolor=(0.6,0.6,0.6,0.5),
                      edgecolor='black',
                      boxstyle='round',
                      pad=0.5),
            size=14,
            clip_on=True,
            zorder=500)