Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Confirmed.
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

Time

Time is a very important dimension in meteorology, and there are many things to keep in mind. Here we will explore how Metview handles this dimension.

Overlaying Time Steps

Image Added

Inspect the supplied GRIB files: z500_fc.grib contains geopotential forecasts made in one run, but for six different forecast steps; z500_an.grib contains analysis fields for two times. Visualise the supplied Geographical View icon and drop the forecast GRIB icon together with its corresponding Contouring icon (cont_fc) into the Display Window, and then drop the analysis GRIB icon together with its corresponding Contouring icon (cont_an) too.

Time

Time is a very important dimension in meteorology, and there are many things to keep in mind. Here we will explore how Metview handles the fourth dimension.

Overlaying Time Steps

Image Removed

Inspect the supplied GRIB files: z500_fc.grib contains geopotential forecasts made in one run, but for six different forecast steps; z500_an.grib contains analysis fields for two times. Visualise the supplied Geographical View icon and drop the forecast GRIB icon along with its corresponding Contouring icon (cont_fc)into the Display Window, and then drop the analysis GRIB icon along with its corresponding Contouring icon (cont_an)too. Go through the frames of animation. The fields have been overlaid, but if you look at the times and dates in the title, you will see that they do not match. Metview has simply plotted the first field of each data file together, then the second, and so on. We can make it more intelligent.

Edit the Geographical View icon and set this:

Map Overlay ControlBy Date

Save the icon, visualise it and drop the data with their visdefs in again. Go through the animation steps and look at the Frames tab in the Display Window to see what has happened. Now the fields will be overlaid only if their valid date and time match.

...

Precipitation data provides an interesting challenge. Precipitation fields in MARS are stored as accumulated fields . Visualise the supplied precip.grib icon with the precip_shade visdef. The first field is empty (check using the Cursor Data). The first field has a step of 0, meaning that it contains the total precipitation accumulated between the run time and the run time plus step. Since these are the same, there is no accumulated precipitation! Subsequent steps show more and more precipitation (the amount accumulated over 3, 6, 9, etc hours).

...

We can see from examining the file that the 6 and 9 o-'clock  steps are fields 3 and 4 respectively (using 1-based indexing). So the following macro code will compute the difference and return it:

...

Code Block
languagepy
precip = read("precip.grib")

n = count(precip) # the number of fields in the fieldset
precip_3h = precip[2, n] - precip[1, n-1]
return precip_3h

Visualise the macro.

...

If you drop the precip_shade visdef icon into the plot, it may become blank! There is one more trick: we have created a derived field, and this changes the automatic scaling algorithm used when plotting. Precipitation is stored in metres, but we want to display it in mm. Modify the precip_shade icon and set:

Grib Scaling of Derived FieldsOn

Visualise your macro result again and confirm that you now have precipitation only for the 3-hour periods, which does not accumulate with each frame.

...

  • midday = date(20150105.5)

Use this syntax to add another variable, d2, which contains the date and time for 13:00h at 2015-03-13. Print it to check it.

...

Compute and print the difference between your two dates, d2 and d1. 

Looping through dates

Three examples (no need to type these in, but the code is in a macro called dates in the solutions folder), to get a feel for it:

Code Block
languagepy
for d = 2015-01-01 to 2015-03-01 do
    print(d)  # each step is 1 day
end for

for d = 2015-01-01 to 2015-03-01 by 2 do
    print(d)  # each step is 2 days
end for

for d = 2015-01-01 to 2015-03-01 by hour(6) do
    print(d)  # each step is 6 hours
end for

Computing the precipitation rate at a point

As an exercise to put all of this together, we will write a new macro to compute the precipitation rate in mm per hour at a particular location for each time period. This could be a little complicated, so we'll do it step by step. The steps will be:

...

Compute the 'period' precipitation from precip.grib

...

This is what we already did earlier, so it's done! Just make a copy

...

your

...

earlier macro, compute_precip, and call it precip_rate. Change the result variable name to precip_diff to make it more generic. Remove the return line, as we want to use this fieldset, not return it.

