This is the hands-on material for the Section Gridded data for the OpenGIS Workshop 2014, held in Deltares during the Delft Software days.

For an Introduction to Gridded data, follow the material you'll find on the .pdf of the presentation here. [The slides will be uploaded on the 2nd of November 2014]. Three tutorials are presented to explore gridded data in NetCDF data format. Mainly Python will be used (package netCDF4).

Tutorial_1 - Satellite data from NOAA OPeNDAP server

A list of servers worldwide can be found via OET opendap server http://opendap.deltares.nl/. Satellite dataset from NOAA is chosen.

Open it in QGIS

There are different ways to visualise your data in QGIS (or ArcGIS). However, a quick method is to use the WMS services that opendap offers. 

Explore it in OPeNDAP

Check:

  • general metadata
  • variables
  • variables metadata
  • variables dimensions
  • unit of measurements
  • check compliancy with CF
  • visualise ASCII

Q. What's the time the dataset is referring to?

Explore data in your favourite language!

An exhaustive list of Software for Manipulating or Displaying NetCDF Data can be found here.

Python and R packages are recommended as open source programming languages. Python will be used for the following tutorial.

Import useful libraries.

import netCDF4
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import numpy as np

 

Get the url of the dataset. Data access happens here, via a url.

url = 'http://data.nodc.noaa.gov/thredds/dodsC/DeepwaterHorizon/Satellite/OceanSurfaceTopography/netcdf/ssha_swh_5day_mean.nc'

 

Create a Dataset object.

d = netCDF4.Dataset(url)

 

Get spatial information.

lat = d.variables['lat'][:]
lon = d.variables['lon'][:]
LON, LAT = np.meshgrid(lon, lat, sparse=False)

 

Often time variable deserves some more attention. Time variable in netcdf has a reference. Usually the same reference of the Epoch time (milliseconds/seconds/days/... that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970) is used. However it depends on the dataset. As a general advise, we recommend to use ISO 8601 as standard of time representation. 

t = d.variables['time'][:]
# look at http://netcdf4-python.googlecode.com/svn/trunk/docs/netCDF4-module.html for some suggestions
dates = [datetime(2010,04,01)+timedelta(days=t[n].astype(float)) for n in range(t.shape[0])]

Q. What is the date relative to the first time value?

 

Load the main variables. Big variables: explore them by slicing them.

ssha=d.variables['ssha'][0][:]
swh_ku=d.variables['swh_ku'][0][:]

 

You can now plot the sea surface height for that date.

plt.subplot(2, 1, 1)
cmap0 = plt.get_cmap('RdBu')

im0 = plt.pcolormesh(LON, LAT, ssha, cmap=cmap0, vmin=-0.5, vmax=0.5)

plt.colorbar()
plt.axis([LON.min(), LON.max(), LAT.min(), LAT.max()])
plt.title('sea_surface_height_above_sea_level [m]')
plt.ylabel('Latitude')
plt.xlabel('Longitude')

 

Q. Plot the map of the sea surface wave significant height.

The result should look like something like this.

Tutorial_2 - Vaklodingen data (Multibeam) from Deltares OPeNDAP server

Explore the famous Vaklodingen dataset (Multibeam bathymetric data originated from Rijkswaterstaat). You can access Tutorial_2 from Openearth public wiki page here. Different languages are used.

Tutorial_3 - Scanfish data from Deltares OPeNDAP server

NetCDF data format is used also for vector data, although that might seem the most efficient way to store that data type. Refer to the following dataset of vector data for Tutorial_3.

Tutorial_3 is presented more as an Exercise, as you would need to go through the hints, step by step. However a solution is presented using Python at the bottom.

Step by step

  • Explore the dataset via the opendap server. Look at the variables, their dimensions, the metadata in the boxes. Get ASCII of the variables.
  • Import the proper libraries to read netcdf files, plotting libraries and additional libraries to handle time.
  • Load variables Time and z variables in the workspace. Q. What's TIME size?
  • Use tools to handle the time variable. Q. When is the data in this dataset referring to?
  • Plot a scatter of depth vs Temperature. Q. What is the unit of measurement of z?

The final result should then look something like

Code (solution)

 

import netCDF4
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
 
url = 'http://opendap.deltares.nl/thredds/dodsC/opendap/rijkswaterstaat/scanfish/scanfish_temperature.nc'
scan = netCDF4.Dataset(url)
 
# variables
lat = scan.variables['lat'][:]
lon = scan.variables['lon'][:]
 
# work with time
scantime = scan.variables['TIME'][:]
dates = [datetime(1970,01,01)+timedelta(days=scantime[n].astype(float)) for n in range(scantime.shape[0])]
 
# get main variables
temp = scan.variables['temperature'][:]
z = scan.variables['z'][:]
 
# plot z vs Temperature
plt.subplot(1, 1, 1)
im3 = plt.scatter(temp,z, c=scantime, alpha = 0.4, s = 20)
# z is a depth. Invert axis 
plt.gca().invert_yaxis()
plt.title('z vs Temperature')
plt.xlabel(r'T [°C]')
plt.ylabel('depth [cm]')

 

 

 

 

 

  • No labels