Child pages
  • Delft Software Days 2013 - OpenGIS Workshop - netcdf

This space contains outdated content and is archived pending removal. Please contact the space or Confluence administrator to reactivate this space.

Skip to end of metadata
Go to start of metadata

This page gives an overview of the exercise with reading and creating CF compliant netcdf files presented on November 1th, 2013 by Kees den Heijer.


The exercise deals with bathymetry data of the Dutch coast. Here is the link to browse the netcdf file of concern with your browser:
This shows you:

The first link on this page (OPeNDAP), goes to a page the shows all the meta information and file structure of a file.
The second link (HTTPServer) can be used to download the whole file to your local hard drive.

The OPeNDAP link brings you to the following page, where the data url can be obtained:

Both in Matlab and in Python, the link to netcdf file can be specified as follows:

ncfile = ''


  • Read bathymetry data (variable 'z') from the above mentioned netcdf file.
  • Extract the latest time slice only
  • Create the new file with this latest time slice, using the netCDF Kickstarter (for further info see the netCDF kickstarter)

Code suggestions for reading netCDF

Matlab (native)

Basic code elements

info = ncinfo(ncfile)
z = ncread(ncfile, 'z');

Example pcolor plot of the most recent available measurement

ncfile = '';

x = ncread(ncfile, 'x');
y = ncread(ncfile, 'y');
z = ncread(ncfile, 'z');

[X, Y] = meshgrid(x, y);

Z = squeeze(z(:,:,end))';

shading interp
axis image

Matlab (OET)

info = nc_info(ncfile)
z = nc_varget(ncfile, 'z');


Basic code elements

import netCDF4
ds = netCDF4.Dataset(ncfile)
print ds
z = ds.variables['z']

Example pcolor plot of the most recent available measurement

from netCDF4 import Dataset
import matplotlib.pyplot as plt
import numpy as np

ncfile = ''

ds = Dataset(ncfile)
x = ds.variables['x'][:]
y = ds.variables['y'][:]
z = ds.variables['z'][-1,]

X,Y = np.meshgrid(x,y)
fig,ax = plt.subplots(nrows=1, ncols=1, subplot_kw=dict(aspect='equal'))
ax.pcolor(X, Y, z)