In [ ]:
%matplotlib inline

Iris introduction course

8. Final Exercise

This exercise draws on various aspects of Iris's functionality that were introduced in the course.

Once you have attempted the exercise, you can check your answers with the provided sample solutions.

Setup


In [ ]:
import matplotlib.pyplot as plt
import iris
import iris.plot as iplt

Exercise:

Produce a set of plots that provide a comparison of decadal-mean air temperatures over North America.

Part 1

Load 'A1B_north_america.nc' from the Iris sample data.


In [ ]:
# EDIT for user code ...

In [ ]:
# SAMPLE SOLUTION :  Un-comment and execute the following to see a possible solution ...

# %load solutions/iris_exercise_8.1

Part 2

Extract just data from the year 1980 and beyond from the loaded data.


In [ ]:
# user code ...

In [ ]:
# SAMPLE SOLUTION
# %load solutions/iris_exercise_8.2

Part 3

Define a function that takes a coordinate and a single time point as arguments, and returns the decade. For example, your function should return 2010 for the following:

time = iris.coords.DimCoord([10], 'time',
                           units='days since 2018-01-01')
print(your_decade_function(time, time.points[0]))

In [ ]:
# user code ...

In [ ]:
# SAMPLE SOLUTION
# %load solutions/iris_exercise_8.3

Part 4

Add a "decade" coordinate to the loaded cube using your function and the coord categorisation module.

(Hint: Look at the documentation for iris.coord_categorisation.add_categorised_coord, which can be used to create a new categorised coordinate from such a function.)


In [ ]:
# user code ...

In [ ]:
# SAMPLE SOLUTION
# %load solutions/iris_exercise_8.4

Part 5

Calculate the decadal means cube for this scenario.


In [ ]:
# user code ...

In [ ]:
# SAMPLE SOLUTION
# %load solutions/iris_exercise_8.5

Part 6

Create a figure with 3 rows and 4 columns displaying the decadal means, with the decade displayed prominently in each axes' title.


In [ ]:
# user code ...

In [ ]:
# SAMPLE SOLUTION
# %load solutions/iris_exercise_8.6