Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read HDF5 data with numpy axis order with Julia HDF5

Tags:

hdf5

julia

I have an HDF5 file containing arrays that are saved with Python/numpy. When I read them into Julia using HDF5.jl, the axes are in the reverse of the order in which they appear in Python. To reduce the mental gymnastics involved in moving between the Python and Julia codebases, I reverse the axis order when I read the data into Julia. I have written my own function to do this:

function reversedims(ary::Array)
  permutedims(ary, [ ndims(ary):-1:1 ])
end

data = HDF5.read(someh5file, somekey) |> reversedims

This is not ideal because (1) I always have to import reversedims to use this; (2) I have to remember to do this for each Array I read. I am wondering if it is possible to either:

  • instruct HDF5.jl to read in the arrays with a numpy-style axis order, either through a keyword argument or some kind of global configuration parameter
  • use a builtin single argument function to reverse the axes
like image 858
Sean Mackesey Avatar asked Oct 30 '22 23:10

Sean Mackesey


1 Answers

The best approach would be to create a H5py.jl package, modeled on MAT.jl (which reads and writes .mat files created by Matlab). See also https://github.com/timholy/HDF5.jl/issues/180.

like image 59
tholy Avatar answered Nov 03 '22 00:11

tholy