NetCDF reader called
He's posted the code and some more usage information on Github too: https://github.com/karimbahgat/pyncf
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: https://thepythongischallenge.wordpress.com/2016/03/26/pynetcdf-netcdf-files-in-pure-python/
As a quick test I installed pyncf using pip directly from Github:
pip install https://github.com/karimbahgat/pyncf/archive/master.zip
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="BodegaMarineLabBuoy.nc")Then I created a variable to hold the header dictionary:
header = nc.headerThe header metadata contains a variety of summary data as nested dictionaries and list. We can access the product description by traversing that structure:
header["gatt_list"]["values"] '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) '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"!