Thread Subject: reading HDF5 dataset subset

Subject: reading HDF5 dataset subset

From: Tess

Date: 2 Nov, 2009 22:15:21

Message: 1 of 16

Using the low-level HDF5 functions in Matlab, I have generated some HDF5 files with several datasets that are each 512x512x1410. I need to be able to read subsets of these different layers. Looks like hdf5read does not have subsetting capabilities like hdfread, so I am guessing I need to use low-level functions such as H5D.read. How do I translate something like the following high level hdfread call into those HDF5 low-level functions?:

data=hdfread('filename','/dataset_name','Index',{[start],[stride],[size]});
e.g.
sst=hdfread(file,'/WeeklySST','Index',{[1 1 999],[1 1 1],[512 512 1]});

(Chunk size is set to 512x512x1, but I need to read across those boundaries as well.)

Thanks very much,
Tess

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 3 Nov, 2009 12:22:26

Message: 2 of 16

On Mon, 02 Nov 2009 17:15:21 -0500, Tess <tess.brandon@noaa.gov> wrote:

> Using the low-level HDF5 functions in Matlab, I have generated some HDF5
> files with several datasets that are each 512x512x1410. I need to be
> able to read subsets of these different layers. Looks like hdf5read
> does not have subsetting capabilities like hdfread, so I am guessing I
> need to use low-level functions such as H5D.read. How do I translate
> something like the following high level hdfread call into those HDF5
> low-level functions?:
>
> data=hdfread('filename','/dataset_name','Index',{[start],[stride],[size]});
> e.g.
> sst=hdfread(file,'/WeeklySST','Index',{[1 1 999],[1 1 1],[512 512 1]});
>
> (Chunk size is set to 512x512x1, but I need to read across those
> boundaries as well.)
>
> Thanks very much,
> Tess

Tess,

http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/

HDF5 (1.6)
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/h5ex_d_hyper.m

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 3 Nov, 2009 12:24:02

Message: 3 of 16

On Tue, 03 Nov 2009 07:22:26 -0500, Ashish Uthama
<first.last@mathworks.com> wrote:

> On Mon, 02 Nov 2009 17:15:21 -0500, Tess <tess.brandon@noaa.gov> wrote:
>
>> Using the low-level HDF5 functions in Matlab, I have generated some
>> HDF5 files with several datasets that are each 512x512x1410. I need to
>> be able to read subsets of these different layers. Looks like hdf5read
>> does not have subsetting capabilities like hdfread, so I am guessing I
>> need to use low-level functions such as H5D.read. How do I translate
>> something like the following high level hdfread call into those HDF5
>> low-level functions?:
>>
>> data=hdfread('filename','/dataset_name','Index',{[start],[stride],[size]});
>> e.g.
>> sst=hdfread(file,'/WeeklySST','Index',{[1 1 999],[1 1 1],[512 512 1]});
>>
>> (Chunk size is set to 512x512x1, but I need to read across those
>> boundaries as well.)
>>
>> Thanks very much,
>> Tess
>
> Tess,
>
> http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/
>
> HDF5 (1.6)
> http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/h5ex_d_hyper.m
>
>

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 3 Nov, 2009 12:27:58

Message: 4 of 16

On Tue, 03 Nov 2009 07:22:26 -0500, Ashish Uthama
<first.last@mathworks.com> wrote:

> On Mon, 02 Nov 2009 17:15:21 -0500, Tess <tess.brandon@noaa.gov> wrote:
>
>> Using the low-level HDF5 functions in Matlab, I have generated some
>> HDF5 files with several datasets that are each 512x512x1410. I need to
>> be able to read subsets of these different layers. Looks like hdf5read
>> does not have subsetting capabilities like hdfread, so I am guessing I
>> need to use low-level functions such as H5D.read. How do I translate
>> something like the following high level hdfread call into those HDF5
>> low-level functions?:
>>
>> data=hdfread('filename','/dataset_name','Index',{[start],[stride],[size]});
>> e.g.
>> sst=hdfread(file,'/WeeklySST','Index',{[1 1 999],[1 1 1],[512 512 1]});
>>
>> (Chunk size is set to 512x512x1, but I need to read across those
>> boundaries as well.)
>>
>> Thanks very much,
>> Tess
>
> Tess,
>
> http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/
>
> HDF5 (1.6)
> http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/h5ex_d_hyper.m
>
>

