Versions Compared

Key

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

...

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

KML as output format

KML is a very special output format. It contains the    it has no notion of output size.   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 till experimental and we look for feedback on it. KML can only be generated if the Cylindrical projections is selected!

Image Added  Image Added

Metadata

When a large amount of plots is 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. This 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.

...

Setting output formats in macro code

You will have already seen some examples of how to save outputs in Macro in previous exercises how to save plots from macros.The following code example shows how to set multiple output formats at the same time and setting 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",        # give a title to be used by a viewer
      output_debug           : "ON",                 # print extra debug information into file
      output_filelist        : "ON",                 # record thesave list of output files generated
      output_filelist_name   : "/tmp/filelist.txt"   # specifywhere to wheresave the list of generated files goes
)

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

png = png_output(
      output_common,
      output_cairo_transparent_background : "ON"  # generateto PNGsget with transparent backgroundPNGs
)

svg = svg_output(
      output_common,
      output_svg_fix_size : "ON",   # normally SVGs are scalable - 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 to where Google earthEarth centres the view
      kml_longitude   : 120,      # longitude to where Google earthEarth centres the view
      kml_coastlines  : "ON"      # normally 
)

output_drivers = [ps, png, svg, kml]

setoutput(output_drivers)

data = read("z500.grib")

plot(data)

 

Setting output dependent on runmode

Depending on how you run your Macros you might want to specify various output formats. For example you might sometimes open your output in the display window, while you might like to save it to a PNG file when you run your Macro in batch. The way to code run mode dependent outcomes is by using the function runmode(). It returns a string with the run mode:

...

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

# select outcome dependent on run-mode
if(mode = "execute")
 then setoutput(to_pngfile)
else if (mode = "batch")
 then setoutput(to_psfile)
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

 

Now, depending on how you call the macro your output will be directed to different media. Choose different options from the icon’s right-click menu to see what happens. Note that you can also simulate these actions from within the Macro editor ( Program | Run Options). The ‘prepare’ run mode is the default one when you run your macro from the Macro editor. The ‘batch’ run mode will be explained in a later paragraph.

If you select an option not covered by the allowed run modes (e.g. Save or Examine), the macro will stop, turn red (failed run) and issue an error message - this behaviour is provided by the fail() function. A related function, stop(), will do the same but allow the macro to exit in the green state (successful run). Note that you may have to see that it has worked! To delete the output files before running the macro in order to 

To run the macro in batch mode, you call Metview with the option -b followed by the macro name on the command line (assuming you are running from the same directory as the macro - otherwise you must provide a path to it) or in shell scripts. For example:

metview -b mymacro.mv

The newlines within the conditional branching part of the code are down to personal preference. You could also have formatted the code as follows:

if (mode = "execute") then

setoutput(to_pngfile)

else if (mode = "batch") then

setoutput(to_psfile)

If You Have Extra Time ...

One important piece of functionality that we have omitted is the ability to save our derived data. Add some code to handle the Save run mode by saving the derived data in a file. There are three things you will have to do:

  • at the end of the run mode checks, instead of

else fail ( ... )

  • we should not fail if the mode is “save”:

else if (mode <> "save")

    then fail ( ... )

...

Task

Create a new Macro icon and rename it outputs. Write a macro code to read the file z500.grib and visualise it on the screen when executed and saved to a PNG if run in batch mode. For any other run mode the output should be saved as a PostScript file.

  1. Run the code in the Macro Editor and see what happens it 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.

Pages

Some graphical formats, such as PostScript and PDF, allow multiple pages within the documents. Other formats, such as PNG, which will contain a single page at the time and therefore contain a number in their name to indicate which page number they contain. You can trigger a new page in Metview Macro with the function

...

This function is normally used within loops to generate output of each iteration on a separate page (or file).

Task

Take one of your existing Macros containing a loop and try to print each iteration on a page.

...

Metview/Magics also supports special tags in SVG for the Inkscape graphical editor. This open source editor is great for when you need to further annotate your maps.

KML as output format

KML is a very special output format. It contains the    it has no notion of output size.   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 till experimental and we look for feedback on it. KML can only be generated if the Cylindrical projections is selected!

Image Removed  Image Removed

If you have extra time

If you have time you might want to try out opening your SVG file from the first exceicise above in inkscape and 

Using Web Map Services (WMS)

Metview provides a module to request maps from a Web Map Services (WMS). The WMS standard is defined by the Open Geospatial Consortium (OGC), which is very popular in the GIS community. The WMS module can be used to query an OGC-compliant WMS server, retrieve maps from it and overlay them with other data.

There is a separate tutorial on how you can integrate maps in Metview.The only thing you need to know is that to use a map service you need to request a so-called GetCapabilities document first. This document contains all information (in human and machine readable form) on what maps are offered and what the client can do. Metview will parse this file and offers you a convent and easy to use interface to request the maps you want.

...