# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 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 cartopy.crs as ccrs  # Projections list
# Some defaults:
plt.rcParams['figure.figsize'] = (12, 5)  # Default plot size

# ## Temperature

# **Compute the mean temperature $\overline{T}$. 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
# -

# ## Precipitation

# 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/ERA5_LowRes_Monthly_tp.nc')
ds.tp

# **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 which didn't take place yet ;-), 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 their western parts? Do all three oceans have similar precipitation patterns?
# - where does more than 3000 mm (less than 50 mm) precipitation a year occur?
# - Note that it is easy to use the ".where()" function to highlight these areas. 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

StarcoderdataJupyterScriptsDedupFiltered