Sorry, that went out before I could complete it.

The above examples are for MATLAB R2009b and earlier, it would help to
have a quick look at
http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/README.txt
to figure out the correct way to specify the start/stride/count arguments.

Please use the 1.8 link for 10a.

You could look at the checksum example for specifying chunking.

HTH

Subject: reading HDF5 dataset subset

From: Tess

Date: 3 Nov, 2009 19:11:03

Message: 5 of 16

Thanks; I've seen these examples but haven't been able to get them to apply to my problem successfully. Is 'hyperslab' just a fancy word for subset or chunk of the data? Does it matter at all how the data set is chunked?

I ran the following code and received the following error:
fileID=H5F.open(file);
dset=H5D.open(fileID,'/WeeklySST'); % this is a 53x512x512 data set which I
% read successfully as a whole using H5D.read
space=H5D.get_space(dset);
start=[0 0 0];
stride=[50 50 50] % making it symmetrical b/c I'm still figuring out how HDF5 flips
% dimensions
count=[]; block=[]; % "If count and block are specified as [], the count and block
% size default to a single element."
H5S.select(space,'H5S_SELECT_SET',start,stride,count,block);

??? Error using ==> hdf5lib2
The HDF5 library encountered an error: "unable to set hyperslab selection"

Error in ==> H5S.select_hyperslab at 35
H5ML.hdf5lib2('H5Sselect_hyperslab', spaceID, op, start, stride, count, block);

I am running 7.8.0 R2009a.

Thanks again,
Tess

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u2tjkwbva5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 03 Nov 2009 07:22:26 -0500, Ashish Uthama
> <first.last@mathworks.com> wrote:
>
> > On Mon, 02 Nov 2009 17:15:21 -0500, Tess <tess.brandon@noaa.gov> wrote:
> >
> >> Using the low-level HDF5 functions in Matlab, I have generated some
> >> HDF5 files with several datasets that are each 512x512x1410. I need to
> >> be able to read subsets of these different layers. Looks like hdf5read
> >> does not have subsetting capabilities like hdfread, so I am guessing I
> >> need to use low-level functions such as H5D.read. How do I translate
> >> something like the following high level hdfread call into those HDF5
> >> low-level functions?:
> >>
> >> data=hdfread('filename','/dataset_name','Index',{[start],[stride],[size]});
> >> e.g.
> >> sst=hdfread(file,'/WeeklySST','Index',{[1 1 999],[1 1 1],[512 512 1]});
> >>
> >> (Chunk size is set to 512x512x1, but I need to read across those
> >> boundaries as well.)
> >>
> >> Thanks very much,
> >> Tess
> >
> > Tess,
> >
> > http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/
> >
> > HDF5 (1.6)
> > http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/h5ex_d_hyper.m
> >
> >
>
> Sorry, that went out before I could complete it.
>
> The above examples are for MATLAB R2009b and earlier, it would help to
> have a quick look at
> http://www.hdfgroup.org/ftp/HDF5/examples/examples-by-api/matlab/HDF5_M_Examples-1.6/README.txt
> to figure out the correct way to specify the start/stride/count arguments.
>
> Please use the 1.8 link for 10a.
>
> You could look at the checksum example for specifying chunking.
>
> HTH

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 3 Nov, 2009 20:10:23

Message: 6 of 16

On Tue, 03 Nov 2009 14:11:03 -0500, Tess <tess.brandon@noaa.gov> wrote:

