In [1]:
import iris
import iris.analysis.cartography
fname = iris.sample_data_path('uk_hires.pp')
cube = iris.load_cube(fname, 'air_potential_temperature')
cube.coord('grid_latitude').guess_bounds()
cube.coord('grid_longitude').guess_bounds()
grid_areas = iris.analysis.cartography.area_weights(cube)
area_avg = cube.collapsed(['grid_longitude', 'grid_latitude'],
iris.analysis.MEAN,
weights=grid_areas)
print(area_avg)
Exercise 5: What other aggregators are available? Calculate the potential temperature variance over model level for the area averaged cube (hint: We want to reduce the vertical dimension, and end up with a cube of length 3). Print the data values of the resulting cube.
In [2]:
var = area_avg.collapsed('model_level_number', iris.analysis.VARIANCE)
print(var.data)