Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Scroll pdf ignore
Panel
titleDownload
Expand
titleClick here for files to download...
Excerpt Include
A Quick Tour of Metview
A Quick Tour of Metview
nopaneltrue

Attachments
uploadfalse
oldfalse
patterns*.tar.gz,*.grib,*.grb
sortByname

Text Plotting

...

A plot's title should not be underestimated - it provides vital information about what is being displayed.

During the exercises, remember to give your icons useful names!

Automatic Titles

The Text Plotting icon controls the content and appearance of the title. By default, it contains this:

Text Line Count1
Text Line 1<magics_title/>

So we have a single-line title which uses the default content defined by Magics, Metview's plotting engine.

...

There is no automatic title for BUFR, geopoints or ASCII table data.

Customising an automatic title

Visualise the supplied GRIB file relative_humidity.grib to see its automatic title.

Create a new Text Plotting icon and try to get the title to look similar to the image above. You should play with the parameters Text ColourText FontText Font Style and Text Font Size.

Positioning a title

Make a duplicate of your Text Plotting icon. We will move the title to another location in the plot using the new icon. Use the following parameters:

Text ModePositional
Text Box X PositionX coordinate of lower left corner of text box (in cm)
Text Box Y PositionY coordinate of lower left corner of text box (in cm)
Text Box X LengthWidth of the box (in cm)
Text Box Y LengthHeight of the box (in cm)
Text Box BlankingOn
Text BorderOn

Remember that Metview uses an A4 page by default, which is 29.7cm wide by 21.0cm high. Try to figure out the coordinates of the box, or look in the solutions folder!

...

  • there can be only one Text Plotting icon where Text Mode is Title - dropping new such icons into the plot replace the current title
  • dropping different Positional Text Plotting icons into the plot add text boxes; but dropping the same Positional icon multiple times (e.g. with modifications in between) will not accumulate - the text box will be updated

...

If you know (or can figure out from some Macro code) exactly what your plot is going to show,  then you can construct a title with no automatically computed elements. Or you can combine the two.

...

Code Block
languagepy
rh = read("relative_humidity.grib")

field_name       = grib_get_string(rh[1], 'name')
field_valid_date = grib_get_string(rh[1], 'validityDate')
field_level      = grib_get_double(rh[1], 'level')

title_text = field_name & ' ' & field_valid_date & ' at level ' & field_level
print(title_text)

title = mtext(text_line_1: title_text)

plot(rh, title)

The print() command shows you what is going into the mtext() definition (which is the Macro function for the Text Plotting icon).

This is fine for a single field, but notice that if you move between the two fields in the relative_humidity dataplot, there are two different vertical levels - but we only have one title, and it was constructed using the meta-data from the first field. We cannot tell it to "use this title for the first field, but use another title for the second field". So in this case we should use a handy feature of the Text Plotting icon which is described in the next section.

Using meta-data references in titles

In the previous example, Macro constructed a title string and passed it to the plot() command, which used it directly. However, the plot() command can be more clever than that. For a start, it knows to translate <magics_title/> into the automatic title. It also has some other tricks.

Instead of having Macro extract the meta-data, we can pass references to the meta-data, which will be replaced with their values at plot time, per field.

Create a copy of your macro and change just one line:

Code Block
field_level = "<grib_info key='level'/>"

Now, we are no longer extracting the level ourselves, but we are asking the plotting module to extract it at plotting time. With this change, the title will show the correct level for each field. We could extend this to construct complex titles showing various information.

Dealing with multiple overlaid fields

Image Added

Adapt your macro to also read and overlay the geopotential data . Use the supplied rh_shade icon to colour the relative humidity field:

Code Block
languagepy
rh = read("relative_humidity.grib")
z  = read("geopotential.grib")
...

rh_shade = mcont( ... )

plot(rh, rh_shade, z, title)

We now have two title lines. When we ask the plotting engine to extract meta-data from its fields, it will produce one title line per field. If we don't want this, then we need to tell it which field we do want a title line for.

Modify the field_level definition so that the <grib_info> tag contains a where clause:

Code Block
languagepy
field_level = "<grib_info key='level' where='shortName=r'/>"

Now, the title will only be produced for the relative humidity field (its shortName key is "r"). We would need to do this for all <grib_info> tags if there were more.

We should also update the parameter names in the title - let's assume that each frame will contain the same parameters (they contain different levels), so we could change field_name to this:

Code Block
languagepy
 field_name = grib_get_string(rh[1], 'name') & ' / ' & grib_get_string(z[1], 'name')

Extra Work

Text boxes

To exemplify the Text Plotting's dropping rules, do the following:

  • Visualise GRIB file relative_humidity.grib
  • apply a Text Plotting icon to move the title to another location (this icon was created previously)
  • apply a new Text Plotting icon to remove the default automatic title
  • apply a new Text Plotting icon to draw a chosen text near the top-left corner of the plot and customise its colour, font, style and size
  • apply a new Text Plotting icon to draw a chosen text around the middle of the plot and customise its border and box-blanking

Next, create a Macro program, name it custom_text_boxes, using all the above icons.

Meta-data references in Macro

The title just shows the date - add the time of the data.