JuliaIO/HDF5.jl

Name: HDF5.jl

Owner: JuliaIO

Description: Saving and loading data in the HDF5 file format

Created: 2012-10-01 01:08:41.0

Updated: 2017-12-14 08:50:36.0

Pushed: 2018-01-18 19:46:00.0

Homepage:

Size: 1423

Language: Julia

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

HDF5 interface for the Julia language

Build Status Build status Coverage Status codecov

HDF5 is a file format and library for storing and accessing data, commonly used for scientific data. HDF5 files can be created and read by numerous programming languages. This package provides an interface to the HDF5 library for the Julia language.

Julia data (*.jld) and Matlab (*.mat) files

The core HDF5 functionality is the foundation for two special-purpose packages, used to read and write HDF5 files with specific formatting conventions. The first is the JLD (“Julia data”) package, which implements a generic mechanism for reading and writing Julia variables. While one can use “plain” HDF5 for this purpose, the advantage of the JLD package is that it preserves the exact type information of each variable.

The other functionality provided through HDF5 is the ability to read and write Matlab *.mat files saved as “-v7.3”. The Matlab-specific portions have been moved to Simon Kornblith's MAT.jl package.

Installation

Within Julia, use the package manager:

add("HDF5")

You also need to have the HDF5 library installed on your system (version 1.8 or higher is required), but for most users no additional steps should be required; the HDF5 library should be installed for you automatically when you add the package.

If you have to install the HDF5 library manually, here are some examples of how to do it:

If you've installed the library but discover that Julia is not finding it, you can add the path to Julia's Libdl.DL_LOAD_PATH variable, e.g.,

!(Libdl.DL_LOAD_PATH, "/opt/local/lib")
build("HDF5")

Inserting this command into your .juliarc.jl file will cause this to happen automatically each time you start Julia.

If you're on Linux but you do not have root privileges on your machine (and you can't persuade the sysadmin to install the libraries for you), you can download the binaries and place them somewhere in your home directory. To use HDF5, you'll have to start julia as

IBRARY_PATH=/path/to/hdf5/libs julia

You can set up an alias so this happens for you automatically each time you start julia.

Quickstart

Begin your code with

g HDF5

To read and write a variable to a file, one approach is to use the filename:

collect(reshape(1:120, 15, 8))
ite("/tmp/test2.h5", "mygroup2/A", A)
 = h5read("/tmp/test2.h5", "mygroup2/A", (2:3:15, 3:5))

where the last line reads back just A[2:3:15, 3:5] from the dataset.

More fine-grained control can be obtained using functional syntax:

en("mydata.h5", "w") do file
write(file, "A", A)  # alternatively, say "@write file A"


h5open("mydata.h5", "r") do file
read(file, "A")

This allows you to add variables as they are generated to an open HDF5 file. You don't have to use the do syntax (file = h5open("mydata.h5", "w") works just fine), but an advantage is that it will automatically close the file (close(file)) for you, even in cases of error.

Julia's high-level wrapper, providing a dictionary-like interface, may also be of interest:

g HDF5

en("test.h5", "w") do file
g = g_create(file, "mygroup") # create a group
g["dset1"] = 3.2              # create a scalar dataset inside the group
attrs(g)["Description"] = "This group contains only a single dataset" # an attribute

Convenience functions for attributes attached to datasets are also provided:

Vector{Int}(1:10)
ite("bar.h5", "foo", A)
iteattr("bar.h5", "foo", Dict("c"=>"value for metadata parameter c","d"=>"metadata d"))
adattr("bar.h5", "foo")
Specific file formats

There is no conflict in having multiple modules (HDF5, JLD, and MAT) available simultaneously; the formatting of the file is determined by the open command.

Complete documentation

The HDF5 API is much more extensive than suggested by this brief introduction. More complete documentation is found in the doc directory.

The test directory contains a number of test scripts that also demonstrate usage.

Credits

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.