Assignment: temperature and precipitation data#

# Import the tools we are going to need today:
import matplotlib.pyplot as plt  # plotting library
import numpy as np  # numerical library
import xarray as xr  # netCDF library
import cartopy  # Map projections libary
import as ccrs  # Projections list
# Some defaults:
plt.rcParams['figure.figsize'] = (12, 5)  # Default plot size


Compute the mean temperature \(\overline{T}\) in °C. Plot it.

# Your answer here

Compute the monthly average temperature for each month \(\overline{T_M}\) (annual cycle). I expect a variable of dimensions (month: 12, latitude: 241, longitude: 480). Hint: remember the .groupby() command we learned in the lesson. Now plot the average monthly temperature range, i.e. \(\overline{T_M}max\) - \(\overline{T_M}min\) on a map.

Where is the range of monthly temperature highest? Note the latitudinal differences. Is the variability higher over land or over oceans? Why?

# Your answer here

Compute the zonal mean temperature \(\overline{\left[ T \right]}\). Plot it. At what latitudes is the zonal average temperature equal to 0°C? Describe the differences between North and South. Can you explain them easily? Add \(\left[\overline{T_{January}}\right]\) and \(\left[\overline{T_{July}}\right]\) to the plot.

# Your answer here

Similarly to the decomposition in time, geophysical fields can also be decomposed zonally:

\(A = \left[ A \right] + A^{*}\)

Where \(\left[ A \right]\) is the zonal average and \(A^{*}\) the departure from the zonal average.

Verify that for any field A:

  1. \(\overline{A^{*}} = \overline{A} - \left[ \overline{A} \right]\)

  2. \(A = \left[ \overline{A} \right] + \left[ A' \right] + \overline{A^{*}} + A'^{*}\)

Compute \(\overline{T^{*}}\) (use eq. 1 above), and plot it on a map. Discuss

# Your answer here

Compute the zonal mean temperature over land \(\overline{\left[ T_{Land} \right]}\) and over oceans \(\overline{\left[ T_{Oceans} \right]}\) and plot them both on the same plot. Discuss.

# Your answer here


Open the precipitation file and explore it. The units of monthly precipitation are wrongly labeled (unfortunately). They should read: m per day.

ds = xr.open_dataset('../data/')
<xarray.DataArray 'tp' (time: 480, latitude: 241, longitude: 480)>
[55526400 values with dtype=float32]
  * longitude  (longitude) float32 -179.6 -178.9 -178.1 ... 178.1 178.9 179.6
  * latitude   (latitude) float32 90.0 89.25 88.5 87.75 ... -88.5 -89.25 -90.0
  * time       (time) datetime64[ns] 1979-01-01 1979-02-01 ... 2018-12-01
    units:      m
    long_name:  Total precipitation

Compute the average total annual precipitation (average precipitation over a year, in mm yr\(^{-1}\)) and store it in a variable called “annual_prcp”. Plot it.

# Your answer here

Draw a new plot of “annual_prcp”, this time with a new colormap (‘YlGnBu’) and with the following discrete levels specified: [50, 200, 500, 700, 1000, 1500, 2000, 3000, 5000]. Now have a look at the patterns again.

Using your knowledge from the lecture, try to answer questions such as:

  • why are the oceans (mostly) dryer than land in the subtropics?

  • this was not covered in the lecture, but why is there only one large desert (in Africa) while other continents at the same latitude are rather wet?

  • why are the eastern subtropical oceans dryer than in their western part? Do all three oceans have similar patterns for precipitation?

  • where does it fall more than 3000 mm precipitation a year? Less than 50 mm precipitation a year? Note that it could be easy to use the “.where()” function to highlight these areas easily. Optional: can you come up with a plot showing them on the map?

# Your answer here

Plot the average precipitation in January on a map. Do the same with precipitation in July, and choose the same levels for both maps in order to compare them. Discuss.

# Your answer here