> Thanks; I've seen these examples but haven't been able to get them to
> apply to my problem successfully. Is 'hyperslab' just a fancy word for
> subset or chunk of the data? Does it matter at all how the data set is
> chunked?
>
> I ran the following code and received the following error:
> fileID=H5F.open(file);
> dset=H5D.open(fileID,'/WeeklySST'); % this is a 53x512x512 data set
> which I
> % read successfully as a whole using H5D.read
> space=H5D.get_space(dset);
> start=[0 0 0];
> stride=[50 50 50] % making it symmetrical b/c I'm still figuring out how
> HDF5 flips
> % dimensions
> count=[]; block=[]; % "If count and block are specified as [], the count
> and block
> % size default to a single element."
> H5S.select(space,'H5S_SELECT_SET',start,stride,count,block);
>
> ??? Error using ==> hdf5lib2
> The HDF5 library encountered an error: "unable to set hyperslab
> selection"
>
> Error in ==> H5S.select_hyperslab at 35
> H5ML.hdf5lib2('H5Sselect_hyperslab', spaceID, op, start, stride, count,
> block);
>
> I am running 7.8.0 R2009a.
>
> Thanks again,
> Tess

1.
As I understand it, chunking is defined on the internals of the file, i.e
how the data is stored/organized internally in the file. This appears to
be something required to enable 'extendible' data sets.
http://www.zib.de/zibdoc/zib/mpp/prog/hdf5/Tutor/extend.html

A hyperslab is what you appear to think of as a 'chunk of data'. It is a
subset of the data. I dont think the chunking of the file matters when you
are reading a hyperslab.

I am sure there is more info somewhere in the HDF documentation.

2. Using [] results in the arguments defaulting to a single element. Thats
not what you want if you want to select a single element (look at code
below)

3. You need to use H5S.select_hyperslab

4. You need to specify a memory space ID which matches the size of the
data selected (see code)



Heres something which might help you understand better and get started
with your own code:



%hdf5write('o.h5','/DS1',reshape(1:53*512*512,[53 512 512])); %used to
create sample data, each element ought to be unique


fileID=H5F.open('o.h5','H5F_ACC_RDONLY','H5P_DEFAULT');
dset=H5D.open(fileID,'/DS1'); % this is a 53x512x512 data set
space=H5D.get_space(dset);


start=[7 18 26]; %zero based!
stride=[1 1 1];
count=[1 1 1]; block=[ ];


H5S.select_hyperslab(space,'H5S_SELECT_SET',fliplr(start-1),... %-1 to
take care of 0 based indexing
     fliplr(stride),fliplr(count),fliplr(block)); %fliplr
to take care of row/column major reversal (please see the ReadMe.txt in my
previous post)
mem_space = H5S.create_simple(3, fliplr(count), []); %see Readme.txt for
explanation on need for flipping


rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');

H5D.close(dset);
H5S.close(space);
H5S.close(mem_space);
H5F.close(fileID);

disp(rdata)


%Cross check with the expected element:
r=hdf5read('o.h5','/DS1');
r(7,18,26)

Subject: reading HDF5 dataset subset

From: Tess

Date: 3 Nov, 2009 20:55:17

Message: 7 of 16

I think you hit on it with #4 -- I didn't know how to set the memory space.

Apologies for accidentally leaving out the "_hyperslab" in "H5S.select_hyperslab" when copying from my workspace.

