问题描述
我想从我拥有的netcdf文件中绘制南极洲的表面海拔高度,但要遮盖海洋.因此,我使用了"maskoceans".但是,使用时,一切都是白色的.如果我看一下创建的蒙版,它到处都会写为"True",因此它无法识别海洋表面.此外,与陆地/海洋掩码关联的创建数组为空.我不明白发生了什么.我尝试了其他底图投影,但是问题仍然相同.我也使用投影坐标.
I would like to plot the surface elevation of Antarctica from netcdf files I have, but masking the ocean. Therfore, I used "maskoceans". However, when using it, everthing is white. If I look at the created mask, it is written "True" everywhere, so it did not recognize the surface of oceans. Moreover, the created array associated to the land/ocean mask is empty. I do not understand what is happening. I have tried with other basemap projections, but the problem is still the same. I also use the projected coordinates.
我用drawlsmask进行了测试:
I made tests with drawlsmask:
- 在不使用maskoceans的情况下,只有lon = 180°的空白空间(我有另一个问题!)充满了指定的颜色.
- 使用Maskoceans,它可以将陆地和海洋正确地充满.
最后,我遇到的最后一个问题是,在lon = 180°处的平淡空间(一条线)仍然存在.
Finally, one last problem I have is that a bland space (a line) at lon=180° remains.
我希望有人能够为我提供帮助,并在此先感谢那些尝试这样做的人.
I hope someone will be able to help me and thank in advance those who will try to.
这是我的代码:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy as np
import cdms2 as cdms
import cdtime
from mpl_toolkits.basemap import Basemap,shiftgrid,maskoceans
import matplotlib.pyplot as plt
##################################################
path='/home/dryas/Sentia/data_ECHAM/T106.surf_height.nc'
var='geosp'
tstart=cdtime.comptime(1960,1,1,0,1,0)
tstop=cdtime.comptime(2013,1,1,23,59)
#Extraction
f=cdms.open(path)
var=f(var)
f.close
lat=var.getLatitude()
lon=var.getLongitude()
timax=var.getTime()
timax.getBounds()
timax.asComponentTime()
var=var(time=(tstart,tstop))
var=var[0,:,:]
var=var.filled()
#Map
fig=plt.figure()
m=Basemap(projection='spstere',boundinglat=-60,lon_0=-180,resolution='l')
lons,lats=np.meshgrid(lon,lat)
x,y=m(lons,lats)
mdata=maskoceans(x,y,var,resolution='h',grid=1.25,inlands=True)
cs=m.contourf(x,y,mdata)
cbar=m.colorbar(cs,location='right')
cbar.set_label('surface elevation (m)')
m.drawcoastlines()
m.drawmapboundary()
m.drawparallels(np.arange(-90.,90.,10.),labels=[1,0,0,0],fontsize=10)
m.drawmeridians(np.arange(-180,180,30.),labels=[0,0,0,1],fontsize=10)
plt.title('Surface Elevation')
plt.show()
>
推荐答案
我已经解决了maskoceans的问题:
I have resolved the problem with maskoceans:
我把x,y坐标放在maskoceans中,而不是lats lons中.现在可以工作了=)
I had put the x,y coordinates in maskoceans instead of the lats lons ones. Now it works =)
这篇关于maskoceans,面罩中没有海洋,也没有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!