Overview
Teaching: 20 min
Exercises: 10 minQuestions
How can I look at datasets using Python?
What operations are available?
Objectives
Use the Xarray library to read a file
Explain dimensions, variables and attributes
Perform simple numpy operations on datasets
There are quite a few libraries for working with climate data files in Python, here are a few:
Most are equally happy to open a file either on disk or over OPENDAP
We’ll mostly look at xarray
here, a ‘higher-level’ library for working with gridded data
Example: Inspecting a file with xarray
- Use xarray to open a file or OPENDAP link
- What information can we see about the data?
Behind the scenes Xarray stores data using an optimised library called numpy
,
with Xarray adding coordinates and metadata.
A lot of the time you don’t want to work with the whole dataset, you need to reduce it somehow. Perhaps you’re only interested in a specific region, or want to work with seasonal instead of monthly data
Example: Slicing and dicing datasets
- What are xarray’s data subset options?
According to model data, what temperature was it in Melbourne today?
Example: Calculating the NINO 3.4 index
The NINO 3.4 index is defined as the anomaly over the region (5N - 5S, 170W - 120W) compared to the historical average between 1961 and 1990
How do the RCP45 and RCP85 scenarios’s NINO 3.5 index compare?
Key Points
Xarray lets you read NetCDF files in Python and inspect their contents
NetCDF fields are made up of data + dimensions + metadata
Numpy and Scipy let you perform calculations on fields