Just to be clear, I already wrote these files to be chunked -- that's not the issue. The issue is whether a file needs to be written with hyperslabs in order to use H5S.select_hyperslab, etc. to read hyperslabs? Should I be using H5S.select_elements instead if I wrote the dataset to the file in one piece originally?

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u2t4zlc7a5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 03 Nov 2009 14:11:03 -0500, Tess <tess.brandon@noaa.gov> wrote:
>
> > Thanks; I've seen these examples but haven't been able to get them to
> > apply to my problem successfully. Is 'hyperslab' just a fancy word for
> > subset or chunk of the data? Does it matter at all how the data set is
> > chunked?
> >
> > I ran the following code and received the following error:
> > fileID=H5F.open(file);
> > dset=H5D.open(fileID,'/WeeklySST'); % this is a 53x512x512 data set
> > which I
> > % read successfully as a whole using H5D.read
> > space=H5D.get_space(dset);
> > start=[0 0 0];
> > stride=[50 50 50] % making it symmetrical b/c I'm still figuring out how
> > HDF5 flips
> > % dimensions
> > count=[]; block=[]; % "If count and block are specified as [], the count
> > and block
> > % size default to a single element."
> > H5S.select(space,'H5S_SELECT_SET',start,stride,count,block);
> >
> > ??? Error using ==> hdf5lib2
> > The HDF5 library encountered an error: "unable to set hyperslab
> > selection"
> >
> > Error in ==> H5S.select_hyperslab at 35
> > H5ML.hdf5lib2('H5Sselect_hyperslab', spaceID, op, start, stride, count,
> > block);
> >
> > I am running 7.8.0 R2009a.
> >
> > Thanks again,
> > Tess
>
> 1.
> As I understand it, chunking is defined on the internals of the file, i.e
> how the data is stored/organized internally in the file. This appears to
> be something required to enable 'extendible' data sets.
> http://www.zib.de/zibdoc/zib/mpp/prog/hdf5/Tutor/extend.html
>
> A hyperslab is what you appear to think of as a 'chunk of data'. It is a
> subset of the data. I dont think the chunking of the file matters when you
> are reading a hyperslab.
>
> I am sure there is more info somewhere in the HDF documentation.
>
> 2. Using [] results in the arguments defaulting to a single element. Thats
> not what you want if you want to select a single element (look at code
> below)
>
> 3. You need to use H5S.select_hyperslab
>
> 4. You need to specify a memory space ID which matches the size of the
> data selected (see code)
>
>
>
> Heres something which might help you understand better and get started
> with your own code:
>
>
>
> %hdf5write('o.h5','/DS1',reshape(1:53*512*512,[53 512 512])); %used to
> create sample data, each element ought to be unique
>
>
> fileID=H5F.open('o.h5','H5F_ACC_RDONLY','H5P_DEFAULT');
> dset=H5D.open(fileID,'/DS1'); % this is a 53x512x512 data set
> space=H5D.get_space(dset);
>
>
> start=[7 18 26]; %zero based!
> stride=[1 1 1];
> count=[1 1 1]; block=[ ];
>
>
> H5S.select_hyperslab(space,'H5S_SELECT_SET',fliplr(start-1),... %-1 to
> take care of 0 based indexing
> fliplr(stride),fliplr(count),fliplr(block)); %fliplr
> to take care of row/column major reversal (please see the ReadMe.txt in my
> previous post)
> mem_space = H5S.create_simple(3, fliplr(count), []); %see Readme.txt for
> explanation on need for flipping
>
>
> rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');
>
> H5D.close(dset);
> H5S.close(space);
> H5S.close(mem_space);
> H5F.close(fileID);
>
> disp(rdata)
>
>
> %Cross check with the expected element:
> r=hdf5read('o.h5','/DS1');
> r(7,18,26)
>
>

Subject: reading HDF5 dataset subset

From: Tess

Date: 3 Nov, 2009 21:09:01

Message: 8 of 16

