In [1]:
    
import matplotlib.pyplot as plt
import iris
import iris.plot as iplt
import numpy
import iris.coord_categorisation
    
In [2]:
    
%matplotlib inline
    
In [3]:
    
infile = '/g/data/ua6/DRSv2/CMIP5/CSIRO-Mk3-6-0/historical/mon/ocean/r1i1p1/msftmyz/latest/msftmyz_Omon_CSIRO-Mk3-6-0_historical_r1i1p1_185001-200512.nc'
    
In [4]:
    
cube = iris.load_cube(infile, 'ocean_meridional_overturning_mass_streamfunction')
    
    
In [5]:
    
print(cube)
    
    
In [6]:
    
dim_coord_names = [coord.name() for coord in cube.dim_coords]
print(dim_coord_names)
    
    
In [7]:
    
aux_coord_names = [coord.name() for coord in cube.aux_coords]
print(aux_coord_names)
    
    
In [8]:
    
mf_cube = cube[:, 0, : ,:]
    
In [9]:
    
mf_cube
    
    Out[9]:
In [10]:
    
mf_clim_cube = mf_cube.collapsed('time', iris.analysis.MEAN)
    
In [11]:
    
mf_clim_cube
    
    Out[11]:
In [12]:
    
iplt.contour(mf_clim_cube, colors='k')
# plt.clabel(contour_plot) fmt='%.1f')
plt.show()
    
    
    
In [13]:
    
depth_constraint = iris.Constraint(depth= lambda cell: cell <= 250)
lat_constraint = iris.Constraint(latitude=lambda cell: -30.0 <= cell < 30.0)
    
In [14]:
    
tropics_cube = mf_clim_cube.extract(depth_constraint & lat_constraint)
    
In [18]:
    
iplt.contourf(tropics_cube, cmap='RdBu_r',
              levels=[-1.25e+10, -1.0e+10, -7.5e+9, -5.0e+9, -2.5e+9, 0, 2.5e+9, 5.0e+9, 7.5e+9, 1.0e+10, 1.25e+10],
              extend='both')
plt.colorbar()
plt.show()
    
    
    
In [27]:
    
tropics_cube.data.max()
    
    Out[27]:
In [16]:
    
sh_lat_constraint = iris.Constraint(latitude=lambda cell: -30.0 <= cell < 0.0)
nh_lat_constraint = iris.Constraint(latitude=lambda cell: 0.0 < cell <= 30.0)
    
In [19]:
    
sh_cube = mf_cube.extract(depth_constraint & sh_lat_constraint)
nh_cube = mf_cube.extract(depth_constraint & nh_lat_constraint)
    
In [18]:
    
sh_cube
    
    Out[18]:
Probably needs to be a depth and latitude weighted mean...
In [21]:
    
def convert_to_annual(cube, full_months=False, aggregation='mean'):
    """Convert data to annual timescale.
    Args:
      cube (iris.cube.Cube)
      full_months(bool): only include years with data for all 12 months
    """
    iris.coord_categorisation.add_year(cube, 'time')
    iris.coord_categorisation.add_month(cube, 'time')
    if aggregation == 'mean':
        aggregator = iris.analysis.MEAN
    elif aggregation == 'sum':
        aggregator = iris.analysis.SUM
    cube = cube.aggregated_by(['year'], aggregator)
    if full_months:
        cube = cube.extract(iris.Constraint(month='Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec'))
  
    cube.remove_coord('year')
    cube.remove_coord('month')
    return cube
    
In [22]:
    
sh_cube = convert_to_annual(sh_cube)
nh_cube = convert_to_annual(nh_cube)
    
In [25]:
    
sh_metric = sh_cube.collapsed(['depth', 'latitude'], iris.analysis.MEAN) # weights=grid_areas)
nh_metric = nh_cube.collapsed(['depth', 'latitude'], iris.analysis.MEAN) # weights=grid_areas)
    
    
In [27]:
    
iplt.plot(sh_metric)
iplt.plot(nh_metric)
plt.show()
    
    
In [28]:
    
iplt.plot(nh_metric - sh_metric)
plt.show()
    
    
In [ ]: