在python底图中绘制gebco数据 [英] plot gebco data in python basemap

查看:191
本文介绍了在python底图中绘制gebco数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了一些gebco测深数据作为netCDF文件.我想用python-basemap绘制它.我已经尝试过了,

I have downloaded some gebco bathymetry data as a netCDF file. I would like to plot it with python-basemap. I have tried,

import netCDF4
from mpl_toolkits.basemap import Basemap


# Load data
dataset = netCDF4.Dataset('/home/david/Desktop/GEBCO/gebco_08_-30_45_5_65.nc')

# Extract variables
x = dataset.variables['x_range']
y = dataset.variables['y_range']
spacing = dataset.variables['spacing']

# Data limits
nx = (x[-1]-x[0])/spacing[0]   # num pts in x-dir
ny = (y[-1]-y[0])/spacing[1]   # num pts in y-dir

# Reshape data
zz = dataset.variables['z']
Z = zz[:].reshape(ny, nx)



# setup basemap.
m = Basemap(llcrnrlon=-30,llcrnrlat=45.0,urcrnrlon=5.0,urcrnrlat=65.0,
            resolution='i',projection='stere',lon_0=-15.0,lat_0=55.0)


# Set up grid
lons, lats = m.makegrid(nx, ny)
x, y = m(lons, lats)

m.contourf(x, y, flipud(Z))
m.fillcontinents(color='grey')
m.drawparallels(np.arange(10,70,10), labels=[1,0,0,0])
m.drawmeridians(np.arange(-80, 5, 10), labels=[0,0,0,1])

这给出了下图,显然是不正确的.问题源于如何定义区域.底图区域由左下角lat和lon定义,右上角lat和lon定义.但是gebco数据采用沿中心线定义的最大和最小lon/lat. 任何人都可以使用gebco数据或看到解决方案?

this gives the figure below, clearly not correct. The problem stems from how the areas are defined. For basemap area is defined by lower left corner lat,lon and upper right corner lat, lon. But the gebco data takes a maximum and minimum lon/lat defined along a center line. Anyone have any experience with gebco data or see a solution??

谢谢 d

推荐答案

为便于记录,以下是使用上面的注释的有效答案:

so just for the record, here's the answer that works, using the comments above:

import netCDF4
from mpl_toolkits.basemap import Basemap

# Load data
dataset = netCDF4.Dataset('/usgs/data1/rsignell/bathy/gebco_08_-30_-45_5_65.nc')

# Extract variables
x = dataset.variables['x_range']
y = dataset.variables['y_range']
spacing = dataset.variables['spacing']

# Compute Lat/Lon
nx = (x[-1]-x[0])/spacing[0]   # num pts in x-dir
ny = (y[-1]-y[0])/spacing[1]   # num pts in y-dir

lon = np.linspace(x[0],x[-1],nx)
lat = np.linspace(y[0],y[-1],ny)

# Reshape data
zz = dataset.variables['z']
Z = zz[:].reshape(ny, nx)

# setup basemap.
m = Basemap(llcrnrlon=-30,llcrnrlat=45.0,urcrnrlon=5.0,urcrnrlat=65.0,
            resolution='i',projection='stere',lon_0=-15.0,lat_0=55.0)

x,y = m(*np.meshgrid(lon,lat))

m.contourf(x, y, flipud(Z));
m.fillcontinents(color='grey');
m.drawparallels(np.arange(10,70,10), labels=[1,0,0,0]);
m.drawmeridians(np.arange(-80, 5, 10), labels=[0,0,0,1]);

将生成此图.

这篇关于在python底图中绘制gebco数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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