๐ 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
- 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()

๐ฏ 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()
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()
- We want to reconstruct data for all Europe (
europe.domain
).
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()
- We explicitly import
matplotlib
to be able to runplt.show()
and display figures.