python - 将 netcdf 转换为图像

标签 python netcdf

我有一个 netcdf 文件,我想使用命令行工具将其转换为图像(joed、png、gif)。

有没有人可以帮我提供库名称以及可能是如何完成的链接。

问候 大卫

最佳答案

其他人提到了使用 ArcGIS、IDL 和 Matlab 的商业解决方案,但这里有一种使用 Python 的方法,使用 netCDF4 模块读取 netcdf 文件,并使用 matplotlib 创建图像。 netCDF4 模块将读取 NetCDF3、NetCDF4 文件,还可以读取通过 OPeNDAP 服务提供的远程 NetCDF(或其他文件)。下面我使用 OPeNDAP 服务读取地形数据,因此您应该能够在不更改的情况下运行该程序。 netCDF4 模块可能有点难以构建,但它包含在 Python(x,y)、Enthought Canopy 和 Continuum Anaconda 发行版中。

import matplotlib.pyplot as plt
import netCDF4

# open a local NetCDF file or remote OPeNDAP URL
url = 'http://www.ngdc.noaa.gov/thredds/dodsC/relief/ETOPO1/thredds/ETOPO1_Bed_g_gmt4.nc'
nc = netCDF4.Dataset(url)

# examine the variables
print nc.variables.keys()
print nc.variables['z']

# sample every 10th point of the 'z' variable
topo = nc.variables['z'][::10,::10]

# make image
plt.figure(figsize=(10,10))
plt.imshow(topo,origin='lower') 
plt.title(nc.title)
plt.savefig('image.png', bbox_inches=0)

生成此图像:enter image description here

关于python - 将 netcdf 转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8864599/

相关文章:

python - 我可以在 django 项目中有一个主模型文件吗?

python - 在 Userlogin 期间,Authenticate 使用正确的用户名和密码返回 None

python - xarray 波周期以秒为单位作为 timedelta64 摄取

python - 根据垂直级别合并多个Netcdf文件

netcdf - 使用 nco 连接具有不同变量的 netcdf 文件

python - 如何使用 Pandas 数据框的余额列计算银行对帐单借方/贷方列?

python - 设置 matplotlib 3d 绘图纵横比

python-3.x - 使用 xarray 更改坐标系以进行切片操作

netcdf - 如何从时间序列数据中去除季节性?

python - BeautifulSoup 在某些下载请求中拾取 div 对象,但在其他下载请求中拾取 div 对象