Metview's documentation is now on readthedocs!

Download source and data


Parcel method on Skew-T 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 GRIB data        
g = read("thermo_profile.grib")

# extract thermo profile
prof = thermo_grib(
	coordinates : [5,0],
	data        : g
)

# compute parcel path - start from surface
parcel = thermo_parcel_path(prof)

# create plot object for parcel areas  
parcel_area = thermo_parcel_area(parcel) 

# create plot object for parcel path
parcel_vis = xy_curve(parcel.t, parcel.p,"charcoal","dash",6)
 
# use default visual definition for t and td profile
prof_vis= mthermo() 
 
# define the thermodynamic view
view = thermoview( type : "skewt",
                   minimum_temperature : -140,
                   maximum_temperature : 40,
                   top_pressure: 50,
                   subpage_clipping: "ON")   
  

# get profile info for title
info = thermo_data_info(prof)

# define title
title_txt = "Run: " & info.date & " " & info.time & " UTC Step: " & info.step &
 " h Lat: " & info.lat & " Lon: " & info.lon 

title = mtext(
    text_lines: title_txt, 
    text_font_size: 0.5,
    text_colour:  "charcoal"
    )
   
# define text lines for info box 
txt = nil
txt = txt & ["     Mode: " & parcel.start.mode ]
txt = txt & ["  Start p: " & round(parcel.start.p,0)  & " hPa"]
txt = txt & ["  Start t: " & round(parcel.start.t,1)  & " C"]
txt = txt & [" Start td: " &  round(parcel.start.td,1)  & " C"]
txt = txt & ["     CAPE: " & round(parcel.cape,3) & " J/kg"]
txt = txt & ["      CIN: " & round(parcel.cin,3) & " J/kg"]
if parcel.lcl <> nil then
    txt = txt & ["    LCL p: " & round(parcel.lcl.p,0) & " hPa"]
    txt = txt & ["    LCL t: " & round(parcel.lcl.t,1) & " C"]
end if
if parcel.lfc <> nil then
    txt = txt & ["    LFC p: " &  round(parcel.lfc.p,0) & " hPa"]
    txt = txt & ["    LFC t: " &  round(parcel.lfc.t,1) & " C"]
end if
if parcel.el <> nil then
    txt = txt & ["     EL p: " & round(parcel.el.p,0) & " hPa"]
    txt = txt & ["     EL t: " & round(parcel.el.t,1) & " C"]
end if
if parcel.top <> nil then
    txt = txt & ["    TOP p: " & round(parcel.top.p,0) & " hPa"]
    txt = txt & ["    TOP t: " & round(parcel.top.t,1) & " C"]
end if

# create info box - make sure font is monospace
info_box = mtext(
    text_lines: txt, 
    text_font: "courier",
    text_font_size: 0.3,
    text_colour:  "charcoal",
    text_justification: "left",
    text_mode           : "positional",
    text_box_x_position : 14.8,
    text_box_y_position : 13.4,
    text_box_x_length   : 5.2,
    text_box_y_length   : count(txt)*0.35+0.4,
    text_box_blanking   : "on",
    text_border         : "on",
    text_border_colour  : "charcoal"
    )

# define the output plot file
setoutput(pdf_output(output_name : 'parcel_path_skewt_grib'))

# plot the profile, parcel areas, parcel path and info box together    
plot(view, parcel_area, prof, prof_vis, parcel_vis, title, info_box) 

Parcel method on Skew-T 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 GRIB data        
g = mv.read("thermo_profile.grib")

# extract thermo profile
prof = mv.thermo_grib(coordinates = [5,0], 
                    data = g)


# compute parcel path - start from surface
parcel = mv.thermo_parcel_path(prof)

# create plot object for parcel areas  
parcel_area = mv.thermo_parcel_area(parcel) 

# create plot object for parcel path
parcel_vis = mv.xy_curve(parcel["t"], parcel["p"], "charcoal", "dash", 6)
 
# use default visual definition for t and td profile
prof_vis = mv.mthermo() 
 
# define the thermodynamic view
view = mv.thermoview( type = "skewt",
                   minimum_temperature = -140,
                   maximum_temperature = 40,
                   top_pressure = 50,
                   subpage_clipping = "ON")   
  
# get profile info for title
info = mv.thermo_data_info(prof)

# define title
title_txt = "Run: {} {} UTC Step: {} h Lat: {:.2f} Lon: {:.2f}" \
    .format(info["date"],info["time"],info["step"],info["lat"],info["lon"])

title = mv.mtext(
    text_lines = title_txt, 
    text_font_size = 0.5,
    text_colour =  "charcoal"
    )
   
# define text lines for info box 
txt = []
txt.append("     Mode: " + parcel["start"]["mode"])
txt.append("  Start p: {:.0f} hPa".format(parcel["start"]["p"]))
txt.append("  Start t: {:.1f} C".format(parcel["start"]["t"]))
txt.append(" Start td: {:.1f} C".format(parcel["start"]["td"]))
txt.append("     CAPE: {:.3f} J/kg".format(parcel["cape"]))
txt.append("      CIN: {:.3f} J/kg".format(parcel["cin"]))

if parcel.lcl != None:
    txt.append("    LCL p: {:.0f} hPa".format(parcel["lcl"]["p"]))
    txt.append("    LCL t: {:.1f} C".format(parcel["lcl"]["t"]))

if parcel.lfc != None:
    txt.append("    LFC p: {:.0f} hPa".format(parcel["lfc"]["p"]))
    txt.append("    LFC t: {:.1f} C".format(parcel["lfc"]["t"]))

if parcel.el != None:
    txt.append("     EL p: {:.0f} hPa".format(parcel["el"]["p"]))
    txt.append("     EL t: {:.1f} C".format(parcel["el"]["t"]))
    
if parcel.top != None:
    txt.append("    TOP p: {:.0f} hPa".format(parcel["top"]["p"]))
    txt.append("    TOP t: {:.1f} C".format(parcel["top"]["t"]))

# create info box - make sure font is monospace
info_box = mv.mtext(
    text_lines = txt, 
    text_font = "courier",
    text_font_size = 0.3,
    text_colour =  "charcoal",
    text_justification = "left",
    text_mode          = "positional",
    text_box_x_position = 14.8,
    text_box_y_position = 13.4,
    text_box_x_length   = 5.2,
    text_box_y_length   = len(txt)*0.35+0.4,
    text_box_blanking   = "on",
    text_border         = "on",
    text_border_colour  = "charcoal"
    )

# define the output plot file
mv.setoutput(mv.pdf_output(output_name = 'parcel_path_skewt_grib'))

# plot the profile, parcel areas, parcel path and info box together    
mv.plot(view, parcel_area, prof, prof_vis, parcel_vis, title, info_box)