前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python在线DEM地形图库harmonica

Python在线DEM地形图库harmonica

作者头像
郭好奇同学
发布2021-10-26 14:53:35
1.2K0
发布2021-10-26 14:53:35
举报
文章被收录于专栏:好奇心Log好奇心Log

The topography and bathymetry of the Earth according to the ETOPO1 model. The original model has 1 arc-minute grid spacing but here we downsampled to 0.5 degree grid spacing to save space and download times. Heights are referenced to sea level.

0 安装在线DEM地形图库harmonica:

conda install -c conda-forge harmonica

1 Python在线DEM地形图库harmonica

代码语言:javascript
复制
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import harmonica as hm
# Load the topography grid
data = hm.datasets.fetch_topography_earth()
print(data)
# Make a plot of data using Cartopy
# 画图
region=[-180,180,-90,90]
proj=ccrs.PlateCarree()
fig=plt.figure(figsize=(16,9),dpi=600)
ax = plt.axes(projection=proj)
ax.set_extent(region,crs=proj)
ax.coastlines(lw=0.4)
ax.set_global()
ax.stock_img()
levs = np.arange(-9000,9000,2000)
pc=data.topography.plot.contourf(ax=ax,levels=levs,transform=ccrs.PlateCarree(),add_colorbar=False,cmap="terrain",extend='both')
cbar=plt.colorbar(pc,shrink=0.75,orientation='vertical',extend='both',pad=0.015,aspect=30) #orientation='horizontal'
cbar.set_label('meters')
ax.set_xticks(np.arange(region[0], region[1] + 1, 60), crs = proj)
ax.set_yticks(np.arange(region[-2], region[-1] + 1, 30), crs = proj)
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=False))
ax.yaxis.set_major_formatter(LatitudeFormatter())
font3={'family':'SimHei','size':16,'color':'k'}
plt.title("Earth Topography分布图",fontdict=font3)
plt.ylabel("纬度",fontdict=font3)
plt.xlabel("经度",fontdict=font3)
plt.savefig('F:/Rpython/lp36/plot103.1.4.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()

2 Python for Dynamics and Evolution of Earth and Planets

代码语言:javascript
复制
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
from pylab import *
import numpy as np
import xarray as xr
import metpy.calc as mpcalc
import metpy.constants as constants
import cmaps
from matplotlib import rcParams
config = {"font.family":'Times New Roman',"font.size":16,"mathtext.fontset":'stix'}
rcParams.update(config)
import xarray as xr
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = [20., 10.]
filename = "F:/Rpython/lp36/data/grd_files_to_interp/GypsumP_100.grd"
df = xr.open_dataset(filename, decode_cf=False)
print(df)
lat=df.lat
lon=df.lon
z=df.z
df.z.plot.contourf()
plt.savefig('F:/Rpython/lp36/plot103.1.1.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()
代码语言:javascript
复制
# 画图
region=[-180,180,-90,90]
proj=ccrs.PlateCarree()
fig=plt.figure(figsize=(16,9),dpi=600)
ax = plt.axes(projection=proj)
ax.set_extent(region,crs=proj)
ax.coastlines(lw=0.4)
ax.set_global()
ax.stock_img()
levs = np.arange(-5,5,1)
mfc_contourf=ax.contourf(lon,lat,z,levels=levs,cmap='gist_rainbow',extend='both')
cbar=plt.colorbar(mfc_contourf,shrink=0.75,orientation='vertical',extend='both',pad=0.015,aspect=30) #orientation='horizontal'
cbar.set_label('z')
ax.set_xticks(np.arange(region[0], region[1] + 1, 60), crs = proj)
ax.set_yticks(np.arange(region[-2], region[-1] + 1, 30), crs = proj)
ax.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=False))
ax.yaxis.set_major_formatter(LatitudeFormatter())
font3={'family':'SimHei','size':16,'color':'k'}
plt.title("Python for Dynamics and Evolution of Earth and Planets分布图",fontdict=font3)
plt.ylabel("纬度",fontdict=font3)
plt.xlabel("经度",fontdict=font3)
plt.savefig('F:/Rpython/lp36/plot103.1.2.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()
代码语言:javascript
复制
import os
import xarray as xr
import numpy as np
import cartopy.crs as ccrs
from cartopy.util import add_cyclic_point
import matplotlib.pyplot as plt
filename = "F:/Rpython/lp36/data/grd_files_to_interp/GypsumP_100.grd"
dset = xr.open_dataset(filename, decode_cf=False)
z = dset['z'][:,:]
dset.close()
zmin =  dset['z'].min()
zmax = dset['z'].max()
fig = plt.figure(figsize=[20, 10])
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Orthographic(central_longitude=90))
z.plot.contourf(ax=ax,transform=ccrs.PlateCarree(),extend='max',vmin=zmin,vmax=zmax,cmap='jet')
ax.set_title(df.title)
ax.coastlines()
ax.gridlines()
plt.savefig('F:/Rpython/lp36/plot103.1.3.png',dpi=800,bbox_inches='tight',pad_inches=0)
plt.show()
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-10-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 好奇心Log 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档