hdf5 module

This module will collect tools for reading, writing and testing structured HDF5 files.

HDF5 Format Specification

Here is a sample of the HDF5 file format.

/
attributes: {'date': '2014-07-22',
             'time': '13:00:00',
             'hdf5_version': 'v0.1',  # Version of the format specification
             'source': 'PSB-B19-AFM',
             'help': 'What is this data?'
             'extra_dimensions': 'x2'
             'comment': 'This is an example HDF5 file with multiple dimensions, and several averages for each data point.'}
    x
    attributes: {'name': 'Frequency',
                 'unit': 'Hz',
                 'label': 'f [Hz]'
                 'label_latex': r'$f \: [\mathrm{Hz}]$',
                 'initial': 0.0,
                 'step': 0.5,
                 'help': 'Frequency array for PSD.'}
        [0, 0.5, 1.0, 1.5]

    x2
    attributes: {'name': 'Laser Power',
                 'unit': 'mW',
                 'label': 'P [mW]',
                 'label_latex': r'$P \: [\mathrm{mW}]$',
                 'help': 'Interferometer Output Laser Power'
                }
        [2.0]

    y/
    attributes: {'name': 'Power Spectral Density of position fluctuations',
                 'unit': 'nm^2/Hz',
                 'label': 'PSD [nm^2 / Hz]',
                 'label_latex': r'$P_{\delta x} \: [\mathrm{nm}^2 / \mathrm{Hz}]',
                 'n_avg': 4,  # If n_avg is not equal to one, there should be a dataset y_std containing standard deviations
                 'help': 'Power spectral density of position fluctuations.'}
        [1, 2.1, 2.9, 4]

    y_std/
        [0.2, 0.3, 0.4, 0.5]


    workup/
        FFT
         [1, 2, 3]
        FTTunit
         'nm'

Note: If x is an empty array, we can determine the array from the initial and step attributes.

Note: If y['n_avg'] == 1, then y is a dataset rather than a group, with y data stored directly, as shown below.

y
attributes: {'name': 'PSD_{\delta x}'
             'n_avg': 1,
             'unit': 'nm^2/Hz',
             'help': 'Power spectral density of position fluctuations.'}
    [1, 2.1, 2.9, 4]

After the data has been processed, you can output any fitting or workup parameters to a group called workup.

hdf5.update_attrs(h5_attrs, attrs)[source]

Update the attributes in h5_attrs, an h5py group or dataset, by adding attributes in the dictionary attrs.

This will overwrite existing attributes.

hdf5.attr_dict_options(setting)[source]

Shorthand for describing possible combinations of required attributes for an hdf5 dataset.

Possible values for setting:

very_permissive
Only require name, unit; other attributes can be inferred / ignored.
hdf5.check_minimum_attrs(attrs, setting='permissive')[source]
hdf5.infer_labels(attrs)[source]
hdf5.add_attrs_if_missing(h5_attrs, **kwargs)[source]
hdf5.infer_missing_attrs(attrs, dataset_type=None, abscissa=None, n_avg=1)[source]

hdf5.hdf5_util module

A set of utility functions for HDF5 files

hdf5.hdf5_util.update_attrs(h5_attrs, attrs)[source]

Update the attributes in h5_attrs, an h5py group or dataset, by adding attributes in the dictionary attrs.

This will overwrite existing attributes; it is functionally equivalent to a python dictionary’s update method.

hdf5.hdf5_util.save_hdf5(f_src, f_dst, datasets, overwrite=False, **kwargs)[source]

Copy all the elements of datasets from f_src to f_dst. For information on kwargs, see the documentation for the h5py copy method.

Parameters:
  • f_src – source h5py file or group object
  • f_dst – destination filename or h5py file or group object
  • datasets – list of datasets / groups to copy
  • overwrite – If True, overwrite an existing file with the filename f_dst.
hdf5.hdf5_util.h5ls_str(g, offset='', print_types=True)[source]

Prints the input file/group/dataset (g) name and begin iterations on its content.

See goo.gl/2JiUQK.

hdf5.hdf5_util.h5ls(*args)[source]

List the contents of an HDF5 file object or group. Accepts a file / group handle, or a string interpreted as the hdf5 file path.