Versions Compared

Key

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

...

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 this dimension.

Overlaying Time Steps

...

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. We'll do it step by step.

...

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

...

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

Extract the date and time from each field

...

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 hourshour() function then converts it into a fraction of a day. The result can be converted with the date() function into a proper date; call the resulting variable dt and print it to check that it is   Add the two together to create a full date variable.:

Code Block
languagepy
dt = date(d) + hour(t/100)

Add the date to the list

If the date variable is dt, then we We add it to the list like this (inside the loop):

...

Compute the differences between consecutive dates

Very 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:

Code Block
languagepy
date_diffs = dates[2, n] - dates[1, n-1]

...

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)

...