In [10]:
import os, sys
import iris
import numpy

In [11]:
cwd = os.getcwd()
repo_dir = '/'
for directory in cwd.split('/')[1:]:
    repo_dir = os.path.join(repo_dir, directory)
    if directory == 'ocean-analysis':
        break

modules_dir = os.path.join(repo_dir, 'modules')
sys.path.append(modules_dir)
import general_io as gio

In [16]:
def calc_ensemble_hemispheric_heat(time_constraint):
    """Calculate the hemispheric change in OHC."""

    model_list = ['CanESM2', 'CCSM4', 'CSIRO-Mk3-6-0', 'GISS-E2-R', 'NorESM1-M']
    nh_values = []
    sh_values = []
    for model in model_list:
        nh_file = '/g/data/r87/dbi599/DRSv2/CMIP5/%s/historical/yr/ocean/r1i1p1/ohc/latest/dedrifted/ohc-nh-sum_Oyr_%s_historical_r1i1p1_all_argo.nc' %(model, model)
        sh_file = '/g/data/r87/dbi599/DRSv2/CMIP5/%s/historical/yr/ocean/r1i1p1/ohc/latest/dedrifted/ohc-sh-sum_Oyr_%s_historical_r1i1p1_all_argo.nc' %(model, model)
    
        nh_cube = iris.load_cube(nh_file, 'ocean heat content nh sum' & time_constraint)
        sh_cube = iris.load_cube(sh_file, 'ocean heat content sh sum' & time_constraint)
    
        nh_value = nh_cube.data[-1] - nh_cube.data[0]
        sh_value = sh_cube.data[-1] - sh_cube.data[0]
        
        nh_values.append(nh_value)
        sh_values.append(sh_value)
        
    nh_ensmean = numpy.median(nh_values)
    sh_ensmean = numpy.median(sh_values)
    
    sh_fraction = sh_ensmean / (nh_ensmean + sh_ensmean)
    
    return nh_ensmean, sh_ensmean, sh_fraction

In [24]:
for start_year in numpy.arange(1861, 1995):
    end_year = start_year + 11
    start_date = str(start_year)+'-01-01'
    end_date = str(end_year)+'-12-31'
    time_constraint = gio.get_time_constraint([start_date, end_date])
    nh_ensmean, sh_ensmean, sh_fraction = calc_ensemble_hemispheric_heat(time_constraint)
    output = '%s-%s: %0.0f%%' %(start_year, end_year, sh_fraction * 100)
    print(output)


1861-1872: 42%
1862-1873: 40%
1863-1874: 50%
1864-1875: 47%
1865-1876: 81%
1866-1877: 46%
1867-1878: 53%
1868-1879: 66%
1869-1880: 87%
1870-1881: 41%
1871-1882: 60%
1872-1883: 96%
1873-1884: -205%
1874-1885: 24%
1875-1886: 46%
1876-1887: 74%
1877-1888: 21%
1878-1889: -7%
1879-1890: 55%
1880-1891: 49%
1881-1892: 57%
1882-1893: 58%
1883-1894: 46%
1884-1895: 87%
1885-1896: 41%
1886-1897: 58%
1887-1898: 77%
1888-1899: -2%
1889-1900: 65%
1890-1901: 34%
1891-1902: 16%
1892-1903: 72%
1893-1904: 377%
1894-1905: -13%
1895-1906: -16%
1896-1907: 23%
1897-1908: -141%
1898-1909: 35%
1899-1910: 81%
1900-1911: 73%
1901-1912: 102%
1902-1913: 109%
1903-1914: 149%
1904-1915: 63%
1905-1916: 64%
1906-1917: 49%
1907-1918: 80%
1908-1919: 78%
1909-1920: 67%
1910-1921: 106%
1911-1922: 110%
1912-1923: 79%
1913-1924: 20%
1914-1925: 46%
1915-1926: 46%
1916-1927: 62%
1917-1928: 61%
1918-1929: 27%
1919-1930: 43%
1920-1931: 39%
1921-1932: 35%
1922-1933: 56%
1923-1934: 37%
1924-1935: 62%
1925-1936: 56%
1926-1937: 53%
1927-1938: 46%
1928-1939: 33%
1929-1940: 51%
1930-1941: 30%
1931-1942: 5%
1932-1943: 2%
1933-1944: 15%
1934-1945: 35%
1935-1946: 36%
1936-1947: 41%
1937-1948: 45%
1938-1949: 37%
1939-1950: 37%
1940-1951: 54%
1941-1952: 68%
1942-1953: 51%
1943-1954: 65%
1944-1955: 61%
1945-1956: 57%
1946-1957: 54%
1947-1958: 66%
1948-1959: 44%
1949-1960: 88%
1950-1961: 44%
1951-1962: 60%
1952-1963: 69%
1953-1964: 280%
1954-1965: 31%
1955-1966: 29%
1956-1967: 41%
1957-1968: 132%
1958-1969: 32%
1959-1970: 59%
1960-1971: 315%
1961-1972: -120%
1962-1973: 159%
1963-1974: 91%
1964-1975: 73%
1965-1976: 72%
1966-1977: 74%
1967-1978: 75%
1968-1979: 96%
1969-1980: 69%
1970-1981: 75%
1971-1982: 73%
1972-1983: 60%
1973-1984: 31%
1974-1985: 44%
1975-1986: 47%
1976-1987: 53%
1977-1988: 34%
1978-1989: 43%
1979-1990: 28%
1980-1991: 40%
1981-1992: 36%
1982-1993: 60%
1983-1994: 42%
1984-1995: 45%
1985-1996: 40%
1986-1997: 65%
1987-1998: 56%
1988-1999: 52%
1989-2000: 70%
1990-2001: 68%
1991-2002: 62%
1992-2003: 53%
1993-2004: 57%
1994-2005: 53%

In [ ]: