底图投影="cyl"有什么问题? [英] what's wrong with basemap projection="cyl"?

查看:454
本文介绍了底图投影="cyl"有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天,我使用Basemap可视化了我的ncep重新分析数据.发现使用底图时仅出现一半数据(projection ="cyl",lon_0 = 0.0,lat_0 = 0.0,resolution ="c"),但整个数据都会出现使用底图时(projection ="cyl",lon_0 = 180.0,lat_0 = 0.0,resolution ="c").此外,我更改了投影,但仍像Basemap(projection ="hammer",lon_0 = 0.0,lat_0 = 0.0,resolution ="c")一样将中心经度设置为0度,但是整个数据.整个数据发生.怎么了 ?非常感谢您的回答.

In recent days, I have visualized my ncep reanalysis data using Basemap. It is found that only half data appears when using Basemap(projection="cyl",lon_0=0.0,lat_0=0.0, resolution="c") , but the whole data occurs when using Basemap(projection="cyl",lon_0=180.0,lat_0=0.0, resolution="c") . Furthermore, I changes the projection, but still set the central longitude to 0 degree like Basemap(projection="hammer",lon_0=0.0,lat_0=0.0, resolution="c"), but the whole data. The whole data occurs. what happens ? Your answers are appreciated very much.

推荐答案

这是basemap的常见问题.即使数据在纵向上应该是循环的,basemap也无法正确处理.我通常使用cdo以应使用的方式显示数据

This is a common problem with basemap. Even though the data should be cyclic in longitudinal direction, basemap can not deal with that properly. I usually use cdo to first order the data in the way it should be displayed using

cdo sellonlatbox,-180,180,-90,90 input.nc output.nc

cdo还提供了 Python包装器,因此您可以直接在脚本中使用它.如果您不想使用cdo,则可以使用numpy重新排列数据,这是一个小示例:

cdo also provides a python wrapper so you can use it directly in your scripts. If you don't want to use cdo, you can use numpy to re-arrange your data, here is a small example:

from matplotlib import pyplot as plt
import numpy as np
from mpl_toolkits import basemap

fig,axes = plt.subplots(nrows=3, ncols=1)

mp1 = basemap.Basemap(ax = axes[0], projection = 'cyl', lon_0=180, lat_0=0)
mp2 = basemap.Basemap(ax = axes[1], projection = 'cyl', lon_0=0,   lat_0=0)
mp3 = basemap.Basemap(ax = axes[2], projection = 'cyl', lon_0=0,   lat_0=0)

for mp in mp1, mp2, mp3:
    mp.drawcoastlines()
    mp.drawcountries()
    mp.drawmeridians(np.arange(0,360,30))
    mp.drawparallels(np.arange(-90,90,30))


##some data:
lons = np.arange(0,360)
lats = np.arange(-90,91)
lons,lats = np.meshgrid(lons,lats)
data = np.sin(2*np.pi*lons/360)+np.sin(np.pi*lats/180)

##first plot
mp1.pcolormesh(lons,lats,data)

##second plot
mp2.pcolormesh(lons,lats,data)

##third plot (with longitudes re-ordered)
lons = lons%180-180*(lons//180) ##re-computing lons to be from -180 to 180

lon_order = np.argsort(lons, axis = 1) ##computing new order of lons
lat_order = np.argsort(lats, axis = 0) ## ... and lats (maybe unnecessary)

mp3.pcolormesh(lons[lat_order,lon_order],lats, data[lat_order,lon_order])

plt.show()

结果看起来像这样,其中第一个图以原始格式显示数据,第二个图尝试将数据居中放置在lon_0=0上而无需重新排序,而第三个图则进行重新排序.

The result looks like this, where the first plot displays the data in the original format, the second one tries to center the data on lon_0=0 without re-ordering and the third one does the re-ordering.

希望这会有所帮助.

这篇关于底图投影="cyl"有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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