1. Load the single cube from the file iris.sample_data_path('SOI_Darwin.nc'). This contains monthly values of the Southern Oscillation Index.
In [1]:
import iris
soi = iris.load_cube(iris.sample_data_path('SOI_Darwin.nc'))
print(soi)
2. Add two new coordinates based upon the time coordinate, one categorising the meteorological season, and one the year the season was in (hint: add_season and add_season_year are pre-defined). Examine the resulting coordinates.
In [2]:
import iris.coord_categorisation as coord_cat
coord_cat.add_season(soi, 'time')
coord_cat.add_season_year(soi, 'time')
print(soi)
3. Compute the seasonal means from this cube (i.e. average together the times within in each individual season). You should end up with a time series of length 593 (hint: you can specify two coordinates to aggregate over).
In [3]:
soi_seasons = soi.aggregated_by(['season', 'season_year'],
iris.analysis.MEAN)
print(soi_seasons)
4. Now compute the seasonal climatology. You should end up with a cube of size 4, one point per season (hint: you can use aggregated_by again).
In [4]:
soi_clims = soi.aggregated_by('season', iris.analysis.MEAN)
print(soi_clims)
5. Extract the DJF season from both the climatology and seasonal means. Use these to compute a time series of DJF anomalies with respect to the DJF mean (hint: remember you can subtract cubes of different dimensionality).
In [5]:
winter = iris.Constraint(season='djf')
soi_djf = soi_seasons.extract(winter)
soi_djf_mean = soi_clims.extract(winter)
print(soi_djf)
print(soi_djf_mean)
soi_djf_anoms = soi_djf - soi_djf_mean
print(soi_djf_anoms)
6. Finally, give the DJF anomalies cube a sensible name and plot the time-series with labelled axes.
In [6]:
import iris.quickplot as qplt
soi_djf_anoms.rename('SOI_Darwin_anomalies')
qplt.plot(soi_djf_anoms)
qplt.show()
In [ ]: