将球形地形映射到 Geopandas 和 Cartopy蛋白质表面制图映射

问题描述

我一直在研究这个问题,但似乎无法解决这个问题。本质上,我想使用制图软件将任意 3D 表面映射到球体(我正在尝试使用 geopandas 和 cartopy)在下面链接的论文的 SI 中有一个代码示例,但他们使用了 Basemap,也是他们的代码片段对我来说也不是很好。

molecular cartography

link to paper

我有一个顶点输入(附加 np.array[x,y,z,value]) 以下代码将表面映射到一个球体(地球的大小)

def cart2pol(coords):
    x = coords[0]
    y = coords[1]
    z = coords[2]
    rho = np.sqrt(x**2 + y**2 + z**2)
    theta = np.arctan2(y,x)
    phi = np.arccos(z/rho)
    return([rho,theta,phi])

def pol2cart(coords):
    rho = coords[0]
    theta = coords[1]
    phi = coords[2]
    x = rho * np.cos(theta) * np.sin(phi)
    y = rho * np.sin(theta) * np.sin(phi)
    z = rho * np.cos(phi)
    return([np.round(x,decimals=3),z])

def cart2geo(coords):
    x = coords[0]
    y = coords[1]
    z = coords[2]
    rho = np.sqrt(x**2 + y**2 + z**2)
    lat = np.rad2deg(np.arcsin(z / rho))
    lon = np.rad2deg(np.arctan2(y,x))
    return(lon,lat)

sph_coords = []
for vert in vertices:
    sph_coords.append(cart2pol(vert))
sphc_pol = np.array(sph_coords)
sphc_pol[:,0] = 6378100

sph_coords = []
for vert in sphc_pol:
    sph_coords.append(pol2cart(vert))
sphc_cart = np.array(sph_coords)

这段代码会给我我想要映射到的经度和纬度(在正射投影中)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import geopandas as gpd
import cartopy.crs as ccrs               
from pyproj import CRS
from scipy.interpolate import griddata
from matplotlib.colors import LinearSegmentedColormap 
from matplotlib import pyplot,transforms

crs = CRS("epsg:4326")

lons = np.arange(-180,181,1)
lats = np.arange(-90,91,1)
x,y = np.meshgrid(lons,lats)
positions = np.vstack([x.ravel(),y.ravel()])
geo = gpd.points_from_xy(positions[0],positions[1],crs=crs)
geogs = gpd.GeoSeries(geo)
geogs.crs = crs

mol3 = ccrs.Orthographic()
crs3 = mol3.proj4_init

geogs2 = geogs.to_crs(crs3)

mapping

最终结果是插入一个可以映射到“地球”的表面,然后访问 cartopy 的投影。

surf = griddata(spherical_points,values,(lons[None,:],lats[:,None]),method = 'cubic')

sph_coords = []
for vert in vertices:
    sph_coords.append(cart2geo(vert))
sphc = np.array(sph_coords)
surf = griddata(sphc,df['value'],method = 'cubic')

colors = ['darkred','red','white','lightblue','blue']
cm = LinearSegmentedColormap.from_list('clist',colors)
base = ccrs.PlateCarree()

fig = plt.figure(figsize=(11,8.5))
levels = [-4,-3,-0.6,0.6,3,4]
ax=plt.axes(projection=ccrs.Mollweide())
ax.set_global()
ax.set_extent([-100,100,-50,50])
ax.gridlines(draw_labels=False,dms=True,x_inline=False,y_inline=False)
ax.contourf(lons,lats,surf,cmap=cm,levels=levels,extend='both',transform=base)

result

但是这个最终结果的几何值都搞砸了,并没有真正与原始球面投影对齐(上图)

我知道这是一篇很长的文章。但也许有一些制图大师可以轻松完成。我试图对我的购物车进行故障排除 -> lat long 转换,但似乎无处可去。我附上了我的顶点文件。谢谢!

numpy array

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...