Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

You have seen already how to either visualise your outputs either processed data on the display or saving save it to a file. Most processing you will do with Metview will lead to a visualisation you might want to save, either to either publish it on web pages or in reports, or simply to keep records. This session will give you more information on how you can save and customise your visualisations. 

Output formats

All graphical output formats are generated through ECMWF's graphics library Magics. This means that all graphical capabilities in Metview depends depend on what Magics offers. Detailed descriptions of the output formats and their settings can be found in the Magics reference documentation.

The table below gives you a list of all the formats that Magics/Metview support and how you can use them.

FormatparameterHow to visualiseWhat to use for
Qt Metview display windowInteractive usage within Metview
PostScriptps/epsokular, ghostscript/gvPrinting, publications
PDFpdfokular, acroreadWeb, archiving
PNGpngweb browsers, display, xvWeb, presentations -> animations
SVGsvgweb browsers, vector graphics editor (e.g. Inkscape)Web HTML5, for further editing in drawing programs
KML/KMZkmlGoogle Earth, Google Maps, OpenLayersInteractive (non-scientific) publications

The KML

...

output format

KML is a very special output format. It has no notion of output size since it is displayed on the globe. KMZ is the compressed version of the KML files and is written by default. You can write out the uncompressed KML if you want to debug the output.

Info
titleBe careful

The KML output is still experimental and we look for feedback on it. KML can only be generated if the Cylindrical projections projection is selectedused!

  

Metadata

When a large number of plots are generated it is often hard to find later plots with specific contents. What can help is to store additional information with the plots to describe what the content is. These descriptions about the content are called Metadata. Magics/Metview support the saving of such metadata when the format allows this. Especially in text/XML based formats, such as Postscript and SVG, you can use simple UNIX tools like grep to search the files for specific keywords.

How to save your visualisations

Here we quickly recap describe how you can save your display displays from the interactive plot window or save them within Macros.

...

Whenever you have a plot window open, you are able to export the plot into other file formats. You can either select the export button in the menu ( option, either from the toolbar button (it looks like a floppy disk with a pen),

...

or

...

from the File menu. The keyboard shortcut is Ctrl+s

...

.

Image Added               Image Added

 

You will be presented with a dialogue (shown below) similar to what is used by other programs to choose a location and filename for the saved output.You can select which pages you want to save (if you have a series of them), which format and if you want to edit any format-specific options.

If you select the "spanner" icon , you are offered an editor to choose format specific options. The example below shows the options for the KML format.

...

Setting output formats in macro codecode

The following piece of code shows the simplest way to save your plot as a PostScript file instead of creating an interactive Display Window.

Code Block
languagepy
# set up the output format

 ps = ps_output(
      output_name : "my_plot"
)
setoutput(ps)


data = read("z500.grib")
plot(data)  #  the plot will be sent to the PostScript file

Try it!

The ps_output() function defines how a PostScript file should be generated. More options are available to further customise it. The setoutput() function selects this output format. So our code can contain many output format definitions and then select just one (or more) with the setoutput() function at run-time (see later).

You will have already seen some examples of how to save outputs in Macro in previous exercises. The following code example shows how to set multiple output formats at the same time and also set various parameters for the different output formats. Note that in most cases the default values are sufficient. A list of all options can found in the Magics documentation for each format at: PostScriptSVG, PNG and KML.

Code Block
languagepy
titleSeeting multiple outputs in Metview Macro
linenumberstrue
#
# Setting common output options for multiple formats
#
output_common = ( 
      output_name            : "/tmp/myOutputTest",  # specify full path
      output_width           : 1000,                 # set width in pixel
      output_title           : "Map of Z500",        # title used by a viewer
      output_debug           : "ON",                 # print extra information
      output_filelist        : "ON",                 # save list of files generated
      output_filelist_name   : "/tmp/filelist.txt"   # where to save the list
)

ps = ps_output(
      output_common,
      output_ps_scale        : 0.9,    # scale content to 90%, for some printers
      output_ps_colour_model : "CMYK"  # set colour model to CYMK
)

png = png_output(
      output_common,
      output_width           : 1000,                 # set width in pixels
      output_cairo_transparent_background : "ON"  # to get transparent PNGs
)

svg = svg_output(
      output_common,
      output_width        : 1000,                 # set width in pixels
      output_svg_fix_size : "ON",   # this fixes the size to 'output_width'
      output_svg_meta     : "Metview map of Z500",
      output_svg_desc     : "This file was generated for the Training course"
)

kml = kml_output(
      output_common,
      kml_description : "This file was generated for the Training course",
      kml_author      : "Stephan Siemen",
      kml_link        : "http://www.ecmwf.int",
      kml_latitude    : 30,     # latitude where Google Earth centres the view
      kml_longitude   : 120,    # longitude where Google Earth centres the view
      kml_coastlines  : "ON"    # normally 
)

output_drivers = [ps, png, svg, kml]

setoutput(output_drivers)

data = read("z500.grib")

plot(data)

...

Code Block
languagepy
titleExample for runmode
# check run mode
mode = runmode()

# select outcome dependent on run-mode
if(mode = "execute")
 then setoutput(to_pngfilepng)
else if (mode = "batch")
 then setoutput(to_psfileps)
else if (mode = "visualise") 
 then print('Plotting to screen')  # for screen do nothing
else if (mode = "prepare")
 then print('Plotting to screen')  # for screen do nothing
else
 fail("Only execute, batch and visualise allowed")
end if

...

Create a new Macro icon and rename it outputs. Write a small macro code to read the file z500.grib and visualise plot it on the screen but saves it to a PDF if . If the macro is run in batch mode and saved , the plot should be saved as a PDF file somewhere into /tmp; otherwise, plot it to the screen.

  1. Run the code in the Macro Editor and see what happens if your execute the macro.
  2. Go on the command line and change to the directory where the macro is located. Execute the macro from the command line outside Metview.

...

Some graphical formats, such as PostScript and PDF, allow multiple pages within the documents. Other formats, such as PNG, will contain a single page at the time and therefore contain a number in their filename to indicate which page they contain. If you plot, for example, a fieldset with 3 fields to a PostScript file,  it will contain 3 pages - each field is plotted into the same view, but on a different page.

You can also trigger a new page in Metview Macro with the function

...