Newbie: Do h5 files automatically close after filling datasets?

43 views
Skip to first unread message

Lorenzo

unread,
Dec 7, 2011, 11:53:24 AM12/7/11
to h5py
Hi all,

I'm a newbie to all this of hdf5 format, and I've been trying to make
a big hdf5 file with data collected from several small NetCDF files.

When initializing the file i call create_dataset, and then try to fill
it using dataset[...,i] = data, where i is an index incremented for
each file. But after i fill every dataset slice, i write dataset in
the python prompt and it says "<Closed HDF5 file>". I solved this
opening the file for every iteration, but i would like to know if this
is normal behaviour or is there something i'm doing wrong.

Best regards.

Matthew Zwier

unread,
Dec 7, 2011, 1:14:51 PM12/7/11
to h5...@googlegroups.com
Hi Lorenzo,

Can you post the script you're using, or a fragment thereof?

MZ

> --
> You received this message because you are subscribed to the Google Groups "h5py" group.
> To post to this group, send email to h5...@googlegroups.com.
> To unsubscribe from this group, send email to h5py+uns...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/h5py?hl=en.
>

Darren Dale

unread,
Dec 8, 2011, 3:01:41 PM12/8/11
to h5...@googlegroups.com
Also, please post what h5py and hdf5 version info.

Lorenzo Luengo

unread,
Dec 9, 2011, 12:46:28 PM12/9/11
to h5...@googlegroups.com
Here is the file i'm using

http://pastebin.com/ZWvG4UcN

If i place the h5py.File sentence outside the for loop, at the second iteration, all datasets and the file handle are closed. It seems related to these properties:

http://h5py.alfven.org/docs/low/h5p.html#h5py.h5p.PropFAID.set_fclose_degree
http://www.hdfgroup.org/HDF5/doc/RM/RM_H5P.html#Property-SetFcloseDegree

According to the last the, the file closes when all children are closed, but what i want is to keep the dataset open until i write all the data from my source files to it.

Is it possible to avoid closing datasets after write?

Andrew Collette

unread,
Dec 11, 2011, 6:01:46 PM12/11/11
to h5...@googlegroups.com
Hi Lorenzo,

> If i place the h5py.File sentence outside the for loop, at the second
> iteration, all datasets and the file handle are closed.

If you're using h5py 1.3.1 there's a nasty bug with this exact
behavior. What version of h5py/HDF5 do you have?

Since you're writing to the same file for every iteration of the loop
I think you certainly want the file-open statement outside the loop.
But the above bug is the only reason I can think of why the file would
be closed the second time around.

Andrew

Lorenzo Luengo

unread,
Dec 12, 2011, 11:45:15 AM12/12/11
to h5...@googlegroups.com
On 11/12/11 20:01, Andrew Collette wrote:
> Hi Lorenzo,
>
>> If i place the h5py.File sentence outside the for loop, at the second
>> iteration, all datasets and the file handle are closed.
> If you're using h5py 1.3.1 there's a nasty bug with this exact
> behavior. What version of h5py/HDF5 do you have?
I'm using the normal ubuntu (oneiric) packages: h5py-2.0.0-1 and hdf5-1.8.4

>
> Since you're writing to the same file for every iteration of the loop
> I think you certainly want the file-open statement outside the loop.
> But the above bug is the only reason I can think of why the file would
> be closed the second time around.
Of course! The logic way to use it is open the file once, write as many
as needed times and finally close the file, so the open statement should
be outside the loop.
>
> Andrew
>


--
Lorenzo Luengo C.
Ingeniero Civil Electr�nico
Cel: 98270385

Reply all
Reply to author
Forward
0 new messages