Metview's documentation is now on readthedocs!

Download source and data


NetCDF Marine Observations 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 maritime observations
# data available at: https://www.unidata.ucar.edu/software/netcdf/examples/files.html
nc = read("madis-maritime.nc")

# This netCDF has the following structure:
#
# dimensions:
#	...
#	recNum = UNLIMITED ; // (405 currently
# variables:
#   float latitude(recNum) ;	
#	float longitude(recNum) ;
#   float temperature(recNum) ;
#		temperature:long_name = "temperature" ;
#		temperature:units = "kelvin" ;

# convert the temperature variable from K -> C 
# store the result in a new netCDF object
setcurrent(nc,"temperature")
nc_t = nc - 273.16

# define netcdf plotting
vis = netcdf_visualiser(
    netcdf_plot_type          : "geo_points",         
    netcdf_latitude_variable  : "latitude",
    netcdf_longitude_variable : "longitude",
    netcdf_value_variable     : "temperature",
    netcdf_data               : nc_t
    )

# define symbol plotting
sym = msymb(
    legend                                 : "on",
    symbol_type                            : "marker",
    symbol_table_mode                      : "advanced",
    symbol_outline                         : "on",
    symbol_advanced_table_min_value        : 0,
    symbol_advanced_table_max_value        : 28,
    symbol_advanced_table_level_count      : 14,
    symbol_advanced_table_max_level_colour : "red",
    symbol_advanced_table_min_level_colour : "greenish_blue",
    symbol_advanced_table_colour_direction : "clockwise",
    symbol_advanced_table_marker_list      : 15,
    symbol_advanced_table_height_list      : 0.6
   ) 

# define coastlines
coastlines = mcoast(
    map_coastline_land_shade        : "on",
    map_coastline_land_shade_colour : "RGB(0.7188,0.6798,0.6381)'",
    map_coastline_sea_shade         : "on",
    map_coastline_sea_shade_colour  : "RGB(0.9002,0.9147,0.9351)",
    map_boundaries                  : "on",
    map_boundaries_colour           : "mustard",
    map_boundaries_thickness        : 2,
    map_grid_colour                 : "RGB(0.337,0.314,0.314)"
   )
  
# define geographical view   
view = geoview(
    map_projection         : "polar_stereographic",
    map_area_definition    : "corners",
    area                   : [4.01,-126.23,42.52,-22.9],
    map_vertical_longitude : -100,
    coastlines             : coastlines
    )

# define legend
legend = mlegend(legend_text_font_size : 0.3)

# define title - get date from the netCDF metadata
title = mtext(text_lines : ["Temperature [C] - "  &
                 global_attributes(nc_t)['cdlDate']],
                 text_font_size : 0.4
                 )

# define output
setoutput(pdf_output(output_name : 'nc_maritime_obs'))

# generate plot
plot(view, vis, sym, legend, title)

NetCDF Marine Observations 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 maritime observations
# data available at: https://www.unidata.ucar.edu/software/netcdf/examples/files.html
nc = mv.read("madis-maritime.nc")

# This netCDF has the following structure:
#
# dimensions:
#	...
#	recNum = UNLIMITED ; // (405 currently
# variables:
#   float latitude(recNum) ;	
#	float longitude(recNum) ;
#   float temperature(recNum) ;
#		temperature:long_name = "temperature" ;
#		temperature:units = "kelvin" ;

# convert the temperature variable from K -> C
# store the result in a new netCDF object
mv.setcurrent(nc,"temperature")
nc_t = nc - 273.16

# define netcdf plotting
vis = mv.netcdf_visualiser(
    netcdf_plot_type          = "geo_points",         
    netcdf_latitude_variable  = "latitude",
    netcdf_longitude_variable = "longitude",
    netcdf_value_variable     = "temperature",
    netcdf_data               = nc_t
    )

# define symbol plotting
sym = mv.msymb(
    legend                                 = "on",
    symbol_type                            = "marker",
    symbol_table_mode                      = "advanced",
    symbol_outline                         = "on",
    symbol_advanced_table_min_value        = 0,
    symbol_advanced_table_max_value        = 28,
    symbol_advanced_table_level_count      = 14,
    symbol_advanced_table_max_level_colour = "red",
    symbol_advanced_table_min_level_colour = "greenish_blue",
    symbol_advanced_table_colour_direction = "clockwise",
    symbol_advanced_table_marker_list      = 15,
    symbol_advanced_table_height_list      = 0.6
   ) 

# define coastlines
coastlines = mv.mcoast(
    map_coastline_land_shade        = "on",
    map_coastline_land_shade_colour = "RGB(0.7188,0.6798,0.6381)'",
    map_coastline_sea_shade         = "on",
    map_coastline_sea_shade_colour  = "RGB(0.9002,0.9147,0.9351)",
    map_boundaries                  = "on",
    map_boundaries_colour           = "mustard",
    map_boundaries_thickness        = 2,
    map_grid_colour                 = "RGB(0.337,0.314,0.314)",
   )
  
# define geographical view   
view = mv.geoview(
    map_projection         = "polar_stereographic",
    map_area_definition    = "corners",
    area                   = [4.01,-126.23,42.52,-22.9],
    map_vertical_longitude = -100,
    coastlines             = coastlines
    )

# define legend
legend = mv.mlegend(legend_text_font_size = 0.3)

# define title - get date from the netCDF metadata
title = mv.mtext(text_lines = ["Temperature [C] - "  +
                 str(mv.global_attributes(nc_t).get('cdlDate'))],
                 text_font_size= 0.4
                 )

# define output
mv.setoutput(mv.pdf_output(output_name = 'nc_maritime_obs'))

# generate plot
mv.plot(view, vis, sym, legend, title)