#!/usr/bin/env python

from pyhdf.SD import SD, SDC 

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.cm as cm
import calendar

#----------------------------------------------------------------------------------------#
# Inputs

file_name = './inputs/myd06_granules_viz/MYD06_L2.A2008015.1435.006.2013342100940.hdf'

#----------------------------------------------------------------------------------------#
# Read HDF Files

file = SD(file_name, SDC.READ)

cer_id = file.select('Cloud_Effective_Radius')
cer_pcl_id = file.select('Cloud_Effective_Radius_PCL')

cer_data = cer_id.get()
cer_pcl_data = cer_pcl_id.get()

#----------------------------------------------------------------------------------------#
# Extract Year, Month, Day, Hour and Minutes from file name

path = file_name.split('/')
name = path[len(path)-1]
list = name.split('.')

hhmm = list[2]
hh = int(hhmm[0:2])
mm = int(hhmm[2:4])

year = int(list[1][1:5])
dayofyear = int(list[1][5:8])

month = 1
day = dayofyear
while day - calendar.monthrange(year,month)[1] > 0 and month <= 12:
	day = day - calendar.monthrange(year,month)[1]
	month = month + 1

print year, month, day, hh, mm

#----------------------------------------------------------------------------------------#
# Plot data

attributes_cer_id = cer_id.attributes()
attributes_cer_pcl_id = cer_pcl_id.attributes()

data_01 = cer_data * attributes_cer_id['scale_factor']
data_02 = cer_pcl_data * attributes_cer_pcl_id['scale_factor']

shape_data_01 = data_01.shape
for i in range(shape_data_01[0]):
	for j in range(shape_data_01[1]):
		if data_02[i,j] > 0: data_01[i,j] = data_02[i,j]

cmap = [(0.0,0.0,0.0)] + [(cm.jet(i)) for i in xrange(1,256)] 
cmap = mpl.colors.ListedColormap(cmap)

bounds = [-100,0,5,10,15,20,25,30,35,40,45,50,55,60]

norm = mpl.colors.BoundaryNorm(bounds, cmap.N)

img = plt.imshow(np.fliplr(data_01), cmap=cmap, norm=norm,
                  interpolation='none', origin='lower')

cbar_bounds = [0,5,10,15,20,25,30,35,40,45,50,55,60]
cbar_ticks = [0,5,10,15,20,25,30,35,40,45,50,55,60]     
               
cbar = plt.colorbar(img, cmap=cmap, norm=norm, boundaries=cbar_bounds, ticks=cbar_ticks)
cbar.ax.set_yticklabels(cbar_ticks, fontsize=10)

title = 'Cloud Effective Radius (PCL + nonPCL) \n MYD06 C6 ({}-{:02d}-{:02d}; {:02d}h{:02d})'
plt.title(title.format( year, month, day, hh, mm), fontsize=10)

plt.savefig("myd06_c6_cloud_effective_radius_PCL_and_nonPCL_baseline.png", 
            bbox_inches='tight', dpi=200)
plt.show()

About / Au sujet de

Ben
Created:
12 avril 2017 21:50:21

Updated:
12 avril 2017 21:50:21

License / Licence

MIT License

Abstract / Résumé