Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Unlike xESMF, verde is mainly designed around unstructured grids. Verde has a lot of great examples, we will use an atmospheric one below, but highly reccomend reading though the documents to get a better handle on the API.

https://www.fatiando.org/verde/latest/

Prerequisites

Knowing your way around pandas, xarray, numpy and matplotlib is beneficial. This is not deisgned to be an introduction to any of those packages. We will be using Cartopy for some of the plots as well.

Imports

appdirs   : 1.4.4
cartopy   : 0.26.0
matplotlib: 3.11.2
numpy     : 2.5.4
pandas    : 3.0.6
verde     : 1.9.0

Loading...
lon float64 lat float64 date datetime64[us] sensor str PM25value int64 sensor_type int64 dtype: object

Let’s pick a time that has decent coverage:

date 2022-09-05 16:00:00 36 2022-09-05 17:00:00 36 2022-09-05 18:00:00 36 2022-09-05 19:00:00 36 2022-09-05 20:00:00 36 Name: count, dtype: int64
Loading...

Plotting the data

/home/runner/micromamba/envs/gridding-cookbook-dev/lib/python3.14/site-packages/cartopy/io/__init__.py:263: DownloadWarning: Downloading: https://naturalearth.s3.amazonaws.com/10m_cultural/ne_10m_admin_1_states_provinces_lakes.zip
  warnings.warn(f'Downloading: {url}', DownloadWarning)
<Figure size 800x500 with 2 Axes>

Verde Workflows

Some of these workflows might not work super well from a scientific standpoint, this is just to show the mechanics of the verde package.

Trend Estimation

Same code, different example can be found here: https://www.fatiando.org/verde/latest/tutorials/trends.html

[38.39163129  0.54379964  0.32281663]
<Figure size 800x500 with 2 Axes>

Unlike the Texas example in Verde, hard to see a distinct regional trend.

Data Decimation

BlockReduce(reduction=<function median at 0x7f7bf80847b0>, spacing=0.5)

Sanity check

True

Plotting the decimated datapoints

<Figure size 600x400 with 1 Axes>

Verde Spline

This turtorial runs though this entire workflow, but with a bathymetery dataset: https://www.fatiando.org/verde/latest/tutorials/projections.html

<xarray.Dataset> Size: 2kB
Dimensions:   (northing: 14, easting: 18)
Coordinates:
  * northing  (northing) float64 112B 35.14 35.66 36.18 ... 40.84 41.36 41.88
  * easting   (easting) float64 144B -110.5 -110.0 -109.5 ... -102.4 -101.9
Data variables:
    PM25      (northing, easting) float64 2kB 74.69 69.09 63.62 ... 11.73 6.292
Attributes:
    metadata:  Generated by Spline(mindist=0)

Let’s make a plot with the gridded and masked output, also shows where the datapoints are:

<Figure size 800x500 with 2 Axes>

Xarray

Making the grid into an xarray dataset is 1 line of code!

Loading...

Exporting this as a netCDF:

Summary

Verde and xESMF are two different gridding packages, with two different aims. They both work well with xarray!