将netcdf转换为图像 [英] Convert netcdf to image

查看:428
本文介绍了将netcdf转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a netcdf file that I would like to convert to an image (joed, png, gif) using a command line tool.

有人可以帮我提供库名,以及可能的链接吗.

Is someone could please help me with the library name and possibly a link to how it is done.

问候 大卫

推荐答案

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

Others have mentioned commercial solutions with ArcGIS, IDL and Matlab, but here's one way to do it using Python, using the netCDF4 module to read the netcdf file, and matplotlib to create the image. The netCDF4 module will read both NetCDF3, NetCDF4 files, and also read remote NetCDF (or other files) served via the OPeNDAP service. Below I read topography data using the OPeNDAP service, so you should be able to run the program without changes. The netCDF4 module can be a bit difficult to build, but it's included in the Python(x,y), Enthought Canopy and Continuum Anaconda distributions.

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)

产生此图像的

:

which produces this image:

这篇关于将netcdf转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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