示例#1
0
def test_plot_2_pages():
    output_name = file_in_testdir('test_plot_2_pages')
    png = mv.png_output(output_name=output_name)
    degraded_field = mv.read(data=TEST_FIELDSET, grid=[4, 4])
    page1 = mv.plot_page(top=2.2, bottom=52.2, right=100)
    page2 = mv.plot_page(top=50)
    dw = mv.plot_superpage(pages=[page1, page2])
    mv.setoutput(png)
    mv.plot(dw[0], degraded_field, dw[1], degraded_field + 50)
    output_name_from_magics = output_name + '.1.png'
    assert (os.path.isfile(output_name_from_magics))
    os.remove(output_name_from_magics)
def plot_geo(geo, coastline, symbol, legend, title):
    with NamedTemporaryFile(suffix=".png") as png, NamedTemporaryFile(
            delete=False, suffix=".pdf") as pdf:
        png_obj = mv.png_output(output_name=png.name.replace(".png", ""))
        mv.setoutput(png_obj)
        mv.plot(coastline, symbol, legend, title, geo)

        pdf_obj = mv.pdf_output(output_name=pdf.name.replace(".pdf", ""))
        mv.setoutput(pdf_obj)
        mv.plot(coastline, symbol, legend, title, geo)
        os.chmod(pdf.name, 0o444)

        with open(png.name.replace(".png", ".1.png"), "rb") as img:
            return {"preview": b64encode(img.read()).decode(), "pdf": pdf.name}
示例#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
    def _build(self, img_size):
        img = []
        names = []
        # img_size = 120
        tmp_dir = os.path.join(os.getenv("METVIEW_TMPDIR", ""), "_maparea_")
        Path(tmp_dir).mkdir(exist_ok=True)
        for name in map_area_names():
            f_name = os.path.join(tmp_dir, name + ".png")
            if not os.path.exists(f_name):
                view = mv.make_geoview(area=name, style="grey_1")
                mv.setoutput(
                    mv.png_output(
                        output_name=f_name[:-4],
                        output_width=300,
                        output_name_first_page_number="off",
                    ))
                mv.plot(view)
            if os.path.exists(f_name):
                names.append(name)
                img.append(self.to_base64(f_name))

        return (img, names)
示例#5
0
    def _build(self, img_size):
        img = []
        names = []
        # img_size = 120
        tmp_dir = os.path.join(os.getenv("METVIEW_TMPDIR", ""), "_mapstyle_")
        Path(tmp_dir).mkdir(exist_ok=True)
        for name, d in map_styles().items():
            f_name = os.path.join(tmp_dir, name + ".png")
            if not os.path.exists(f_name):
                view = mv.make_geoview(area=[30, -30, 75, 45], style=name)
                view.update({"MAP_COASTLINE_RESOLUTION": "low"},
                            sub="coastlines")
                mv.setoutput(
                    mv.png_output(
                        output_name=f_name[:-4],
                        output_width=300,
                        output_name_first_page_number="off",
                    ))
                mv.plot(view)
            if os.path.exists(f_name):
                names.append(name)
                img.append(self.to_base64(f_name))

        return (img, names)
示例#6
0
    map_coastline_sea_shade_colour="RGB(0.85,0.93,1)",
)

area_view = mv.geoview(
    map_area_definition="corners",
    area=[45.83, -13.87, 62.03, 8.92],
    coastlines=land_shade,
)

# Simplest plot:
# NOTE that when plotting a 'raw' BUFR file, Magics will plot synop symbols as shown in
# https://software.ecmwf.int/wiki/display/METV/Data+Part+1 "Plotting BUFR Data"

obs = mv.read("../tests/obs_3day.bufr")

mv.setoutput(mv.png_output(output_width=1200, output_name="./obsplot1"))
mv.plot(area_view, obs)

# ALTERNATIVELY, add an Observations Plotting visual definition

obs_plotting = mv.mobs(
    obs_temperature=False,
    obs_cloud=False,
    obs_low_cloud=False,
    obs_dewpoint_colour="purple",
)

mv.setoutput(mv.png_output(output_width=1200, output_name="./obsplot2"))
mv.plot(area_view, obs, obs_plotting)

# ALTERNATIVELY, if we don't want to plot the whole observations, but instead want to
示例#7
0
# 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,
    contour_legend_text="Geopotential",
)

