import matplotlib.pyplot as plt
import numpy as np
Load in the data as in previous exercises, except this time we want the "temperature"
array:
with np.load("weather_data.npz") as weather:
temperature = weather["temperature"]
The ground-level slice is at index 0
, so we can grab it and use the np.mean
function to average the values in it:
np.mean(temperature[0])
This number is so high due to it being in Kelvin. Convert it to Celcius with:
temperature -= 273.15
Now, the mean will be in the correct units:
np.mean(temperature[0])
Now, the entire ground-level slice looks like:
fig, ax = plt.subplots()
im = ax.imshow(temperature[0])
fig.colorbar(im)
Including all the data from the higher atmosphere both smooths out the data, as well as bringing its average down.
We do this by giving the mean
function the complete 3D array, but tell it to average along the zeroth axis (altitude):
average_column = np.mean(temperature, axis=0)
fig, ax = plt.subplots()
im = ax.imshow(average_column)
fig.colorbar(im)
If we instead grab just the ground-level layer and average along the latitude axis, we see that it gets warmer the further South you go:
# Higher values of the index are more South
average_by_latitude = np.mean(temperature[0], axis=1)
fig, ax = plt.subplots()
im = ax.plot(average_by_latitude)