查看原文
其他

Python安装geopandas库绘制NASA-OMI卫星空气质量全球分布图(附2020年6月中国省、市、县行政区划shp)

隐阳勒布朗 气象水文科研猫 2023-09-06

0 Python3安装geopandas库:

方法1:pip install geopandas

方法2:conda install -c conda-forge geopandas


1 geopandas库绘制2021年河南省市级行政地图

import geopandas as gpdimport matplotlib.pyplot as pltfrom matplotlib import rcParamsconfig = {"font.family":'Times New Roman',"font.size":16,"mathtext.fontset":'stix'}rcParams.update(config)henan=gpd.GeoDataFrame.from_file('F:/RMeteoInfo/data/map/henan.shp',encoding='utf-8')data=gpd.read_file('F:/RMeteoInfo/data/map/henan.dbf',encoding='utf-8')henan1= data.copy()henan1['coords']=henan1['geometry'].apply(lambda x: x.representative_point().coords[0])henan1.plot(figsize=(8,6),column='name',legend=False,cmap='hsv',edgecolor='k')font3={'family':'SimHei','size':16,'color':'k'}for n, i in enumerate(henan1['coords']): plt.text(i[0]-0.2,i[1],henan1['name'][n],fontdict=font3,horizontalalignment="left")plt.title('2021年河南省市级行政地图',fontdict=font3)plt.grid(True,alpha=0.5)plt.savefig('F:/Rpython/lp36/plot124.1.png',dpi=800,bbox_inches='tight',pad_inches=0)plt.show()


2 绘制2019年NASA-OMI卫星空气质量全球分布图

2.1 geopandas库绘制

import numpy as npimport h5pyimport globimport geopandas as gpdimport pandas as pdfrom shapely.geometry import Polygonfrom matplotlib.pylab import pltworld = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))files = glob.glob('F:/Rpython/lp36/data/moyu1025/co2/*')print(files[0:3])PIXEL_SIZE = 0.25lon = np.arange(-180, 180, PIXEL_SIZE)lat = np.arange(-90, 90, PIXEL_SIZE)FILL_VALUE = -1.2676506e+30def monthly_no2(files, filter_to_nan = 14.5): """ Return monthly averaged $NO_2$ matrix from a list of files """ arr = np.empty((len(files), lat.shape[0], lon.shape[0]), dtype=float) p = 'ColumnAmountNO2TropCloudScreened' for ix, file in enumerate(files): with h5py.File(file, 'r') as f: data = f['HDFEOS']['GRIDS']['ColumnAmountNO2']['Data Fields'][p][:] data[(data == FILL_VALUE) | (data <= 0)] = np.nan arr[ix] = data average_monthly = np.log10(np.nanmean(arr, axis = 0)) average_monthly[average_monthly < filter_to_nan] = np.nan return average_monthlyaverage_monthly = monthly_no2(files)continents = world.dissolve(by='continent')continents = continents[~continents.index.isin(['Seven seas (open ocean)', 'Antarctica'])]continents = continents.geometry.explode().reset_index()fig, ax = plt.subplots(1, figsize=(16,10))vmin=average_monthly.min()vmax=average_monthly.max()ax.pcolormesh(lon,lat,average_monthly, cmap='cividis')# continents.boundary.plot(ax=ax, color='black')ax.set_xlim(-180,180)ax.set_ylim(-90, 90)plt.savefig('F:/Rpython/lp36/plot125.1.png',dpi=800,bbox_inches='tight',pad_inches=0)plt.show()


2.2 cartopy库绘制

cf=ax.contourf(lon,lat,average_monthly,levels=levs,cmap=cmaps.NCV_bright,extend='both')


3 获取本文中国行政区划shp数据的途径:

气象水文科研猫公众号后台回复:

2020年6月中国省、市、县行政区划shp”,

获取百度云免费下载链接。



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存