This GitLab instance is undergoing maintenance and is operating in read-only mode.

You are on a read-only GitLab instance.
yearly_cycle_cldhgh.py 2.06 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

describe = """yearly_cycle_cldhgh plot."""


13
def make_plot(config, out_path='.'):
14

15
16
    img_list = []

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

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

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

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

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

65
66
67
68
69
70
71
72
73
74
    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