Metview's documentation is now on readthedocs!

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

STILL IN WORK!  DO NOT READ IT!!!!

 

Preparation

In this exercise we will use Metview to produce the plots aligned on the same page shown above:

  • the plot at the top shows map with mean sea level pressure forecast fields overlayed with the track of Hurricane Sandy.
  • the plot at the bottom contains a graph chart showing the evolution of the minimum of the mean sea level pressure computed along the storm track.

 

We will also attach a marker to show a specific location on the map (New York City) and customise the legend and title.

XXX Download data

Verify that the data are as expected.

We will prepare the plot interactively using icons. Then, at the end, we will put it all together into a macro. Remember to give your icons useful names!

Setting the map View

With a new Geographical View icon, set up a cylindrical projection with its area defined as

South/West/North/East: 17/-97/51/-45

Set up a new Coastlines icon with the following:

  • the land coloured in grey
  • the sea coloured as #dcf0ff

Plotting the Mean Sea Level Pressure field

Plot the GRIB file sandy_msl.grib into this view using a new Contouring icon. Plot black isolines with an interval of 5 hPa between them. The fields you visualised were taken from the model run at 2012-10-27 0UTC and containing 12 hourly forecast steps from 0 to 120 hours.

Plotting the storm track

The storm track data is stored in the CSV file called 'sandy_track.txt'. If you open this file you will see that it contains the date, time and geographical coordinates of the track points.

Create a new Table Visualiser icon and set it to visualise your CSV file:

  • set the plot type to geo points
  • select the columns holding the latitude and longitude by their index
  • carefully specify the table delimiter and header information by setting
    • table_delimiter to whitespace ()
    • table_combine_delimiters to on
    • table header_row to 0

Now drag your Table Visualiser icon the plot to overlay the mean sea level forecast with the track.

Customise the storm track

The storm track in its current form does not look great so you need to customise it with a Graph Plotting icon by setting the

  • the track line to black and thick
  • the track points to white filled circles (their marker index is 15) with red outline.

Plotting date/time labels onto the track

To finalise the track plot you need to add the date/time labels to the track points. This can be done with a Symbol Plotting icon by specifying the list of labels you want to plot into the map. Since it would require too much editing you will learn a better (programmatic) way of doing it by using Metview Macro.

Create new Macro and edit it. First, read the CSV file in with the Table Reader (see its documentation here):

tbl = read_table(
	table_delimiter	:	" ",
	table_combine_delimiters	:	"on",
	table_header_row	:	0,
	table_filename	:	"sandy_track.txt"
	)

Here the object referenced by variable tbl contains all the columns from the CSV file. Now read the date and time (from the first two columns) into separate vectors:

val_date=values(tbl,1)
val_time=values(tbl,2)

Next, you need to build the list of labels. Each label is made up from a day and an hour part separated by a slash. Use this loop to construct the list:

labels=nil

for i=1 to count(val_date) do
	labels = labels & ["   " & substring(string(val_date[i]),7,8) & "/" & val_time[i] ]
end for

Finally, define a Symbol Plotting visual definition and return it.

Symbol Plotting in text mode is used to plot string values to the positions of the dataset it is applied to. The rule is that the first string in the list defined by symbol_text_list goes to the first data position, the second one to the second position and so on.

The code you need to add is like this:

sym = msymb(
	symbol_type	:	"text",
	symbol_text_font_colour : "black",
	symbol_text_font_size: "0.3",
	symbol_text_font_style: "bold",
	symbol_text_list	:	labels	
	)

return [sym]

By returning the visual definition you built a Macro behaves as if it were a real Symbol Plotting icon. So once the Macro is finished drag it into the plot and you should see the labels appearing along the track.

The Curve plot

 

Setting the View

With a new Cartesian View icon, set up a view to cater for the graph by setting

  • the x-axis type id date
  • the y-axis label is hPa
  • the y-axis minimum value is 940 and its maximum is 1000

Compute the minimum pressure along the track

Since this task is fairly complex you will use a Macro for it. The idea goes like this:

  • you read the track points from the CSV file
  • define a lot-lon box around each point
  • read the forecast mean sea level data for the box for the corresponding time
  • compute the minimum of the pressure in the box
  • from these minimum values you can build the curve data to plot .

Create new Macro and edit it. First, read the CSV file in the very same way as before but this time you need to Now read the date and time (from the first two columns) into separate vectors:

val_lat=values(tbl,3)
val_lon=values(tbl,4)

Next, you need to build the list of labels. Each label is made up from a day and an hour part separated by a slash. Use this loop to construct the list:

labels=nil

