Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read dataset with 2d array stored fails on reading chunks #103

Open
oguitart opened this issue Mar 12, 2019 · 10 comments
Open

Read dataset with 2d array stored fails on reading chunks #103

oguitart opened this issue Mar 12, 2019 · 10 comments

Comments

@oguitart
Copy link

Hello,

We have several h5 files that were created in python with the h5py package. These files contain a dataset called "V", which contains a 2D array. I'm trying to read only parts of this dataset by using the following method:

var file = new hdf5.File(/data_signatures/signA1.h5", Access.ACC_RDONLY);
var data = h5lt.readDataset(file.id, "V",{start: [0], stride: [1], count: [128]});

In the above case, I'm trying to read the first 128 rows but what I get it is the whole 2d array but transformed to 1D array. The prove of that is that I do:

data.length

And the output it is the multiplication of the number of rows and the number of columns of this 2d array.
Am I doing anything wrong? Or maybe there is an issue reading this kind of data?
If I do the same thing on a dataset that contains a 1D array then it works fine and I only get the chunk of the data that I want.
Thanks,

oriol

@rimmartin
Copy link
Collaborator

probably need to set the start, stride and count to two rank hyperslab;
like http://hdf-ni.github.io/hdf5.node/tut/subset_tutorial.html

var data = h5lt.readDataset(file.id, "V",{start: [0,0], stride: [1,1], count: [1,128]});

start, stride and count are arrays the size of rank for choosing the subset/hyperslab

@rimmartin
Copy link
Collaborator

rimmartin commented Mar 13, 2019

or reading your description further to be by column of row values

var yCount=0;
var data = h5lt.readDataset(file.id, "V",{start: [0,yCount], stride: [1,1], count: [128, 1]});

where you vary yCount to get each column(all the rows values at that column)

@oguitart
Copy link
Author

Hi,

Thank you for the answer. But the options that you offer don't work. They all read the whole 2d array. Attached one of these files, if you want to test it.

Regards,

oriol

signD3.h5.tar.gz

@rimmartin
Copy link
Collaborator

Ah ok, I'll try

@rimmartin
Copy link
Collaborator

h5lt.readDatasetAsBuffer works while h5lt.readDataset doesn't. In later node js versions the javascript object returned by h5lt.readDatasetAsBuffer is ArrayBufferView with constructor name Buffer and has the functionality of https://nodejs.org/docs/latest/api/buffer.html. I'll work hyperslabs into h5lt.readDataset to catch it up to the documentation ad return a Float32Array. Until I commit changes the following should work for you to get to the hyperslab

try
{
    var file = new hdf5.File("/home/roger/Downloads/signD3.h5", Access.ACC_RDONLY);
    var data = h5lt.readDatasetAsBuffer(file.id, "V",{start: [0,0], stride: [1,1], count: [1,128]});
    console.log("length"+data.length);
    file.close();
}
catch(err) {
    console.dir(err.message);
}

@rimmartin
Copy link
Collaborator

I've committed so h5lt.readDataset should work as well and return a Float32Array for your case.

travis build passed. Yet I do want to add more tests

@oguitart
Copy link
Author

oguitart commented Apr 8, 2019

Hi,

How can I get the latest version to test it? I used npm to install hdf5 package.
Thanks,

oriol

@rimmartin
Copy link
Collaborator

npm install HDF-NI/hdf5.node 

should pull from the github master branch

I got some other things going on before another publish

@oguitart
Copy link
Author

oguitart commented Apr 9, 2019

Hi,

I tested it and it looks good.
Please let me know when it will be available as a new release.
Thanks,

oriol

@rimmartin
Copy link
Collaborator

I will. I think in about two week ends

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants