import os import matplotlib.pyplot as plt from netCDF4 import Dataset from livvkit.util import elements as el describe = """yearly_cycle_cldlow plot.""" def make_plot(config=None, 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/'): img_list = [] months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] percent_vals = [] model_vals = [] cldsat_vals = [] isccp_vals = [] for month in months: # ---------------- Data source at OLCF ------------------------ # CESM1 input_file1 = os.path.join(cesm_path, "postproc", "atm", "climos", "b.e10.BG20TRCN.f09_g16.002_{:02d}_aavg_climo.nc".format(month)) ncid1 = Dataset(input_file1, mode='r') model_cld = ncid1.variables['CLDLOW'][0] # CLDSAT f_cloudsat = os.path.join(cloud_path, "CLOUDSAT_{:02d}_aavg_climo.nc".format(month)) ncid2 = Dataset(f_cloudsat, mode='r') cldsat_cld = ncid2.variables['CLDLOW'][0] # ISCCP f_isccp = os.path.join(cloud_path, "ISCCP_{:02d}_aavg_climo.nc".format(month)) ncid3 = Dataset(f_isccp, mode='r') isccp_cld = ncid3.variables['CLDLOW'][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 CLDLOW 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.tight_layout() img_path = os.path.join(out_path, 'CESM_yearly_cycle_CLDLOW.png') plt.savefig(img_path) plt.close() img_link = os.path.join(os.path.basename(out_path), os.path.basename(img_path)) img_elem = el.image('yearly_cycle_cldlow', ' '.join(describe.split()), img_link) if config: img_elem['Height'] = config['image_height'] img_list.append(img_elem) return img_list if __name__ == '__main__': plt.switch_backend('agg') make_plot()