import numpy as np
import h5py
from matplotlib import pyplot as PLT
import cartopy.crs as ccrs
import PIL
MOPITT Carbon Monoxide (CO) Mixing Ratio
Summary
Note
By: Cheyenne Land
Tested using Python 3.8.10
1. Setup
2. Open and read file
The file must be in the same directory.
= 'MOP03JM-202001-L3V95.9.3.he5'
FILE_NAME with h5py.File(FILE_NAME, mode='r') as f:
= '/HDFEOS/GRIDS/MOP03/Data Fields/RetrievedCOMixingRatioProfileDay'
name
# Slice data to get the pressure level of your choice
# [Longitude(Xdim):360 , Latitude(Ydim):180, Presure level:9]
# Pressure Level: 0 = 900 hPa, 1 = 800 hPa, 2 = 700 hPa, 3 = 600 hPa
# 4 = 500 hPa, 5 = 400 hpa, 6 = 300 hPa, 7 = 200 hPa, 8 = 100 hPa
= f[name][:]
d = np.transpose(d)
data
# Retrieve the lat and lon data as well as the area of your choice
= f['/HDFEOS/GRIDS/MOP03/Data Fields/Longitude'][:]
lon = f['/HDFEOS/GRIDS/MOP03/Data Fields/Latitude'][:]
lat
# Turn the -9999.0 into a NaN
= np.ma.masked_where(data <= 0, data)
masked_data = data.copy()
CO_mixing_ratio <= 0] = np.nan
CO_mixing_ratio[masked_data
= np.arange(0,9) pressure_levels
3. Plot all graphs in a for loop
for i in pressure_levels:
=(7.20,3.60))
PLT.figure(figsize= PLT.axes(projection=ccrs.PlateCarree())
ax = PLT.contourf(lon, lat, CO_mixing_ratio[i,:,:], 300,
im =PLT.get_cmap('jet'), vmin=0, vmax=600,
cmap=np.arange(0,700, 100),
levels=ccrs.PlateCarree())
transform
ax.coastlines()
= PLT.colorbar(im, shrink = 0.76)
cb 'ppbv', fontsize=8)
cb.set_label(= -i + 9
pressure 'MOP03JM-202001-L3V95.9.3_RetrievedCOMixingRatioProfileDay_'+str(pressure)+'00hPa',
PLT.title(=8)
fontsize
# save the figure in your current directory
"MOP03JM-202001-L3V95.9.3_RetrievedCOMixingRatioProfileDay_"+str(pressure)+"00hPa.jpg",
PLT.savefig(=200)
dpi
PLT.close() PLT.clf()
4. Create gif
Source: GeoDelta Labs.(2020, March 22). How to create an animated time-lapse of temperature using netCDF grid data [Video File]. https://www.youtube.com/watch?v=dSv3-obKv3M
= []
frames = np.arange(1,10)[::-1]
pressure
for j in pressure:
= PIL.Image.open(r'MOP03JM-202001-L3V95.9.3_RetrievedCOMixingRatioProfileDay_'+str(j)+'00hPa.jpg')
new_frame
frames.append(new_frame)
0].save('RetrievedCOMixingRatioProfileDay_PressureLevels.gif', format = 'GIF',
frames[= frames[:], save_all = True, duration = 250,
append_images = 0) loop