Cartopy:无法绘制具有不确定性(和相关问题)的向量场 [英] Cartopy: Can't plot vector field with uncertainties (and related questions)

查看:68
本文介绍了Cartopy:无法绘制具有不确定性(和相关问题)的向量场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一段时间,在Cartopy中绘制带有不确定椭圆形的矢量场.这个想法是,如果我有一个位置(纬度/经度)和一个矢量(例如风速),但是该矢量具有不确定性(例如以标准偏差衡量),那么我想绘制一个椭圆箭头的尖端周围表示不确定性.在GMT中, psvelo 可以解决问题,我的目标是类似的东西.

I've been trying for a while now to plot vector field with uncertainty ellipses in Cartopy. The idea is that if I have a location (lat/lon) and a vector (wind speed, for example), but that vector has an uncertainty (measured in standard deviation, for example), then I'd like to plot an ellipses around the tip of the arrow indicating that uncertainty. In GMT, psvelo does the trick, my goal is something like this.

这与之前被问到的问题相同

This is the same question as has been asked before here - I'm reopening it because I think that if someone can help me understand transforms better and I can find the location of the tip of the arrow, I can plot the error ellipse myself. Plus, some Matplotlib/Cartopy functionality might have changed in the last 4 years.

所以,这是我到目前为止尝试过的:

So, here's what I tried so far:

  1. 制作地图,使用 quiver 绘制矢量,然后尝试访问返回的 Quiver 对象中的某种比例参数.我找不到任何有用的东西,尽管 scale 属性看起来是正确的,但结果证明它永远不会被设置,除非我自己设置.

  1. Making a map, using quiver to plot the vectors, and then trying to access some sort of scale parameter in the returned Quiver object. I couldn't find anything useful, and even though the scale attribute looked like it would've been the right thing, it turned out never to be set unless I set it myself.

如果我自己设置缩放比例,如果我的位置和向量的单位不同,我不知道该怎么做,而且两者显然都与轴宽度无关.例如,如果我决定要在10°E,40°N下有一个50 m/s的长矢量,作为轴宽度的一部分,我的 scale 参数是?我尝试转换的随机组合并没有得到任何结果.(这里的想法是,如果我能弄清楚这种关系,那么我离知道把椭圆放在哪里更近了一步.)

If I do set the scaling myself, I don't know how to do this if my location and vector have different units, and both are obviously not related to the axis width. For example, if I decided that I want to have a 50 m/s long vector at 10°E, 40°N, to be a certain fraction of the width of the axis, what would my scale parameter be? Me trying out random combinations of transformations has not gotten any results. (The idea here then being, if I can figure out that relation, then I am one step closer to knowing where to put the ellipse.)

我试图弄清楚 quiver 的自动缩放比例,看看如何才能预测"内部的功能,然后使用它来知道箭头是.遗憾的是,它不像 Matlab 变体那么简单,所以我失败了以及.

I've tried to figure out quiver 's autoscaling to see how I can "predict" what it's going to do internally, and then use that to know where the tip of the arrow is. Sadly, it's not as straightforward as the Matlab variant, so I failed at that as well.

最后,我也不明白为什么我不能使用 cartopy.crs.Geodetic() 作为我的源坐标系.我得到的错误是 无效变换:不支持球形箭袋 - 考虑使用 PlateCarree/RotatedPole. 从阅读 Cartopy 文档来看,如果我的矢量位置是按纬度测量的,那不是合适的,经度和高度?

Lastly, I also don't understand why I can't use cartopy.crs.Geodetic() as my source coordinate system. The error I get is invalid transform: Spherical quiver is not supported - consider using PlateCarree/RotatedPole. From reading the Cartopy documentation, wouldn't that be the appropriate one if my vector's location is measured in latitude, longitude and altitude?

这是一个 MWE:

# imports
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# data
lon, lat = np.array([10, 10.5]), np.array([40, 40])
east, north = np.array([0, 50]), np.array([50, 0])
# map
fig, ax = plt.subplots(subplot_kw={"projection": ccrs.Mercator()})
ax.set_extent([7, 13, 38, 42], ccrs.Geodetic())
ax.coastlines("50m")
q = ax.quiver(lon, lat, east, north, transform=ccrs.PlateCarree())
plt.show()

我真的认为这是 Cartopy 应该拥有的一个功能,因为它是迄今为止我在将 Python 用于地球科学应用程序时遇到的最大障碍之一.目前,我所知道的唯一方法是从我的Python程序中编写GMT脚本文件,并通过Python系统调用运行GMT,这确实很痛苦.

I really think this is a feature that Cartopy should have, as it is one of the biggest hurdles I've encountered so far when using Python for geoscience applications. Currently, the only approach I know is to write a GMT script file from within my Python program, and run GMT with a Python system call, and that's really a pain.

我知道 GMT正在开发自己的Python接口,但他们甚至还没有整合所有基本功能,因此任何人都可以猜测何时到达 psvelo ...

I know that GMT is developing their own Python interface, but they haven't even incorporated all the basic functionality, so it's anyone's guess when they will get to psvelo...

感谢您的所有帮助和提示,

Thanks for all your help and tips,

PBB

推荐答案

关于这个的困难部分是 matplotlib 部分.如果我试图做到这一点,我会先专注于它,然后再让它在 Cartopy 中工作.从技术上讲,您需要的点位于 quiver 命令生成的路径集中的某个位置(位于 MWE 中的 q._paths 中).一个更简单的解决方案是使用 pivot='tip',这样箭头的点总是位于 (x,y) 点.

Well the hard part about this is the matplotlib part. If I were trying to make this, I'd focus on that before making it work in Cartopy. Technically, the point you need is somewhere in the set of paths generated by the quiver command (located in q._paths in your MWE). A simpler solution would be to use pivot='tip' so that the point of the arrow is always located at the (x,y) point.

当您尝试使用 Geodetic 时,您从 Cartopy 得到的错误是因为在球体上工作时正确执行所有操作涉及更复杂的数学 - 因此并非所有内容都适用于 Geodetic.如果您改为使用 PlateCarree,它会将 lon/lat 视为平面上的笛卡尔坐标.

The error you're getting from Cartopy when you try to use Geodetic is because doing everying correctly when working on a sphere involves more complicated math--thus not everything works with Geodetic. If instead you use PlateCarree, it will treat lon/lat as Cartesian coordinates on a plane.

这篇关于Cartopy:无法绘制具有不确定性(和相关问题)的向量场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