Versions Compared

Key

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

...

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

...

Here are some hints to help.

You can get the date and time of a field as numbers A list is built up like this:

Code Block
languagepy
ddates = nil
for i = .... do
    dt = .....  # construct a date/time variable
    dates = dates & [dt]
end for

You can get the date and time of a field as numbers like this:

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

...

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.

A list is built up like this:

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

 

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

...

The final calculation requires converting the time intervals into hours (because data values into mm per hour - divide this list of values by the list of time differences, which are 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).

...