Skip to content

๐Ÿ‘‹ Welcome to the climatrix Tutorial

This tutorial will walk you through some typical use cases showing how climatrix makes managing climate data easier.

We'll simulate sparse meteorological observations spread across Europe.


๐Ÿ› ๏ธ Step A: Configure Access to CDS

Warning

If you already have a ~/.cdsapirc file, you can skip this step.

To configure access to the CDS (Climate Data Store), run:

cm dataset config cds

To configure CDS store.

๐Ÿ“ฅ Step B: Download ERA5-Land Reanalysis Data

We'll use the ERA5-Land global reanalysis product. To download it, run:

cm dataset download era5-land --year 2018 --month 10 --day 12 --target ./era5-land.nc
Note

Downloading data can take a few minutesโ€”please be patient.

๐Ÿ“‚ Step C: Open the Dataset

Weโ€™ll open the dataset using the climatrix accessor:

import xarray as xr
import climatrix as cm # (1)!

dset = xr.open_dataset("./era5-land.nc").cm
  1. Even though we're not using climatrix directly, we must import it to enable the climatrix xarray accessor to available.

๐ŸŒ Step D: Shift to Signed Longitude Convention

ERA5-Land uses the positive longitude convention (\(\lambda \in [0, 360]\)). To make it easier to work with Europe, weโ€™ll convert it to the signed convention (\(\lambda \in [-180, 180]\)).

dset = dset.to_signed_longitude()
Warning

Changing longitude convention on a large dataset can be time and memory intensive.

๐ŸŒ Step E: Subset to Europe

We'll now extract a region covering Europe:

europe = dset.subset(north=71, south=36, west=-24, east=35)

โฑ๏ธ Step F: Select a Single Time Instant

Note

cliamtrix currently doesnโ€™t support plotting dynamic datasets. Letโ€™s select a single timestamp.

To select a single time instant, let's use:

europe = europe.time("2018-10-12T04:00:00")
europe.plot()
Europe

Tip

You can also pass Python datetime object to the time method.

๐ŸŽฏ Step G: Sample Data Around Warsaw

We'll create a sparse sample of data points around Warsaw, using a normal distribution:

WARSAW = (21.017532, 52.237049)
sparse = europe.sample_normal(number=5_00, center_point=WARSAW, sigma=1.5)
Tip

You can use the portion argument instead of number to sample a fraction of the dataset (e.g., 50%).

๐Ÿ–ผ๏ธ Step H: Plot the Sparse Observations

Now we can plot the output:

sparse.plot()

Sparse observation arount Warsaw

Warning

Plotting requires downloading coastline and border data, so it may take longer the first time.

๐Ÿ” Step I: Reconstruct Using IDW

Weโ€™ll reconstruct a dense field from the sparse data using Inverse Distance Weighting (IDW):

idw = sparse.reconstruct(europe.domain, method="idw") # (1)!
idw.plot()
  1. We want to reconstruct data for all Europe (europe.domain).

Reconstructed values

Note

Note that we reconstructed the data for the entire Europe. Those visible artifacts are the result of too few samples concentrated around Warsaw. They are not representative for the entire Europe.

๐Ÿ“Š Step J: Compare with Original Data

We'll use Comparison object to visualize the differences.

import matplotlib.pyplot as plt # (1)!

cmp = cm.Comparison(europe, idw) 
cmp.plot_diff()
cmp.plot_signed_diff_hist()

plt.show()
  1. We explicitly import matplotlib to be able to run plt.show() and display figures.

Map of differences Histogram of signed differences