Reading oval axis HDF5 data with Julia HDF5

I have an HDF5 file containing arrays that are saved using Python / numpy. When I read them in Julia using HDF5.jl, the axes are in the reverse order in which they appear in Python. To reduce the mental gymnastics associated with the transition between Python and Julia code codes, I reverse the axis order when I read data in Julia. I wrote my own function for 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 need to import callbacks in order to use this; (2) I have to keep this in mind for every Array I read. I am wondering if this is possible:

  • instruct HDF5.jl to read in arrays with axis order in numpy order, either through a keyword argument, or some kind of global configuration parameter
  • use the built-in function of one argument to change the axes
+5
source share
2 answers

A better approach would be to create the 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 .

+2
source

It seems to me that permutedims! does what you are looking for, however it does a copy of the array. If you can rewrite hdf5 files in python, numpy.asfortranarray claims that you are returning your data stored in column format, although numpy internals docs seem to assume that the data is not changed, just a step, so I don't know if there will be an output hdf5 file any other

Edit: Sorry, I just saw that you are already using permutedims in your function. I couldn't find anything else on Julia's side, but I will still try numpy.asfortranarray and see if that helps.

0
source

All Articles