...
Computing the mean surface temperature over land
XXXXXXX image
As an example, we will use a land-sea mask field as the basis of performing a computation on only the land points, excluding all sea points.
Visualise the supplied land_sea_mask.grib icon using the gridvals contour iconthe grid_shade icon. This Contouring icon is set up to shade the grid points exactly as they are in the data with no interpolation. To help illustrate what's going on, we've chosen low-resolution fields - this one is 4x4 degrees. The values are 0 over the sea, 1 over the land and somewhere between 0 and 1 on points which are close to both sea and land. Before we can use this field as a mask, we must do something with those "in-between" points and decide whether they count as land or sea! Let's say that a value of 0.5 or more is land.
...
The variable lsm
has been replaced with a stricter mask. Applying boolean operators such as < and > returns a result consisting entirely of 1s (where the grid values pass the test) and 0s (where the grid values fail the test). Plot the result with gridvals grid_shade to confirm this change.
Now we want to read t2m.grib - this contains 2 metre temperature analysis data from 5 days. Add a line of code to read this file into a new variable t2m
. Compute the mean value of the points using the integrate()
function. It will return a list of values - the mean value from each field.
We now want to and 'deactivate' the points where the land-sea mask is 0 (the sea points).
...
So we will convert the zeros in the lsm
fieldset to missing values using the bitmap()
and nobitmap()
functions, whose documentation is reproduced here:
...
- modify the
lsm
variable to have missing values where there are currently zeros (visualise to verify) - read t2m.grib into a new variable
t2m
- copy the missing value mask from
lsm
tot2m
(plott2m
to verify) - compute and print the mean value values of the fields in
t2m
- use the functionintegrate()
- this result is now the means of only the land points
The code should in fact only be a few lines. All of Metview's functions will respect missing values and treat them properly.
As an experiment, try setting all the values to missing values (just change the threshold in the expression "(lsm >= 0.5)
") to something silly. The integrate() function should now return nil
as its result. This is a special variable in Macro, and trying to do anything with it (e.g. multiplying it by a number) will result in an error. To make your code bullet-proof, you can test for it with something like this:
...