for i=1 to count(val_date) do
	labels = labels & ["   " & substring(string(val_date[i]),7,8) & "/" & val_time[i] ]
end for

Finally, define a Symbol Plotting visual definition and return it.

Symbol Plotting in text mode is used to plot string values to the positions of the dataset it is applied to. The rule is that the first string in the list defined by symbol_text_list goes to the first data position, the second one to the second position and so on.

The code you need to add is like this:

sym = msymb(
	symbol_type	:	"text",
	symbol_text_font_colour : "black",
	symbol_text_font_size: "0.3",
	symbol_text_font_style: "bold",
	symbol_text_list	:	labels	
	)

return [sym]

By returning the visual definition you built a Macro behaves as if it were a real Symbol Plotting icon. So once the Macro is finished drag it into the plot and you should see the labels appearing along the track.

 

 

Plotting the Mean Sea Level Pressure field

Plot the GRIB file msl.grib into this view using a new Contouring icon. Plot black isolines with an interval of 5 hPa between them. Since this will be plotted on top of another field, it would also be a good idea to increase the thickness of the isolines. Activate the legend in the Contouring icon and set the legend text for this icon to "MSLP". Animate through the filelds to see how the forecast evolving.

Plotting the Precipitation Field

The GRIB file precip.grib contains a pre-processed field of precipitation accumulated over 3 hours before and after the time of the MSLP field (a total of 6 hours of precipitation).

GRIB files store their fields in SI units. For precipitation this is metres, which is not what meteorologists tend to use. Metview will normally automatically scale such parameters into their 'normal' units (in this case mm), but if a field is the result of some post-processing (as this one is) then this scaling will not be applied because the processing may have changed the nature of the field. Here, the field is still precipitation, so we would like the normal scaling to be applied. The Contouring icon has a parameter called Grib Scaling of Derived Fields which should be set to On in this case.

Plot the precipitation data using new Contouring icon. Do this in isolation from the MSLP field until you are happy with the result.

  • use the following list of levels for contouring: 0.5, 2, 4, 10, 25, 50, 100, 250  (but remember that in the Contouring icon editor to use a forward slash to separate the items)
  • use the following list of colours:  cyan, greenish_blue, blue, bluish_purple, magenta, orange, red, charcoal (use the Contour Shade Colour List helper tool)
  • deactivate the contour highlight
  • activate the legend

Overlaying Both Fields

Visualise your Geographical View icon and drop the following icons into the Display Window:

  • your Coastlines icon
  • the msl.grib icon with your MSLP Contouring icon
  • the precip.grib icon with your precipitation Contouring icon

Improving the Legend

Create a new Legend icon and change Legend Display Type to Disjoint. Play with the font size and colour and set the legend title to say something about the precipitation field. Drop it into the Display Window to see the results.

Adding the Position of New York City

One easy way to add a place-mark is to use the Input Visualiser icon and combine it with a Symbol Plotting icon.

Edit a new Input Visualiser icon and set the following:

Input Plot TypeGeo Points
Input Longitude Values-74
Input Latitude Values40.71

Create a new Symbol Plotting icon to plot this as a red marker (the filled circle is marker index 28) with some text for its legend entry.

Adding a Custom Title

Using a Text Plotting icon, add a custom title as shown in the plot.

Generating a Macro to Reproduce the Plot

Generate a macro which will reproduce your plot with a single click. This can be done either by clicking the Generate Macro button from the Display Window or by editing a new Macro icon, dropping your data and visdef icons into it and adding a plot() command.

Extra Work

Try the following if you have time.

Ensuring the title has the correct date and time

There are various ways we can ensure that the title has the date and time according to the actual data. The default title in fact contains the date and time, but in this exercise we want more control over it.

Construct the second line of the title by extracting the date and time from the MSLP field and converting into an appropriate string - do this in the Macro code.

Hints:

  • if you have a fieldset variable called msl_grib, the following line will extract the date at which the field is valid:
    • msl_date = grib_get_long(msl_grib, 'validityDate')
  • we can do something similar for the validity time
  • these are extracted as integer numbers, but can be combined into a proper date variable in Macro:
    • full_date = date(msl_date) + hour(msl_time)

  • use the string() function to construct a date string similar to the one used in the current title
  • insert this into the mtext() function instead of the current title
  • it is now more robust - if you use data from a different date or time, the title will still be correct
  • note that this method will not work directly if you want to generate an animation from different time steps of data

Experiment with different backgrounds

Modify the Coastlines icon, for example:

  • plot the US state boundaries
  • try different land or sea shading colours
  • change the frequency of the grid lines

 

  • No labels