mv.setoutput(mv.png_output(output_width=1000, output_name="./gribplot"))
mv.plot(t2, t_shade_c, z, z_isolines)
示例#8
0
t2m_grib = mv.read("./t2m_grib.grib")

obs_3day = mv.read("./obs_3day.bufr")

t2m_gpt = mv.obsfilter(parameter="012004", output="geopoints", data=obs_3day)

diff = t2m_grib - t2m_gpt

diff_symb = mv.msymb(
    legend=True,
    symbol_type="marker",
    symbol_table_mode="advanced",
)

mv.setoutput(mv.png_output(output_width=1000, output_name="./obsdiff1"))
mv.plot(area_view, diff, diff_symb)

# Extract geopoints that are hotter by 1 deg or more
# hotter = mv.filter(diff, diff >= 1)
hotter = diff.filter(diff >= 1)

# Extract geopoints that are colder by 1 deg or more
# colder = mv.filter(diff, diff <= -1)
colder = diff.filter(diff <= -1)

# Get geopoints that are within +/-1
# exact = mv.filter(diff, (diff > -1) * (diff < 1))
exact = diff.filter((diff > -1) * (diff < 1))

# Symbol visdefs for each classification
示例#9
0
UC-05. The Analyst retrieves certain parameters, computes a derived
parameter and plots its values for a specific time.

--------------------------------------------------------------------------------
1. Analyst filters, the chosen parameters of a file from a given
   source (i.e. MARS, files, observation databases)
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
2. Analyst computes the desired derived parameter (i.e. wind velocity from zonal
   and meridional components)
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
3. Analyst plots the derived parameter values
--------------------------------------------------------------------------------
"""

import metview as mv

uv = mv.read('./uv.grib')

u = mv.read(data=uv, param='u')
v = mv.read(data=uv, param='v')

wind_speed = mv.sqrt(u * u + v * v)

mv.setoutput(mv.png_output(output_width=1000, output_name='./uvplot'))
mv.plot(wind_speed)
示例#10
0
t2m_grib = mv.read('./t2m_grib.grib')

obs_3day = mv.read('./obs_3day.bufr')

t2m_gpt = mv.obsfilter(parameter='012004', output='geopoints', data=obs_3day)

diff = t2m_grib - t2m_gpt

diff_symb = mv.msymb(
    legend=True,
    symbol_type='marker',
    symbol_table_mode='advanced',
)

mv.setoutput(mv.png_output(output_width=1000, output_name='./obsdiff1'))
mv.plot(area_view, diff, diff_symb)

# Extract geopoints that are hotter by 1 deg or more
#hotter = mv.filter(diff, diff >= 1)
hotter = diff.filter(diff >= 1)

# Extract geopoints that are colder by 1 deg or more
#colder = mv.filter(diff, diff <= -1)
colder = diff.filter(diff <= -1)

# Get geopoints that are within +/-1
#exact = mv.filter(diff, (diff > -1) * (diff < 1))
exact = diff.filter((diff > -1) * (diff < 1))

# Symbol visdefs for each classification
示例#11
0
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'
}

mv.plot(derived, grid_shade, **png_output)
示例#12
0
land_shade = mv.mcoast(map_coastline_land_shade=True,
                       map_coastline_land_shade_colour="RGB(0.98,0.95,0.82)",
                       map_coastline_sea_shade=False,
                       map_coastline_sea_shade_colour="RGB(0.85,0.93,1)")

area_view = mv.geoview(map_area_definition='corners',
                       area=[45.83, -13.87, 62.03, 8.92],
                       coastlines=land_shade)

# Simplest plot:
# NOTE that when plotting a 'raw' BUFR file, Magics will plot synop symbols as shown in
# https://software.ecmwf.int/wiki/display/METV/Data+Part+1 "Plotting BUFR Data"

obs = mv.read('../tests/obs_3day.bufr')

mv.setoutput(mv.png_output(output_width=1200, output_name='./obsplot1'))
mv.plot(area_view, obs)

# ALTERNATIVELY, add an Observations Plotting visual definition

obs_plotting = mv.mobs(obs_temperature=False,
                       obs_cloud=False,
                       obs_low_cloud=False,
                       obs_dewpoint_colour='purple')

mv.setoutput(mv.png_output(output_width=1200, output_name='./obsplot2'))
mv.plot(area_view, obs, obs_plotting)

# ALTERNATIVELY, if we don't want to plot the whole observations, but instead want to
# extract a specific parameter from the BUFR messages, then we use the Observation Filter
# as shown here: