Skip to main content

netCDF4 via h5py

Project description

https://travis-ci.org/shoyer/h5netcdf.svg?branch=master https://badge.fury.io/py/h5netcdf.svg

A Python interface for the netCDF4 file-format that reads and writes HDF5 files API directly via h5py, without relying on the Unidata netCDF library.

This is an experimental project. It currently passes basic tests for reading and writing netCDF4 files with Python, but it has not been tested for compatibility with other netCDF4 interfaces.

Motivations

Why did I write h5netcdf? Well, here are a few reasons:

  • To prove it could be done (it seemed like an obvious thing to do) and that netCDF4 is not actually that complicated.

  • We’ve seen occasional reports of better performance with h5py than netCDF4-python that I wanted to be able to verify. For some workflows, h5netcdf has been reported to be almost 4x faster than netCDF4-python.

  • h5py seems to have thought through multi-threading pretty carefully, so this in particular seems like a case where things could make a difference. I’ve started to care about this because I recently hooked up a multi-threaded backend to xray.

  • It’s one less massive binary dependency (netCDF C). Anecdotally, HDF5 users seem to be unexcited about switching to netCDF – hopefully this will convince them that they are really the same thing!

  • Finally, side-stepping the netCDF C library (and Cython bindings to it) gives us an easier way to identify the source of performance issues and bugs.

Install

Ensure you have h5py installed (I recommend using conda). Then: pip install h5netcdf

Usage

h5netcdf has two APIs, a new API and a legacy API.

New API

The new API supports direct hierarchical access of variables and groups. It’s design is an adaptation of h5py to the netCDF data model. For example:

import h5netcdf
import numpy as np

with h5netcdf.File('mydata.nc', 'w') as f:
    v = f.create_variable('/grouped/data', ('x',), data=np.arange(10))
    v.attrs['foo'] = 'bar'
    print(f['/grouped/data'])

Warning: The design of the new API is *not yet stable*. I only recommended using it for experiments. Please share your feedback in this GitHub issue.

Legacy API

The legacy API is designed for compatibility with netCDF4-python. To use it, import h5netcdf.legacyapi:

import h5netcdf.legacyapi as netCDF4
# everything here would also work with this instead:
# import netCDF4
import numpy as np

with netCDF4.Dataset('mydata.nc', 'w') as ds:
    ds.createDimension('x', 10)
    g = ds.createGroup('grouped')
    g.createVariable('data', 'i8', ('x',))
    v = g['data']
    v[...] = np.arange(10)
    v.foo = 'bar'
    print(ds.groups['grouped'].variables['data'])

License

3-clause BSD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

h5netcdf-0.2.0.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file h5netcdf-0.2.0.tar.gz.

File metadata

  • Download URL: h5netcdf-0.2.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for h5netcdf-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8365a9988a11cb358689b5c061d9572a2540f3bf7744e370e31b2a9c9da28004
MD5 2e561aefd1145869748f7f0649ec854c
BLAKE2b-256 3dc41ba07a2616e7fbe0b21f31179d265d1298722a1e85a723f3b49e8ab1019c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page