Metview's documentation is now on readthedocs!

Download source and data


Model Orography with Land Sea Mask_TEST
"""
GRIB - Model Orography with Land Sea Mask
"""

# (C) Copyright 2017- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

import metview as mv

# get data
use_mars = False

# get data from MARS
if use_mars:
    g = mv.retrieve(
        type="an",
        date=-1,
        time=0,
        levtype="sfc",
        param=["z", "lsm"],
        area=[90, -60, 20, 70],
        grid=[0.1, 0.1],
    )
# read data from GRIB file
else:
    filename = "model_orog.grib"
    if mv.exist(filename):
        g = mv.read(filename)
    else:
        g = mv.gallery.load_dataset(filename)


# convert geopotential to metres
h = g[0] / 9.81

# set all water surface points as missing in h
lsm = g[1]
h = mv.bitmap(h, mv.bitmap(lsm > 0.1, 0))

# define contour shading
cont = mv.mcont(
    legend="on",
    contour="off",
    contour_label="off",
    contour_level_list=[
        -400,
        0,
        20,
        100,
        200,
        300,
        500,
        800,
        1000,
        1500,
        2000,
        2500,
        3000,
        4000,
        5000,
        8000,
    ],
    contour_level_selection_type="level_list",
    contour_shade="on",
    contour_shade_colour_list=[
        "rgb(0.15,0.5,0.4)",
        "rgb(0.16,0.4,0)",
        "rgb(0.2,0.5,0)",
        "rgb(0.3,0.6,0)",
        "rgb(0.4,0.7,0)",
        "rgb(0.5,0.8,0)",
        "rgb(0.7,0.9,0)",
        "rgb(0.9,1,0)",
        "rgb(0.9,0.8,0)",
        "rgb(0.8,0.6,0)",
        "rgb(0.7,0.45,0)",
        "rgb(0.6,0.3,0)",
        "rgb(0.45,0.2,0)",
        "rgb(0.5,0.5,0.5)",
        "rgb(1,1,0.5)",
    ],
    contour_shade_colour_method="list",
    contour_shade_max_level=8000,
    contour_shade_method="area_fill",
    contour_shade_min_level=-400,
    contour_method="linear",
    contour_internal_reduction_factor=1,
)

# define coastlines
coast = mv.mcoast(
    map_coastline_resolution="medium",
    map_coastline_sea_shade="on",
    map_coastline_sea_shade_colour="RGB(0.4845,0.6572,0.9351)",
)

# define view
view = mv.geoview(area_mode="name", area_name="europe", coastlines=coast)

# define title
title = mv.mtext(text_lines=["Model Orography"], text_font_size=0.4)

# define the output plot file
mv.setoutput(mv.pdf_output(output_name="model_orography"))

# generate plot
mv.plot(view, h, cont, title)

4 Comments

  1. What on Earth is "contour_internal_reduction_factor"? Found no help about it.

  2. Hi, 

    Yes you are right, contour_internal_reduction_factor ( default 4)  is not documented , mainly because it should be used with some precautions since it has an impact on the performance. 

    It is used in the shading/contouring algorithm to compute the size of the Matrix that will be used as input of the algorithm.

    We made  experiments and decided that a good compromise between quality  and speed is to use a factor of 4 between the size of matrix, and the size of the output ( in our internal units), but sometimes for some parameters this number is not good enough, and we need to apply the algorithm on a larger matrix. It is why we introduced this parameter to give in these extreme cases more control to the user. 

    If you decrease this factor, the quality will increase, but the speed also. 

    It is used in this plot, to get a more accurate result. 

    I hope this helps. 

  3. Thank you, Sylvie, of course it helps!.

    I had a contour plot with very tightly packed  isolines over a certain small region. In that region, some blank pixels appeared between the isolines. I tried to reduce the contour_internal_reduction_factor to one, and the problem disappeared, with non appreciable time penalty.

    1. Great, 

      Maybe we should document it then..