Using grids

Grids are a core component of athmospheric modelling. They are used to discretize the domain of the problem and to store the values of the variables at the grid points.

In this notebook we will see how to create grids and use them in emiproc.

Regular grids

Most of the time, regular latitude longitude grids are used. They are usually define by the number of points in the latitude and longitude directions and the spacing between the points. When not modelling the whole globe, the longitude and latitude ranges are also needed.

[1]:
from emiproc.grids import RegularGrid

grid = RegularGrid(xmin=110, xmax=155, ymin=-45, ymax=-10, nx=20, ny=16)
grid

[1]:
RegularGrid(x(110,155)_y(-45,-10)_nx(20)_ny(16))

This created an emiproc object of the RegularGrid type.

We can visualize the grid using geopandas capabilities. Interanly the geometry is stored in the gdf attribute of the grid.

[2]:
# Be careful, this can be slow for large grids
grid.gdf.explore()
[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook

There are other paramters you can use to define the grid, such as resolution.

[3]:
resolution_basedgrid = RegularGrid(
    xmin=110, xmax=160, ymin=-45, ymax=-10, dx=5, dy=5)
# This creates a grid with 5x5 degree cells size
resolution_basedgrid

[3]:
RegularGrid(x(110,160)_y(-45,-10)_nx(10)_ny(7))

Hexagonal grid

Similarly to regular grid, hexagonal grids or “honeycomb” grids can be used.

[4]:
from emiproc.grids import HexGrid
grid = HexGrid(xmin=110, xmax=155, ymin=-45, ymax=-10,spacing=5)
grid.gdf.explore()
[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Geopandas grid

As emiproc is based on geopandas, you can also use any geometry that is a geopandas dataframe as a grid.

For example we could create a “country grid” where each country is a polygon belonging to the grid. We can use emiproc utilities to get the data about the countries and create the grid.

[5]:
from emiproc.grids import GeoPandasGrid

# Utitlies of countries based on natural earth data
from emiproc.utilities import get_natural_earth

countries = get_natural_earth(
    resolution='10m',
    category='cultural',
    name='admin_0_countries',

)
# This data contains the geometry of the countries
countries.head()
[5]:
featurecla scalerank LABELRANK SOVEREIGNT SOV_A3 ADM0_DIF LEVEL TYPE TLC ADMIN ... FCLASS_TR FCLASS_ID FCLASS_PL FCLASS_GR FCLASS_IT FCLASS_NL FCLASS_SE FCLASS_BD FCLASS_UA geometry
0 Admin-0 country 0 2 Indonesia IDN 0 2 Sovereign country 1 Indonesia ... None None None None None None None None None MULTIPOLYGON (((117.70361 4.16341, 117.70361 4...
1 Admin-0 country 0 3 Malaysia MYS 0 2 Sovereign country 1 Malaysia ... None None None None None None None None None MULTIPOLYGON (((117.70361 4.16341, 117.69711 4...
2 Admin-0 country 0 2 Chile CHL 0 2 Sovereign country 1 Chile ... None None None None None None None None None MULTIPOLYGON (((-69.51009 -17.50659, -69.50611...
3 Admin-0 country 0 3 Bolivia BOL 0 2 Sovereign country 1 Bolivia ... None None None None None None None None None POLYGON ((-69.51009 -17.50659, -69.51009 -17.5...
4 Admin-0 country 0 2 Peru PER 0 2 Sovereign country 1 Peru ... None None None None None None None None None MULTIPOLYGON (((-69.51009 -17.50659, -69.63832...

5 rows × 169 columns

[6]:
# Now create the grid from the country shapes
grid = GeoPandasGrid(countries, name="country_grid")
grid.gdf.explore()
[6]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Note that this grid is note covering the oceans, so if you use it, you will have to take care of the ocean values in an other way.

Conclusion

After this tutorial you should have understood the concept of grids in emiproc. You should be able to create a grid and use it in your simulation.

Grids are very flexible and they can use for remapping very efficiently.