In [1]:
import iris

In [17]:
def hemispheric_comparison(variable, model, argo=False):
    """Compare the hemispheres"""
    
    assert variable in ['areacello', 'volcello']
    if variable == 'volcello':
        long_name = 'ocean_volume'
    else:
        long_name = 'cell_area'
    
    if argo:
        nh_subset = lambda cell: 0.0 <= cell <= 60.0
        sh_subset = lambda cell: -60.0 <= cell < 0.0
    else:
        nh_subset = lambda cell: cell >= 0.0
        sh_subset = lambda cell: cell < 0.0
    
    nh_constraint = iris.Constraint(latitude=nh_subset)
    sh_constraint = iris.Constraint(latitude=sh_subset)
    
    infile = '/g/data/ua6/DRSv2/CMIP5/%s/historical/fx/ocean/r0i0p0/%s/latest/%s_fx_%s_historical_r0i0p0.nc' %(model, variable, variable, model)
    globe_cube = iris.load_cube(infile, long_name)
    nh_cube = iris.load_cube(infile, long_name & nh_constraint)
    sh_cube = iris.load_cube(infile, long_name & sh_constraint)
    
    if variable == 'volcello' and argo:
        depth_constraint = iris.Constraint(depth=lambda cell: cell < 2000.0)
        globe_cube = globe_cube.extract(depth_constraint)
        nh_cube = nh_cube.extract(depth_constraint)
        sh_cube = sh_cube.extract(depth_constraint)
        
    globe_sum = globe_cube.data.sum()
    nh_sum = nh_cube.data.sum()
    sh_sum = sh_cube.data.sum()
    
    print(globe_sum, nh_sum, sh_sum, nh_sum + sh_sum)
    
    print(sh_sum / globe_sum)

In [18]:
hemispheric_comparison('volcello', 'CSIRO-Mk3-6-0')


1.33911e+18 5.45417e+17 7.93698e+17 1.33911e+18
0.592704

In [19]:
hemispheric_comparison('volcello', 'CSIRO-Mk3-6-0', argo=True)


6.20361e+17 2.38315e+17 3.32922e+17 5.71237e+17
0.536659

In [20]:
hemispheric_comparison('volcello', 'CanESM2')


1.32367e+18 5.45191e+17 7.78481e+17 1.32367e+18
0.588122

In [21]:
hemispheric_comparison('volcello', 'CanESM2', argo=True)


6.08632e+17 2.34689e+17 3.2724e+17 5.61929e+17
0.537665

In [36]:
hemispheric_comparison('areacello', 'CSIRO-Mk3-6-0')


3.60752e+14 1.58128e+14 2.02624e+14 3.60752e+14
0.561672

In [37]:
hemispheric_comparison('areacello', 'CanESM2')


3.53282e+14 1.51885e+14 2.01397e+14 3.53282e+14
0.570075

In [38]:
import iris.plot as iplt
import matplotlib.pyplot as plt

In [39]:
%matplotlib inline

In [82]:
def plot_metric(model, aa_physics, ylim=None):
    """Plot the OHC SH fraction metric"""
    
    #assert var in ['ohc-nh-sum-div-globe-sum']
    
    hist_file = '/g/data/r87/dbi599/DRSv2/CMIP5/%s/rcp85/yr/ocean/r1i1p1/ohc/latest/dedrifted/ohc-nh-sum-div-globe-sum_Oyr_%s_historical-rcp85_r1i1p1_all.nc' %(model, model)
    ghg_file = '/g/data/r87/dbi599/DRSv2/CMIP5/%s/historicalGHG/yr/ocean/r1i1p1/ohc/latest/dedrifted/ohc-nh-sum-div-globe-sum_Oyr_%s_historicalGHG_r1i1p1_all.nc' %(model, model)
    aa_file = '/g/data/r87/dbi599/DRSv2/CMIP5/%s/historicalMisc/yr/ocean/r1i1%s/ohc/latest/dedrifted/ohc-nh-sum-div-globe-sum_Oyr_%s_historicalMisc_r1i1%s_all.nc' %(model, aa_physics, model, aa_physics)
    
    time_constraint = iris.Constraint(time=lambda t: t.point <= iris.time.PartialDateTime(year=2100, month=12, day=31))
    
    hist_cube = iris.load_cube(hist_file, time_constraint)
    ghg_cube = iris.load_cube(ghg_file, time_constraint)
    aa_cube = iris.load_cube(aa_file, time_constraint)
    
    iplt.plot(aa_cube, color='blue', label='AA-only')
    iplt.plot(ghg_cube, color='red', label='GHG-only')
    iplt.plot(hist_cube, color='black', label='hist-rcp85')

    if ylim:
        plt.ylim(ylim[0], ylim[1])
    
    plt.title(model)
    plt.legend(loc=3)
    print(plt.ylim())
    plt.show()

In [77]:
plot_metric('CanESM2', 'p4')


(41.262, 41.277999999999999)

In [78]:
plot_metric('CCSM4', 'p10')


(40.6905, 40.695)

In [84]:
plot_metric('CSIRO-Mk3-6-0', 'p4', ylim=(40.805, 40.815))


(40.805, 40.814999999999998)

In [80]:
plot_metric('GISS-E2-R', 'p107')


(41.272000000000006, 41.278000000000006)

In [81]:
plot_metric('NorESM1-M', 'p1')


(40.757999999999996, 40.771999999999998)

In [ ]: