Metview's documentation is now on readthedocs!

Download source and data


Temperature Gradient Vector Example
#Metview Macro

#  **************************** LICENSE START ***********************************
# 
#  Copyright 2019 ECMWF. This software is distributed under the terms
#  of the Apache License version 2.0. In applying this license, ECMWF does not
#  waive the privileges and immunities granted to it by virtue of its status as
#  an Intergovernmental Organization or submit itself to any jurisdiction.
# 
#  ***************************** LICENSE END ************************************
# 

# read t field (the only field in the file)
t = read(source : "t850.grb", param : "t")

# compute gradient 
grad = gradient(t)

# scale gradient
grad = grad*1E5

# define the vector structure for plotting 
v = grib_vectors(u_component: grad[1],
                 v_component: grad[2])


# define wind plotting for gradient
wp = mwind(
    wind_thinning_factor                  : 1,
    legend                                : "on",
    wind_advanced_method                  : "on",
    wind_advanced_colour_min_value        : 1,
    wind_advanced_colour_max_level_colour : "red",
    wind_advanced_colour_min_level_colour : "violet",
    wind_advanced_colour_direction        : "clockwise",
    wind_arrow_unit_velocity              : 8,
    wind_arrow_thickness                  : 1,
    wind_arrow_legend_text                : "1E-2 K/km"
    )

# define contouring for temeprature
t_cont = mcont(
    contour_line_colour     : "RGB(0.4,0.4,0.4)",
    contour_line_style      : "dash",
    contour_line_thickness  : 2,
    contour_highlight       : "off",
    contour_level_selection_type : "interval",
    contour_interval             : 2,
    contour_label_height         : 0.25,
    grib_scaling_of_derived_fields: "on"
    )
    
# define caastline    
coast = mcoast(
    map_coastline_land_shade        : "on",
    map_coastline_land_shade_colour : "grey",
    map_coastline_sea_shade         : "on",
    map_coastline_sea_shade_colour  : "RGB(0.8944,0.9086,0.933)",
    map_grid_colour                 : "charcoal",
    map_grid_longitude_increment    : 10
    )

# define map view
view = geoview(
    map_projection         : "polar_stereographic",
    map_area_definition    : "corners",
    area                   : [37.71,-53.33,58.46,15.21],
    map_vertical_longitude : -30,
    coastlines             : coast
    )


# define title    
title = mtext(text_lines: ["Temperature 850 hPa [C]","Temperature Gradient 850 hPa [1E-2 K/km]"])    
 
# define the output plot file
setoutput(pdf_output(output_name : 'gradient_vector'))   
    
# generate plot    
plot(view, t, t_cont, v, wp, title)
Temperature Gradient Vector Example
#  **************************** LICENSE START ***********************************
# 
#  Copyright 2019 ECMWF. This software is distributed under the terms
#  of the Apache License version 2.0. In applying this license, ECMWF does not
#  waive the privileges and immunities granted to it by virtue of its status as
#  an Intergovernmental Organization or submit itself to any jurisdiction.
# 
#  ***************************** LICENSE END ************************************
# 

import metview as mv

# read t field (the only field in the file)
t = mv.read(source = "t850.grb", param = "t")

# compute gradient 
grad = mv.gradient(t)

# scale gradient
grad = grad * 1E5

# define the vector structure for plotting 
v = mv.grib_vectors(u_component = grad[0],
                    v_component = grad[1])


# define wind plotting for gradient
wp = mv.mwind(
    wind_thinning_factor                  = 1,
    legend                                = "on",
    wind_advanced_method                  = "on",
    wind_advanced_colour_min_value        = 1,
    wind_advanced_colour_max_level_colour = "red",
    wind_advanced_colour_min_level_colour = "violet",
    wind_advanced_colour_direction        = "clockwise",
    wind_arrow_unit_velocity              = 8,
    wind_arrow_thickness                  = 1,
    wind_arrow_legend_text                = "1E-2 K/km"
    )

# define contouring for temeprature
t_cont = mv.mcont(
    contour_line_colour     = "RGB(0.4,0.4,0.4)",
    contour_line_style      = "dash",
    contour_line_thickness  = 2,
    contour_highlight       = "off",
    contour_level_selection_type = "interval",
    contour_interval             = 2,
    contour_label_height         = 0.25,
    grib_scaling_of_derived_fields = "on"
    )
    
# define caastline    
coast = mv.mcoast(
    map_coastline_land_shade        = "on",
    map_coastline_land_shade_colour = "grey",
    map_coastline_sea_shade         = "on",
    map_coastline_sea_shade_colour  = "RGB(0.8944,0.9086,0.933)",
    map_grid_colour                 = "charcoal",
    map_grid_longitude_increment    = 10
    )

# define map view
view = mv.geoview(
    map_projection         = "polar_stereographic",
    map_area_definition    = "corners",
    area                   = [37.71,-53.33,58.46,15.21],
    map_vertical_longitude = -30,
    coastlines             = coast
    )


# define title    
title = mv.mtext(text_lines = ["Temperature 850 hPa [C]","Temperature Gradient 850 hPa [1E-2 K/km]"])    
 
# define the output plot file
mv.setoutput(mv.pdf_output(output_name = 'gradient_vector'))   
    
# generate plot    
mv.plot(view, t, t_cont, v, wp, title)