Note

This tutorial was generated from an IPython notebook that can be downloaded here.

Create numpy region mask

In this tutorial we will show how to create a mask for arbitrary latitude and longitude grids.

Import regionmask and check the version:

'0.2.0'

We define a lon/ lat grid with a 1° grid spacing, where the points define the middle of the grid. Additionally we create a grid that spans the edges of the grid for the plotting.

Again we use the SREX regions. Using xarray=False tells the code to output to a numpy array.

mask is now a n_lon x n_lat numpy array. Gridpoints that do not fall in a region are NaN, the gridpoints that fall in a region are encoded with the number of the region (here 1 to 26).

The function mask determines if all cominations of points given in lon and lat lies within the polygon making up the region.

We can now plot the mask:

../../_images/mask_numpy_9_0.png

Finally the mask can now be used to mask out all data that is not in a specific region.

Plot the selected data

../../_images/mask_numpy_13_0.png

Finally we can obtain the region mean:

Global mean:    -0.00329869391794
Central Europe: 0.0326627413837

Create a mask with a different lon/ lat grid

The interesting thing of gridmask is that you can use any lon/ lat grid.

Use a 5° x 5° grid:

../../_images/mask_numpy_19_0.png

Now the grid cells are much larger.