I just ran your code and realized that while you defined the memory space to be rank 3, [x y z], the output is only one value. The way you've defined start, stride and count, you should have ended up with a 1x3 vector. I need to be able to subset, say, a [1x512x512] slice of data.

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u2t4zlc7a5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 03 Nov 2009 14:11:03 -0500, Tess <tess.brandon@noaa.gov> wrote:
>
> > Thanks; I've seen these examples but haven't been able to get them to
> > apply to my problem successfully. Is 'hyperslab' just a fancy word for
> > subset or chunk of the data? Does it matter at all how the data set is
> > chunked?
> >
> > I ran the following code and received the following error:
> > fileID=H5F.open(file);
> > dset=H5D.open(fileID,'/WeeklySST'); % this is a 53x512x512 data set
> > which I
> > % read successfully as a whole using H5D.read
> > space=H5D.get_space(dset);
> > start=[0 0 0];
> > stride=[50 50 50] % making it symmetrical b/c I'm still figuring out how
> > HDF5 flips
> > % dimensions
> > count=[]; block=[]; % "If count and block are specified as [], the count
> > and block
> > % size default to a single element."
> > H5S.select(space,'H5S_SELECT_SET',start,stride,count,block);
> >
> > ??? Error using ==> hdf5lib2
> > The HDF5 library encountered an error: "unable to set hyperslab
> > selection"
> >
> > Error in ==> H5S.select_hyperslab at 35
> > H5ML.hdf5lib2('H5Sselect_hyperslab', spaceID, op, start, stride, count,
> > block);
> >
> > I am running 7.8.0 R2009a.
> >
> > Thanks again,
> > Tess
>
> 1.
> As I understand it, chunking is defined on the internals of the file, i.e
> how the data is stored/organized internally in the file. This appears to
> be something required to enable 'extendible' data sets.
> http://www.zib.de/zibdoc/zib/mpp/prog/hdf5/Tutor/extend.html
>
> A hyperslab is what you appear to think of as a 'chunk of data'. It is a
> subset of the data. I dont think the chunking of the file matters when you
> are reading a hyperslab.
>
> I am sure there is more info somewhere in the HDF documentation.
>
> 2. Using [] results in the arguments defaulting to a single element. Thats
> not what you want if you want to select a single element (look at code
> below)
>
> 3. You need to use H5S.select_hyperslab
>
> 4. You need to specify a memory space ID which matches the size of the
> data selected (see code)
>
>
>
> Heres something which might help you understand better and get started
> with your own code:
>
>
>
> %hdf5write('o.h5','/DS1',reshape(1:53*512*512,[53 512 512])); %used to
> create sample data, each element ought to be unique
>
>
> fileID=H5F.open('o.h5','H5F_ACC_RDONLY','H5P_DEFAULT');
> dset=H5D.open(fileID,'/DS1'); % this is a 53x512x512 data set
> space=H5D.get_space(dset);
>
>
> start=[7 18 26]; %zero based!
> stride=[1 1 1];
> count=[1 1 1]; block=[ ];
>
>
> H5S.select_hyperslab(space,'H5S_SELECT_SET',fliplr(start-1),... %-1 to
> take care of 0 based indexing
> fliplr(stride),fliplr(count),fliplr(block)); %fliplr
> to take care of row/column major reversal (please see the ReadMe.txt in my
> previous post)
> mem_space = H5S.create_simple(3, fliplr(count), []); %see Readme.txt for
> explanation on need for flipping
>
>
> rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');
>
> H5D.close(dset);
> H5S.close(space);
> H5S.close(mem_space);
> H5F.close(fileID);
>
> disp(rdata)
>
>
> %Cross check with the expected element:
> r=hdf5read('o.h5','/DS1');
> r(7,18,26)
>
>

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 3 Nov, 2009 21:11:07

Message: 9 of 16

On Tue, 03 Nov 2009 15:55:17 -0500, Tess <tess.brandon@noaa.gov> wrote:

> I think you hit on it with #4 -- I didn't know how to set the memory
> space.
>
> Apologies for accidentally leaving out the "_hyperslab" in
> "H5S.select_hyperslab" when copying from my workspace.
>
> Just to be clear, I already wrote these files to be chunked -- that's
> not the issue. The issue is whether a file needs to be written with
> hyperslabs in order to use H5S.select_hyperslab, etc. to read
> hyperslabs? Should I be using H5S.select_elements instead if I wrote
> the dataset to the file in one piece originally?

I am curious to know why you enabled chunking when you were writing?

I hope you got my point earlier that chunking and hyperslabs are not the
same. Chunking has to do with how HDF5 library internally organizes parts
of the dataset. Hyperslab concept is at the application level, it is
independent of the chunking in the file.

Have a quick look at '4.5 Storage strategies' here
http://www.hdfgroup.org/HDF5/doc/UG/UG_frame10Datasets.html

You can use any of he selection/read methods (hyperslab/elements) on a
HDF5 file irrespective of how it was written/chunked.

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 3 Nov, 2009 21:19:27

Message: 10 of 16

On Tue, 03 Nov 2009 16:09:01 -0500, Tess <tess.brandon@noaa.gov> wrote:

