In this exercise we will use Metview to produce the plots shown above:
You will need to work with icons interactively and write Macro code, as well. First, you will create the two plots independently then align them together in the same page.
This exercise involves:
|
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!
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:
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. Animate through the fields to see how the forecast evolving.
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. |
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:
Now drag your Table Visualiser icon the plot to overlay the mean sea level forecast with the 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
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 a new Macro and edit it. First, read the CSV file in with the Table Reader:
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 dPart = substring(string(val_date[i]),7,8) tPart = val_time[i] label = " " & dPart & "/" & tPart labels = labels & [label] 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 |
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 your Macro behaves as if it were a real Symbol Plotting icon. So save the Macro and drag it into the plot to see the labels appearing along the track.
With a new Cartesian View icon, set up a view to cater for the graph showing the mean sea level pressure values in hPa by setting
Since this task is fairly complex you will use a Macro for it. The idea goes like this:
Create new Macro and edit it. First, read the CSV file in the very same way as before but this time, on top of date and time, you also need to read latitude and longitude into vectors:
val_lat=values(tbl,3) val_lon=values(tbl,4) |
Next, read in the GRIB file containing the mean sea level forecast:
g=read("sandy_mslp.grib") |
The curve data requires two lists: one for the dates and one for the values. First you need to initialise these lists:
trVal=nil trDate = nil |
Now the main part of the macro follows: you need to loop through the track points and build the curve dataset. You can use a loop like this:
for i=1 to count(val_date) do ... end for |
Within the loop first construct an area of e.g. 10 degrees wide centred on the current track point.
Remember an area is a list of South/West/North/East values. The coordinates of the current track point are |
Next, read the forecast data for the current forecast step and the area you defined (supposing your area is called wbox
):
p=read( data: g, step: i*24, area : wbox ) |
Here we used the fact the forecasts steps are stored in hours units in the GRIB file.
Next, compute the minimum of the field in the subarea using the minval()
macro function:
pmin=minval(p) |
Finally, build the lists for the values (scaling Pa units stored in the GRIB to hPa):
trVal= trVal & [v/100] |
and for the dates:
trDate = trDate & [date(val_date[i]) + hour(val_time[i])] |
Having finished the body of the loop the last step is to define an Input Visualiser and return it. The code you need to add is like this:
vis = input_visualiser ( input_x_type : "date", input_date_x_values : trDate, input_y_values : trVal ) return [vis] |
By returning the visualiser you built a Macro that behaves as if it were an Input Visualiser icon. Now visualise your Cartesian View icon and drag your Macro into it.
Customise the graph with a Graph Plotting icon by setting the
Define a custom title as shown in the example plot with a new Text Plotting icon.
With a new Display Window icon design an A4 portrait layout with two views: your Geographical View icon should go top and your Cartesian View icon into the bottom. Now visualise your icon and populate the views with the data.