Versions Compared

Key

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

...

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 step. The steps will be:

...

We'll do it step by step.

Compute the 'period' precipitation from precip.grib

...

This is what we already did earlier, so it's done! Just copy the code to your new macro and change the result variable name to precip_diff.

Construct a loop to go through the fields

We will obtain the date for each field of the original precipitation fieldset. We need to loop through the fields:

Code Block
languagepy
n = count(precip) # the number of fields in the fieldset

# extract the dates and times from the original fields and put into a list
dates = nil
for i = 1 to n do
   print(i) # we will put proper code here later!
end for

 

The skeleton of the loop should

  • loop through the fields in the original fieldset and for each:
    • get the date and time of the forecast step (see the hint later)
    • combine these into a Metview date variable
    • add it to a list (which was initialised to nil before the loop)
  • use syntax similar to the line of code used to compute the 'period' precipitation to find the differences between the times of adjacent fields (ok, we know it's 3 hours, but in theory it could be anything)
  • extract the point value for each field in precip_diff (use the nearest_gridpoint() function). Choose a location with some high precipitation
  • scale up from metres (as the data are stored) to mm by multiplying by 1000
  • convert this into a rate, mm per hour, using the time differences computed earlier

...