I have an .h5 file that I can read with Matlab, IDL, and python. However, both Matlab and python load this file but the Dataset gets a Datatype H5T_STD_U16LE (uint16). Basically I have values of floating point that get converted to integer in the reading process, making values like 0.1 into just 0.

Reading with IDL somehow ignores the internal flags in HDF5 file and gives me proper values.

Is there a way in Matlab or python to force read HDF5 file Datasets with double precision?

In Matlab I do:

hinfo = hdf5info('./data.h5');
dset = hdf5read(hinfo.GroupHierarchy.Groups(1).Groups(1).Datasets(1));

In python:

import h5py
f = h5py.File('./data.h5', 'r')
dset = f['entry']['data']['data']

1 Answers

max9111 On

Reinterpreting the data in Numpy

At first make sure that you know the actual datatype. You wrote float, but you have to know the exact datatype (float64, float32, float16) and the order (Little, BigEndian).

Interpreting float64 to uint16 and back

import numpy as np
#copy the dset using np.copy()
#The following should be quite straight forward
#Interpret the data as np.uint16
#Make the reverse

[1. 1.]
[    0     0     0 16368     0     0     0 16368]
[1. 1.]