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.
Regards David
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.
Regards David
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:
Here is the official list of software for manipulating NetCDF.
http://www.unidata.ucar.edu/software/netcdf/software.html
If there is anything it is probably there. But I have a couple of comments on the subject if you are interested.
What platform are you using? Linux, Windows etc? Whatever the answer I think the answer is you will be struggling to find a command line tool with out creating it yourself.
It is probably relatively easy to create something using Java or Python and some GDAL libraries or the like. I have made something similar using ArcGIS if you have this but it is not command line because that is quite difficult to achieve.
Part of the problem you will face is that in using a command line you will need to have additional information as to how it is exported setup before hand but this information does not lend itself to a non-GUI environment.
Questions such as is it going to be grey scale or colour. If colour which colours because these will need to be defined. Say we use blue to red colour ramp then is red a high value or a low value. How is the colour going to be assigned to the values. Will it be gradual or will it be stepped e.g. values 0 - 10 correspond to a single colour then 10 - 20 to another colour.
It's not command line but 'NcView' may work for you.
http://meteora.ucsd.edu/~pierce/ncview_home_page.html
IDV is a good visualization tool for NetCDF, but, as far as I know, there is no command line interface.
I would recommend Matlab. It has read and write functions for NetCDF as well as an extensive plotting library...probably one of the best. You can then compile the matlab code and run it from the command line.
this may help:
http://gmt.soest.hawaii.edu/gmt/html/man/grdimage.html
here some examples: web.ics.purdue.edu/~ecalais/teaching/gmt/GMT_6.pdf
GDAL can do this and you can control the output colour palettes in a variety of ways, and the rgdal
package provides an R interface to some of this.
R has support to read NetCDF files and write to image files via a number of contributed packages, namely ncdf
, RNetCDF
and ncdf4
.