yearly_cycle_cldtot.py 2.13 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
describe = """
Climatological monthly average of total cloud cover over Greenland 
12
for Model (red), ISCCP (green; Rossow and Schiffer, 1999), and CLOUDSAT (cyan; 
13
14
Kay and Gettelman, 2009).
"""
15

16
17
title = "Monthly total cloud cover over Greenland"

18

19
def make_plot(config, out_path='.'):
20

21
22
    img_list = []

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

    for month in months:
30
        ncid1 = Dataset(config['atm_glob'].replace('??', '{:02d}'.format(month)), mode='r')
31
32
33
        model_cld = ncid1.variables['CLDTOT'][0]

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

        # ISCCP
39
        f_isccp = os.path.join(config['cloud_data'], "ISCCP_{:02d}_aavg_climo.nc".format(month))
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
        ncid3 = Dataset(f_isccp, mode='r')
        isccp_cld = ncid3.variables['CLDTOT'][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)

55
    # plot months of the year versus CLDTOT for Model and CLOUDSAT
56
57
58
59
60
61

    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')
62
63
    plt.tight_layout()

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

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

    return img_list