yearly_cycle_cldhgh.py 2.3 KB
Newer Older
1
2
3
4
5
6
import os

import matplotlib.pyplot as plt

from netCDF4 import Dataset

7
from livvkit.util import elements as el
8

9
10
11
12
13

describe = """yearly_cycle_cldhgh plot."""


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

17
18
    img_list = []

19
    months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
20
21
22
23
24
25
26
27
    percent_vals = []
    model_vals = []
    cldsat_vals = []
    isccp_vals = []

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

        # CLDSAT
33
        f_cloudsat = os.path.join(cloud_path, "CLOUDSAT_{:02d}_aavg_climo.nc".format(month))
34
35
36
37
        ncid2 = Dataset(f_cloudsat, mode='r')
        cldsat_cld = ncid2.variables['CLDHGH'][0]

        # ISCCP
38
        f_isccp = os.path.join(cloud_path, "ISCCP_{:02d}_aavg_climo.nc".format(month))
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        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')
61
62
    plt.tight_layout()

63
    img_path = os.path.join(out_path, 'CESM_yearly_cycle_CLDHGH.png')
64
    plt.savefig(img_path)
65
66
    plt.close()

67
68
69
70
71
72
73
74
75
76
77
    img_link = os.path.join(os.path.basename(out_path),
                            os.path.basename(img_path))
    img_elem = el.image('yearly_cycle_cldhgh',
                        ' '.join(describe.split()),
                        img_link)
    if config:
        img_elem['Height'] = config['image_height']
    img_list.append(img_elem)

    return img_list

78
79
80
81

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