Sunday, April 3, 2016

Pure Python NetCDF Reader

Great news! Pure Python geospatial programmer Karim Bahgat created a depenency-free Pythonpyncf.  If you're not familiar with NetCDF, it is technically a collection of software libraries and machine-independent data formats commonly used for multi-dimensional scientific data of any type.  NetCDF currently uses a hierarchial data storage format called HDF5.  NetCDF has a concept of dimensions, variables, and attributes and can scale from one-to-one relationships up to many-to-many relationships in all directions.  In geospatial contexts, NetCDF is frequently used to store 2D and 3D raster or vector datasets over time.  It is very popular for ocean observations and climatological data.
NetCDF reader called

He's posted the code and some more usage information on Github too:

Karim goes into detail on the ideas behind the library on his blog.  But be careful, the examples on the blog aren't as current as the ones on Github:

As a quick test I installed pyncf using pip directly from Github:
pip install

I then downloaded the sample time series orthogonal point data NetCDF sample file from here:

The actual link to the netcdf file is here:

What's nice about these NOAA samples is that they have a plain-text CDL (Common Data Language) version as well that let's you see what's in the file when you're experimenting with an API like this:

First, I imported the library and created a NetCDF object from the sample file:

import pyncf
nc = pyncf.NetCDF(filepath="")
Then I created a variable to hold the header dictionary:
header = nc.header
The header metadata contains a variety of summary data as nested dictionaries and list.  We can access the product description by traversing that structure:


'These seawater data are collected by a moored fluorescence 
and turbidity instrument operated at Cordell Bank, California, USA, 
by CBNMS and BML. Beginning on 2008-04-23, fluorescence and turbidity 
measurements were collected using a Wetlabs ECO Fluorescence 
and Turbidity Sensor (ECO-FLNTUSB). The instrument depth of the 
water quality sensors was 01.0 meter, in an overall water depth 
of 85 meters (both relative to Mean Sea Level, MSL). 
The measurements reflect a 10 minute sampling interval.'

The time values in this dataset are stored as epoch seconds.  I accessed those and then converted the first and last into readable dates to see exactly what period this dataset spans:

import time
t = nc.read_dimension_values("time")
print time.ctime(t[0])
'Mon Jul 28 12:30:00 2008'
print time.time(t[-1])
'Wed Sep 10 10:31:00 2008'
The pyncf codebase is considered an alpha version and is currently read only, but what a great addition to your pure Python geospatial toolbox!  I wish this library was available when I updated "Learning Geospatial Analysis with Python"!


  1. I must say you had done a tremendous job,I appreciate all your efforts.
    Thanks alot for your writings.
    Waiting for a new 1...Please visit our wonderful and valuable website-
    For More Details Visit are Official Websites :

  2. Thank you for sharing the post! Glad to hear the information.

  3. It is so nice to see you writing on your blog again!

  4. With havin so much written content do you ever run into any issues of plagorism or copyright violation? My website has scr888 download a lot of completely unique content I've either written myself or outsourced but it looks like a lot of it is popping it up all over the internet without my authorization. Do you know any ways to help protect against content from being ripped off? I'd genuinely appreciate it.

  5. Joyelle Derma Cream scr888 games is an anti-aging formula that is formulated for daily use subsequent to maximum prescription strength.You must be familiar from fraud products in the puff and go ahead behind Joyelle Derma Cream.Joyelle Derma Cream is an up to standard anti-aging cream that is in view of that energetic cream.Joyelle Derma Instant Wrinkle Reducer assists in repairing the wear and tear of your damaged skin considering the assist of its potent formula.This Cream is the rejuvenating and anti-ageing cream, it works by penetrating your skin and prevents from the harmful rays of sun.It is a realistic enemy of maturing bargain that aides in removing every the awful indications of maturing.Joyelle Derma It would take an individual choice relating to wrinkle a specific decline technique that you have agreed to utilize.It works differently. Our skin science experts know that the artifice for clinically-derived collagen to entertain into the skin is to use lonely total molecules.