Versions Compared

Key

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

...

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.

...

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.

...

Extract the date and time from each field

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

Code Block
languagepy
d = grib_get_long(precip[i], 'validityDate')
t = grib_get_long(precip[i], 'validityTime')

Print the results of these to understand the numbers that are being returned.

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. These are handled by the GRIB_API library.

Convert these numbers into a date variable

The date (d) can be converted with the date() function into a proper date variable. 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). A time of 12:00 is returned as 1200, so we need to divide by 100 to get it into hours. The hour() function then converts it into a fraction of a day.  Add the two together to create a full date variableindex:

Code Block
languagepy
dt = valid_date(d) + hour(t/100)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 loop:

...

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.

GRIB

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

Other formats

Extracting dates from other formats can be more tricky and will not be covered here.

...