Construct a loop to go through the fields

...

  • get the date and time of the forecast step
  • combine these into a Metview date variable
  • add it to a list (which was initialised to nil before the loop)

...

Now, create an empty list (dates = nil). We will add each date variable to it as we loop through the fields.

We will obtain the date for each field of the original precipitation fieldset and add it to the list. We need to loop through the fields - we should already have n defined as the number of fields from the previous exercise:

Code Block
languagepy
dates = nil
for i = 1 to n do
   print(i) # we will put proper code here in the next step!
end for

Extract the date and time from each field

You can get the valid date (including its time) of a field like this, inside the loop, where i is the field index

Here are some hints to help.

A list is built up like this:

Code Block
languagepy
datesdt = nil
for i = .... do
    dt = .....  # construct a date/time variable
    dates = dates & [dt]
end forvalid_date(precip[i])

Print the result to see what's being returned.

Add the date to the list

We add it to the list like this (inside the loop):

Code Block
languagepy
dates = dates & [dt]

Compute the differences between consecutive dates

This is very similar to computing the precipitation data earlier (ok, we know it's 3 hours, but in theory it could be anything). We do this after the previous loopYou can get the date and time of a field as numbers like this:

Code Block
languagepy
ddate_diffs = grib_get_long(precip_diff[i], 'validityDate')
t = grib_get_long(precip_diff[i], 'validityTime')

then combine those numbers into proper date variables. Print the results of these function calls to check exactly what they are returning before you try to convert them into date variables. You will need to divide the time variable (t) to convert it into a fraction of a day before adding it to the date variable (d).

Info
The grib_get() functions are general-purpose functions to get pieces of meta-data from a GRIB field, specified by keys such as 'validityDate'. The Grib Examiner can help you find the available keys.
dates[2, n] - dates[1, n-1]

Now you have a list of time differences in days. You can multiply by 24 to get them in hours.

Code Block
languagepy
date_diffs_in_hours = date_diffs*24

Extract the point value for each field in precip_diff

Use the nearest_gridpoint() function on the precip_diff fieldset. It returns a list of values, one for each field. Choose a location with some high precipitationNow that you have a list of proper date variables, you can find the difference between consecutive dates using a single line which subtracts one set of list elements from another (very similar to computing the 'period precipitation' we did earlier). Now you have a list of time differences in days. You can multiply by 24 to get them in hours.

The nearest_gridpoint() function can be called in a number of ways, but we will use it like this (giving actual numbers for lat and lon) :

Code Block
languagepy
 values = nearest_gridpoint(precip_diffs, lat, lon)

The result is a list of values, a value for each field. You can directly multiply a list variable by a number to obtain a new list where each element has been multiplied - do this to scale from metres to mm.

Compute precipitation rate in mm per hour

The final calculation requires converting the data values into mm per hour - divide this list of values by the list of time differences, which should be in hours (e.g. if the time difference between two steps is 7 hours, then the rate of precip per hour is the mean precip value divided by 7)converting the data values into mm per hour - divide the list of precipitation values by the list of time differences, which are in hours.

Print the result - it will be a list of numbers, one for each time period.

...

Often, these climatological averages are computed individually for each time step. So in our case, we want to now produce two means: one for all the fields at 00:00 and one for all the fields at 12:00. Hint: use the GRIB Filter icon (and its equivalent Macro code) to extract all the fields where Time = 0, and compute their mean. Do the same with all the 12:00 fields. Concatenate the two mean fields into a 2-field fieldset and plot it.

...

The easiest way to extract dates from a BUFR file is to convert it to geopoints using the Observation Filter and then extract the dates from the resulting geopoints.

Other formats

then extract the dates from the resulting geopoints.

GRIB

For GRIB, we also have the base_date() function, which returns the model run time for each field.

NetCDF

The values() function will return a list of dates when the current variable is a time variable - see Data Part 2Extracting dates from other formats can be more tricky and will not be covered here.

Extra Work

If you have time, try the following.

...

In Missing Values and Masks, we will see how we could do this sort of thing directly with the GRIB fields.