> I just ran your code and realized that while you defined the memory
> space to be rank 3, [x y z], the output is only one value. The way
> you've defined start, stride and count, you should have ended up with a
> 1x3 vector. I need to be able to subset, say, a [1x512x512] slice of
> data.

With this:
start=[7 18 26];
stride=[1 1 1];
count=[1 1 1]; block=[ ];

Count is the number of data points along that specific dimension.
Total number of actual data points selected is 1x1x1 = 1


Did you consider using this:

start=[1 1 1];
stride=[1 1 1];
count=[1 512 512]; block=[];

Subject: reading HDF5 dataset subset

From: Tess

Date: 3 Nov, 2009 21:48:02

Message: 11 of 16

Yes! Done. Thank you.

This is a long shot, but do you have any idea whether there is any intention to add the subsetting functionality of hdfread (for HDF4) into hdf5read? That was so much simpler.

"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.u2t76p0ya5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 03 Nov 2009 16:09:01 -0500, Tess <tess.brandon@noaa.gov> wrote:
>
> > I just ran your code and realized that while you defined the memory
> > space to be rank 3, [x y z], the output is only one value. The way
> > you've defined start, stride and count, you should have ended up with a
> > 1x3 vector. I need to be able to subset, say, a [1x512x512] slice of
> > data.
>
> With this:
> start=[7 18 26];
> stride=[1 1 1];
> count=[1 1 1]; block=[ ];
>
> Count is the number of data points along that specific dimension.
> Total number of actual data points selected is 1x1x1 = 1
>
>
> Did you consider using this:
>
> start=[1 1 1];
> stride=[1 1 1];
> count=[1 512 512]; block=[];

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 4 Nov, 2009 13:36:42

Message: 12 of 16

On Tue, 03 Nov 2009 16:48:02 -0500, Tess <tess.brandon@noaa.gov> wrote:

> Yes! Done. Thank you.
>
> This is a long shot, but do you have any idea whether there is any
> intention to add the subsetting functionality of hdfread (for HDF4) into
> hdf5read? That was so much simpler.

The team may be aware of this need, I'll pass on the message.

Subject: reading HDF5 dataset subset

From: Luis Fernandes

Date: 5 Mar, 2010 14:48:24

Message: 13 of 16

Hi,

I've tried your solution with R2008a (7.6.0) to adapt for my case and I get an error:

??? Could not read dataset.

So, I've copied your code to see if it was my problem and I get the same error.

??? Could not read dataset.

Error in ==> testhyperslab at 20
rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');

testhyperslab is the m file with your code as shown below:

hdf5write('o.h5','/DS1',reshape(1:53*512*512,[53 512 512]))

fileID=H5F.open('o.h5','H5F_ACC_RDONLY','H5P_DEFAULT');
dset=H5D.open(fileID,'/DS1'); % this is a 53x512x512 data set
space=H5D.get_space(dset);


start=[7 18 26]; %zero based!
stride=[1 1 1];
count=[1 1 1]; block=[ ];


