绘图OMI使用Basemap包来卫星日常数据

时间:2016-06-15 12:53:25

标签: python matplotlib matplotlib-basemap hdf

OMI (臭氧监测仪器)测量关键的空气质量成分,如二氧化氮(NO2),臭氧(O3)。我下载的每日columnO3文件here代表了对流层臭氧柱浓度的全球分布。

文件的大小约为90Mb。有兴趣的人可以下载任何一个。

这里的数据以(15,720,1440)

的形式上传
  • 15是候选场景数量
  • 1440是X维度,经度[-180:180]从左到右
  • 720是从下到上的Y维,纬度[-90:90]

h5py 和matplotlib.basemap,这是我的尝试:

import h5py
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import sys

file = h5py.File("OMI-Aura_L2-OMNO2_2016m0529t1759-o63150_v003-2016m0531t023832.he5", 'r')
dataFields=file['HDFEOS']['GRIDS']['ColumnAmountNO2']['Data Fields']
SDS_NAME='ColumnAmountNO2'
data=dataFields[SDS_NAME]
map_label=data.attrs['Units'].decode()

fv=data.attrs['_FillValue']
mv=data.attrs['MissingValue']
offset=data.attrs['Offset']
scale=data.attrs['ScaleFactor']

lat=dataFields['Latitude'][:][0]
min_lat=np.min(lat)
max_lat=np.max(lat)
lon=dataFields['Longitude'][:][0]
min_lon=np.min(lon)
max_lon=np.max(lon)     

dataArray=data[:][1]
dataArray[dataArray==fv]=np.nan
dataArray[dataArray==mv]=np.nan
dataArray = scale * (dataArray - offset)    

fig = plt.figure()
data_mask = np.ma.masked_array(data[0], np.isnan(data[0]))
m = Basemap(projection='cyl', resolution='l',llcrnrlat=-90, urcrnrlat = 90,llcrnrlon=-180, urcrnrlon = 180)
m.drawcoastlines(linewidth=0.5)
m.drawparallels(np.arange(-90., 120., 30.), labels=[1, 0, 0, 0])
m.drawmeridians(np.arange(-180, 180., 45.), labels=[0, 0, 0, 1])
my_cmap = plt.cm.get_cmap('gist_stern_r')
my_cmap.set_under('w')
m.pcolormesh(lon, lat, data_mask,latlon=True, cmap=my_cmap)
cb = m.colorbar()
cb.set_label(map_label)
plt.autoscale()
plt.show() 

图如下所示:

enter image description here

使用 Panoply ,候选人0,图如下所示:

enter image description here

我的问题

  • 如何设置候选场景以表示每日全球发行(候选场景的含义是什么?它与轨道轨道相对应吗?)

  • 我的代码没有显示正确的数字有什么问题

我的目标

下图是从互联网上删除的。这是我的目标风格!

任何建议或教程指南都将不胜感激!

enter image description here

1 个答案:

答案 0 :(得分:1)

LatitudeLongitude变量也有缺失值,即-1.2676506e + 30,因此会导致绘图中出现大的xrange和yrange。另请注意,_FillValueMissingValue属性是列表,因此您使用NaN替换是错误的。

import h5py
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import sys

def array_with_nans(h5var):
    """ Extracts the array and replaces fillvalues and missing values with Nans
    """
    array = h5var[:] # not very efficient

    # _FillValue and MissingValue attributes are lists
    for value in h5var.attrs['MissingValue']:
        array[array==value]=np.nan

    for value in h5var.attrs['_FillValue']:
        array[array==value]=np.nan

    return array


#file = h5py.File("OMI-Aura_L2-OMNO2_2016m0529t1759-o63150_v003-2016m0531t023832.he5", 'r')
file = h5py.File("OMI-Aura_L2G-OMNO2G_2004m1001_v003-2012m0714t175148.he5", 'r')
dataFields=file['HDFEOS']['GRIDS']['ColumnAmountNO2']['Data Fields']
SDS_NAME='ColumnAmountNO2'
data=dataFields[SDS_NAME]
map_label=data.attrs['Units'].decode()

offset=data.attrs['Offset'][0]
print("offset: {}".format(offset))
scale=data.attrs['ScaleFactor'][0]
print("scale: {}".format(scale))

candidate = 0

dataArray=array_with_nans(data)[candidate]    
dataArray = scale * (dataArray - offset) 

lat = array_with_nans(dataFields['Latitude'])[candidate]
lon = array_with_nans(dataFields['Longitude'])[candidate]

fig = plt.figure()
data_mask = np.ma.masked_array(dataArray, np.isnan(dataArray))


m = Basemap(projection='cyl', resolution='l',llcrnrlat=-90, urcrnrlat = 90,llcrnrlon=-180, urcrnrlon = 180)
m.drawcoastlines(linewidth=0.5)
m.drawparallels(np.arange(-90., 120., 30.), labels=[1, 0, 0, 0])
m.drawmeridians(np.arange(-180, 180., 45.), labels=[0, 0, 0, 1])
my_cmap = plt.cm.get_cmap('gist_stern_r')
my_cmap.set_under('w')
m.pcolormesh(lon, lat, data_mask,latlon=True, cmap=my_cmap)
cb = m.colorbar()
cb.set_label(map_label)
plt.autoscale()
plt.show() 

最好每个帖子只询问一个问题,你不太可能得到候选人场景的含义。您可以在product documentation

中找到答案