yearly_cycle_CLDHGH.py 1.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os

import matplotlib.pyplot as plt

from netCDF4 import Dataset


def make_plot(out_path='.',
              cloud_path='/lustre/atlas1/cli115/world-shared/4ue/obs_data/',
              cesm_path='/lustre/atlas1/cli115/world-shared/4ue/b.e10.BG20TRCN.f09_g16.002/'):

    months = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
    percent_vals = []
    model_vals = []
    cldsat_vals = []
    isccp_vals = []

    for month in months:
        # CESM1
        f_cesm = os.path.join(cesm_path, "postproc", "atm", "climos",
                              "b.e10.BG20TRCN.f09_g16.002_{}_aavg_climo.nc".format(month))
        ncid1 = Dataset(f_cesm, mode='r')
        model_cld = ncid1.variables['CLDHGH'][0]

        # CLDSAT
        f_cloudsat = os.path.join(cloud_path, "CLOUDSAT_{}_aavg_climo.nc".format(month))
        ncid2 = Dataset(f_cloudsat, mode='r')
        cldsat_cld = ncid2.variables['CLDHGH'][0]

        # ISCCP
        f_isccp = os.path.join(cloud_path, "ISCCP_{}_aavg_climo.nc".format(month))
        ncid3 = Dataset(f_isccp, mode='r')
        isccp_cld = ncid3.variables['CLDHGH'][0]

        model_vals.append(model_cld)
        cldsat_vals.append(cldsat_cld)
        isccp_vals.append(isccp_cld)

        ncid1.close()
        ncid2.close()
        ncid3.close()

    for percent in model_vals:
        percent = percent * 100
        percent_vals.append(percent)

    # plot months of the year versus CLDHGH for CESM and CLOUDSAT

    plt.plot(months, percent_vals, 'r')
    plt.plot(months, cldsat_vals, 'g--')
    plt.plot(months, isccp_vals, 'c-.')
    plt.xlabel('Months of climatology')
    plt.ylabel('Percent total cloud')
    plt.savefig(os.path.join(out_path, 'CESM_yearly_cycle_CLDHGH.png'), bbox_inches='tight')
    plt.close()


if __name__ == '__main__':
    plt.switch_backend('agg')
    make_plot()