Пример #1
0
def test_met_plot():
    contour = mv.mcont({
        'CONTOUR_LINE_COLOUR': 'PURPLE',
        'CONTOUR_LINE_THICKNESS': 3,
        'CONTOUR_HIGHLIGHT': False
    })
    coast = mv.mcoast({'MAP_COASTLINE_LAND_SHADE': True})
    bindings.met_plot(TEST_FIELDSET, contour, coast)
Пример #2
0
def test_definitions():
    mcont_def = mv.mcont({'legend': True})
    msymb_def = mv.msymb({'symbol_type': 'marker'})
    mcoast_def = mv.mcoast({'map_coastline_land_shade': True})
    mobs_def = mv.mobs({'obs_temperature': False})
    mtext_def = mv.mtext({'text_font_size': '0.80'})
    geoview_def = mv.geoview({'map_projection': 'polar_stereographic'})
    ps_output_def = mv.ps_output({'output_name': 'test'})
    assert mcont_def['LEGEND'] == 'ON'
    assert msymb_def['SYMBOL_TYPE'] == 'MARKER'
    assert mcoast_def['MAP_COASTLINE_LAND_SHADE'] == 'ON'
    assert mobs_def['OBS_TEMPERATURE'] == 'OFF'
    assert mtext_def['TEXT_FONT_SIZE'] == 0.8
    assert geoview_def['MAP_PROJECTION'] == 'POLAR_STEREOGRAPHIC'
    assert ps_output_def['OUTPUT_NAME'] == 'test'
Пример #3
0
def test_plot_2():
    output_name = file_in_testdir('test_plot_2')
    png = mv.png_output(output_name=output_name)
    grid_shade = {
        'legend': True,
        'contour': False,
        'contour_highlight': True,
        'contour_shade': True,
        'contour_shade_technique': 'grid_shading',
        'contour_shade_max_level_colour': 'olive',
        'contour_shade_min_level_colour': 'blue',
        'contour_shade_colour_direction': 'clockwise',
    }
    degraded_field = mv.read(data=TEST_FIELDSET, grid=[4, 4])
    mv.plot(png, degraded_field, mv.mcont(grid_shade))
    output_name_from_magics = output_name + '.1.png'
    assert (os.path.isfile(output_name_from_magics))
    os.remove(output_name_from_magics)
Пример #4
0
import metview as mv

# read 2m temperature
t2 = mv.read("./t2_for_UC-04.grib")

# read geopotential
z = mv.read("./z_for_UC-04.grib")

t_shade_c = mv.mcont(
    legend=True,
    contour_highlight=False,
    contour_level_selection_type="interval",
    contour_interval=10,
    contour_shade=True,
    contour_shade_max_level=60,
    contour_shade_min_level=-60,
    contour_shade_method="area_fill",
    contour_shade_max_level_colour="red",
    contour_shade_min_level_colour="blue",
    contour_shade_colour_direction="clockwise",
)

z_isolines = mv.mcont(
    legend=True,
    contour_line_thickness=2,
    contour_line_colour="black",
    contour_highlight_colour="black",
    contour_highlight_thickness=4,
    contour_level_selection_type="interval",
    contour_interval=5,
Пример #5
0
def plot_stamp(
    *args,
    an=[],
    fc=[],
    layout=None,
    view=None,
    area=None,
    title_font_size=0.4,
    frame=-1,
    animate="auto",
    diff_base=None,
):
    """
    Plot ENS stamp maps
    """

    # define the view
    view = _make_view(view, area)

    desc = []
    data = {}
    vd = {}

    if diff_base is not None:
        assert isinstance(diff_base, mv.Fieldset)

    if len(args) > 0:
        assert isinstance(args[0], mv.Fieldset)
        layers = _make_layers(*args, form_layout=False)
        assert len(layers) == 1

        # prepare ens
        data["ens"] = layers[0]["data"]
        assert data["ens"] is not None
        if diff_base is not None:
            vd["ens"] = _make_visdef(data["ens"], [], style_db="diff")
        else:
            vd["ens"] = _make_visdef(data["ens"], layers[0]["vd"])

    # prepare an and fc
    d = {"an": an, "fc": fc}
    for k, v in d.items():
        if v:
            layers = _make_layers(v, form_layout=False)
            if layers:
                data[k] = layers[0]["data"]
                vd[k] = layers[0]["vd"]
                if diff_base is not None:
                    vd[k] = vd["ens"]
                else:
                    if len(vd[k]) == 0 and "ens" in vd:
                        vd[k] = vd["ens"]
                    else:
                        vd[k] = _make_visdef(data[k], vd[k])

    # determine ens number
    members = []
    if "ens" in data:
        members = data["ens"]._unique_metadata("number")
        LOG.debug(f"members={members}")
        if len(members) == 0:
            raise Exceception("No ENS data found in input!")

    # determine number of maps
    num = len(members) + sum([1 for x in ["an", "fc"] if x in data])

    # build the layout
    dw = Layout().build_stamp(num, layout=layout, view=view)

    if len(dw) < num + 1:
        raise Exception(
            f"Layout has less maps (={len(dw)}) than expected (={num})")

    title = Title(font_size=title_font_size)

    # ens members
    for i, m in enumerate(members):
        desc.append(dw[i])
        d = data["ens"].select(number=m)
        if diff_base is not None:
            d = d - diff_base
        desc.append(d)

        if vd["ens"]:
            desc.extend(vd["ens"])

        t = title.build_stamp(d, member=str(i))
        desc.append(t)

    # add an and fc
    n = len(members)
    for t in ["an", "fc"]:
        if t in data:
            desc.append(dw[n])
            d = data[t]
            if diff_base is not None:
                d = d - diff_base
            desc.append(d)
            if vd[t]:
                desc.append(vd[t])
            t = title.build_stamp(data[t], member="")
            desc.append(t)
            n += 1

    for i in range(n, len(dw)):
        desc.append(dw[i])

    if len(members) > 0 and "ens" in data:
        cont = mv.mcont(contour="off", contour_label="off")
        dummy = d = data["ens"].select(number=members[0])
        t = title.build(dummy)
        desc.extend([dw[-1], t, dummy, cont])

    return mv.plot(desc, animate=animate)
Пример #6
0
def make_eccharts_mcont():
    return mv.mcont(contour_automatic_settings="ecmwf", legend="on")
Пример #7
0
Analyst saves his data as a GRIB file and creates a plot in PNG format. 
"""

import metview as mv

mydata = mv.read('../tests/test.grib')

derived = mydata * 2 + 5

mv.write('derived_data.grib', derived)

grid_shade = mv.mcont(
    legend=True,
    contour=False,
    contour_highlight=True,
    contour_shade=True,
    contour_shade_technique='grid_shading',
    contour_shade_max_level_colour='red',
    contour_shade_min_level_colour='blue',
    contour_shade_colour_direction='clockwise',
)

# Macro-like PNG creation:
png = mv.png_output(output_width=1200, output_name='./myplot')

mv.plot(png, derived, grid_shade)

# Using a different notation:
png_output = {
    'output_type': 'png',
    'output_width': 1200,
    'output_name': './myplot2'