I am currently working for a non profit organisation, working on enhancing the interaction between the energy industry and the weather, climate and broader environmental sciences community.
Not coming from a climate science background, I had to become quickly accustomed to the terminology and technologies associated with this field of research. A commonly used file types produced to represent weather and climate data, are Network Common Data Files (aka NetCDF files).
NetCDF are multi-dimensional array files. This enables scenarios such as time series area measurements to be recorded, for that example you may have longitude, latitude and time as dimensions. They are also self describing, including metadata to give relevant information and context.
So, if you’ve come across a .nc file and are wondering how to view it. First I would recommend downloading a free program called Panoply, which allows a quick way to view the array and plot the data.

Once you’ve established you have some NetCDF data, you want to start having a closer look, right? In this example I am going to use R to examine the .nc file.
Firstly, install the R ncdf4 package:
1 2 |
# install packages install.packages("ncdf4") |
Start a new R script and load your ncdf4 package:
1 2 |
# load package library(ncdf4) |
Point R to your working directory (where you have your .nc files):
1 2 |
# create working directory dirw <- "/Users/user/Documents/NetCDF_files/" |
Load in your NetCDF file. There are some example files you can try at the unidata site here. I’m going to use the sea surface temperatures data:
1 2 |
# load NetCDF file fn <- paste(dirw,"tos_O1_2001-2002.nc", sep="") |
The following nc_open function opens the NetCDF file. The arguments I’ve used are:
- filename – The NetCDF file.
- write=FALSE – loads it as read only.
- readunlim=TRUE – NetCDF4 files support unlimited dimensions, which can be big in large data files. You can set this to false to ignore unlimited dimensions.
- verbose=FALSE – Turns off messages printed out during this function.
1 2 |
# open NetCDF file nc <- nc_open(fn, write=FALSE, readunlim=TRUE, verbose=FALSE) |
Now your NetCDF is loaded in and ready, you can print information about a netCDF file, including the variables and dimensions it contains by doing the following:
1 2 |
# print information on NetCDF file print(nc) |
This will print out quite a large amount of information
You may want to just see the attributes:
1 2 |
# see attributes of NetCDF file attributes(nc)$names |
Or the following will print out a nice summary ( nabbed from this article ):
1 2 |
# print how many variables, dimensions and NetCDF attributes print(paste("The file has",nc$nvars,"variables,",nc$ndims,"dimensions and",nc$natts,"NetCDF attributes")) |
You may want to check how big your file is before loading it in:
1 2 |
#check file size in bytes file.size(fn) |
Finally, close the NetCDF file using the nc_close function:
1 2 |
# closes NetCDF file and flushes data to disk, not doing this can cause data loss! nc_close(nc) |
At some point, I will follow this up with some examples on how to plot NetCDF data using R and some nice packages like ggplot2.