Climate Data

Using NetCDF in Python

Overview

Teaching: 20 min
Exercises: 10 min
Questions
  • 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

Notebook

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

Notebook

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

Notebook

How do the RCP45 and RCP85 scenarios’s NINO 3.5 index compare?

OPENDAP links

Key Points