H5S.select_hyperslab(space,'H5S_SELECT_SET',fliplr(start-1),... %-1 totake care of 0 based indexing
     fliplr(stride),fliplr(count),fliplr(block)); %fliplrto take care of row/column major reversal (please see the ReadMe.txt in myprevious post
mem_space = H5S.create_simple(3, fliplr(count), []); %see Readme.txt forexplanation on need for flipping


rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');

H5D.close(dset);
H5S.close(space);
H5S.close(mem_space);
H5F.close(fileID);

disp(rdata)

If I read the entire array it's fine, but with hyperslab I get the "can't read dataset" error. Any idea on what's going on? Thanks!
Luis

Subject: reading HDF5 dataset subset

From: John Evans

Date: 5 Mar, 2010 19:36:27

Message: 14 of 16

"Luis Fernandes" <luisfernandes77@hotmail.com> wrote in message <hmr5jo$5dc$1@fred.mathworks.com>...
> Hi,
>
> I've tried your solution with R2008a (7.6.0) to adapt for my case and I get an error:
>
> ??? Could not read dataset.
>
> So, I've copied your code to see if it was my problem and I get the same error.
>
> ??? Could not read dataset.
>
> Error in ==> testhyperslab at 20
> rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');
>
> testhyperslab is the m file with your code as shown below:
>
> hdf5write('o.h5','/DS1',reshape(1:53*512*512,[53 512 512]))
>
> fileID=H5F.open('o.h5','H5F_ACC_RDONLY','H5P_DEFAULT');
> dset=H5D.open(fileID,'/DS1'); % this is a 53x512x512 data set
> space=H5D.get_space(dset);
>
>
> start=[7 18 26]; %zero based!
> stride=[1 1 1];
> count=[1 1 1]; block=[ ];
>
>
> H5S.select_hyperslab(space,'H5S_SELECT_SET',fliplr(start-1),... %-1 totake care of 0 based indexing
> fliplr(stride),fliplr(count),fliplr(block)); %fliplrto take care of row/column major reversal (please see the ReadMe.txt in myprevious post
> mem_space = H5S.create_simple(3, fliplr(count), []); %see Readme.txt forexplanation on need for flipping
>
>
> rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');
>
> H5D.close(dset);
> H5S.close(space);
> H5S.close(mem_space);
> H5F.close(fileID);
>
> disp(rdata)
>
> If I read the entire array it's fine, but with hyperslab I get the "can't read dataset" error. Any idea on what's going on? Thanks!
> Luis

Try using 'H5ML_DEFAULT' instead of 'H5T_NATIVE_INT'.

Subject: reading HDF5 dataset subset

From: Ashish Uthama

Date: 5 Mar, 2010 19:38:41

Message: 15 of 16

On Fri, 05 Mar 2010 09:48:24 -0500, Luis Fernandes
<luisfernandes77@hotmail.com> wrote:

> Hi,
>
> I've tried your solution with R2008a (7.6.0) to adapt for my case and I
> get an error:
>
> ??? Could not read dataset.
>
> So, I've copied your code to see if it was my problem and I get the same
> error.
>
> ??? Could not read dataset.
>
> Error in ==> testhyperslab at 20
> rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');
>
> testhyperslab is the m file with your code as shown below:
> hdf5write('o.h5','/DS1',reshape(1:53*512*512,[53 512 512]))
>
> fileID=H5F.open('o.h5','H5F_ACC_RDONLY','H5P_DEFAULT');
> dset=H5D.open(fileID,'/DS1'); % this is a 53x512x512 data set
> space=H5D.get_space(dset);
>
>
> start=[7 18 26]; %zero based!
> stride=[1 1 1];
> count=[1 1 1]; block=[ ];
>
>
> H5S.select_hyperslab(space,'H5S_SELECT_SET',fliplr(start-1),... %-1
> totake care of 0 based indexing
> fliplr(stride),fliplr(count),fliplr(block)); %fliplrto take care of
> row/column major reversal (please see the ReadMe.txt in myprevious post
> mem_space = H5S.create_simple(3, fliplr(count), []); %see Readme.txt
> forexplanation on need for flipping
>
>
> rdata = H5D.read(dset,'H5T_NATIVE_INT',mem_space,space,'H5P_DEFAULT');
>
> H5D.close(dset);
> H5S.close(space);
> H5S.close(mem_space);
> H5F.close(fileID);
>
> disp(rdata)
>
> If I read the entire array it's fine, but with hyperslab I get the
> "can't read dataset" error. Any idea on what's going on? Thanks!
> Luis

For 8a, try replacing the read with:
rdata = H5D.read(dset,'H5ML_DEFAULT',mem_space,space,'H5P_DEFAULT');

Subject: reading HDF5 dataset subset

From: Luis Fernandes

Date: 8 Mar, 2010 08:58:05

Message: 16 of 16


> For 8a, try replacing the read with:
> rdata = H5D.read(dset,'H5ML_DEFAULT',mem_space,space,'H5P_DEFAULT');


Thanks, it worked.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
hdf5 Tess 2 Nov, 2009 17:19:04
rssFeed for this Thread

Contact us at files@mathworks.com