简体   繁体   English

为 Cartopy map 添加高分辨率底部地形

[英]Add high-resolution bottom topography to Cartopy map

I'm migrating from basemap to Cartopy and would like to plot ocean bottom topography with high resolution for a limited area.我正在从底图迁移到 Cartopy,并希望在有限区域内使用高分辨率的 plot 海底地形。 In basemap I was using ETOPO1_Ice_g_gmt4.grd and transforming it to map coordinates based on documentation I had found somewhere.在底图中,我使用 ETOPO1_Ice_g_gmt4.grd 并根据我在某处找到的文档将其转换为 map 坐标。 I don't know how to do that for Cartopy.我不知道如何为 Cartopy 做到这一点。 Can anyone help?任何人都可以帮忙吗? Cheers, Sünnje干杯,孙杰

Update: Code in Basemap更新:底图中的代码

map = Basemap(projection = 'merc', llcrnrlat = 67.2, urcrnrlat = 69.5,\ map = 底图(投影 = 'merc',llcrnrlat = 67.2,urcrnrlat = 69.5,\
llcrnrlon = 8, urcrnrlon = 16.5, lat_ts = 67.5,) llcrnrlon = 8,urcrnrlon = 16.5,lat_ts = 67.5,)

topoFile = nc.NetCDFFile('/home/sunnje/data/ETOPO1_Ice_g_gmt4.grd','r')                                                       
topoLons = topoFile.variables['x'][:]                                                                                         
topoLats = topoFile.variables['y'][:]                                                                                         
topoZ = topoFile.variables['z'][:]                                                                                            
                                                                                                                              
# transform to nx x ny regularly spaced 1km native projection grid                                                            
nx = int((map.xmax - map.xmin)/1000.)+1                                                                                       
ny = int((map.ymax - map.ymin)/1000.)+1                                                                                       
                                                                                                                              
topodat = map.transform_scalar(topoZ,topoLons,topoLats,nx,ny)                                                                 
                                                                                                                              
tyi = np.linspace(map.ymin,map.ymax,topodat.shape[0])                                                                         
txi = np.linspace(map.xmin,map.xmax,topodat.shape[1])                                                                         
ttxi, ttyi = np.meshgrid(txi,tyi)                                                                                             
                                                                                                                              
cm = map.contour(ttxi, ttyi, topodat)

First, here is a demo code and its output map using cartopy.首先,这里是一个演示代码及其 output map 使用 cartopy。 It uses the projection and map's extent that you specified.它使用您指定的投影和地图范围。

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from scipy.stats import multivariate_normal

# set extent necessary for data and plots
map_ext = [8, 16.5, 67.2, 69.5] #longmin,longmax,latmin,latmax

# for demo purposes
# set needed values for data creation
xmean, ymean = (map_ext[0]+map_ext[1])/2.0, (map_ext[2]+map_ext[3])/2.0
mu = np.array([xmean, ymean])
covar = np.array([[ 10. , -0.5], [-0.5,  10.5]])
lon_range = np.linspace(-180, 180, 200)
lat_range = np.linspace(-90, 90, 100)
xs,ys = np.meshgrid(lon_range, lat_range)
pos = np.empty(xs.shape + (2,))
pos[:, :, 0] = xs
pos[:, :, 1] = ys
# generate values as a function of (x,y) for contour genereation
zs = multivariate_normal(mu, covar).pdf(pos)

# setup projection for the map
projection = ccrs.Mercator(latitude_true_scale=67.5)
# create figure, axis for the map
fig, ax = plt.subplots(figsize=(8,6), subplot_kw={'projection': projection})

ax.set_extent(map_ext)
ax.coastlines()

ax.contourf(xs, ys, zs, transform=ccrs.PlateCarree(), zorder=10, alpha=0.6)
ax.contour(xs, ys, zs, transform=ccrs.PlateCarree(), zorder=12)

ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True)
plt.show()

轮廓1

To modify the code to plot your data, just change (xs,ys,zs) to (ttxi, ttyi, topodat).要将代码修改为 plot 您的数据,只需将 (xs,ys,zs) 更改为 (ttxi, ttyi, topodat)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 提高 Cartopy map 的分辨率 - Improve resolution of Cartopy map 如何使用 Python 获取高分辨率的谷歌地图卫星图像? - How can I fetch high-resolution google map satellite image using Python? 使用 plotnine 保存高分辨率图像 - Saving high-resolution images with plotnine 如何使用seaborn生成高分辨率热图? - How to generate high-resolution heatmap using seaborn? 如何使用 xESMF 将高分辨率 GRIB 网格重新采样为更粗略的分辨率? - How do I resample a high-resolution GRIB grid to a coarser resolution using xESMF? AutoEncoder 的编码器输出中的大多数条目为零,同时用于从高分辨率图像中提取特征 - Most of the entries in encoder output of an AutoEncoder is zero while used for feature extraction from high-resolution images 如何在Python中将整数转换为高分辨率时间? 还是如何防止Python掉零? - How do I convert integers into high-resolution times in Python? Or how do I keep Python from dropping zeros? 添加矩形到 map 用 Cartopy python 到 select 子空间 - Add rectangle to map made with Cartopy python to select subspace 在 cartopy map 上添加具有给定坐标(纬度、经度)的图像 - add a image with given coordination (lat, lon) on the cartopy map 使用Matplotlib / Cartopy / Python无法以高缩放级别(即缩小)检索地图图块 - Unable to retrieve map tiles at high zoom level (i.e. zoomed out) with Matplotlib/Cartopy/Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM