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

HDF error on close when using _FillValue attributes #54

Closed
dopplershift opened this issue Feb 26, 2014 · 6 comments
Closed

HDF error on close when using _FillValue attributes #54

dopplershift opened this issue Feb 26, 2014 · 6 comments

Comments

@dopplershift
Copy link
Member

From martin.r...@gmail.com on June 22, 2010 16:37:48

What steps will reproduce the problem? 1. Run the attached file 2. 3. What is the expected output? What do you see instead? I expect a file containing all defined attributes, I get an error instead (and a half complete file)

$ python testcase.py
Traceback (most recent call last):
File "testcase.py", line 23, in
rootgrp.close()
File "netCDF4.pyx", line 1350, in netCDF4.Dataset.close (netCDF4.c:6119)
RuntimeError: HDF error What version of the product are you using? On what operating system? netcdf4-python 9.1, on linux fedora 10, 64 bits Please provide any additional information below. Changing 'attrname' in the program from "_FillValue" to something else solves the problem... Is there something wrong with this attribute name ?

Thanks,
Martin

Attachment: testcase.py

Original issue: http://code.google.com/p/netcdf4-python/issues/detail?id=54

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on June 22, 2010 16:26:17

What version of the HDF5 library are you linking?

(can't reproduce this error here on macos x 10.5 using 1.8.4-patch1, but I will try on a x86_64 linux system tomorrow)

@dopplershift
Copy link
Member Author

From martin.r...@gmail.com on June 22, 2010 16:42:28

HDF5 version is 1.8.5, and netcdf is 4.1.1

Thanks for the quick reaction :)

Martin

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on June 23, 2010 04:40:58

This error happens with hdf5 1.8.5, but not 1.8.4-patch1. No idea why.

However, it's probably not a good idea to set the _FillValue this way. _FillValue is a special netcdf attribute that controls how the variable is filled when the varable is created and before any data is written to it. Therefore, it's best to set it when the variable is created, before anything else has happend to it. You can set it at variable creation time using the fill_value keyword to createVariable, i.e. in your example

var_a = rootgrp.createVariable("A", 'float64', ('x', 'y'),fill_value=-99999.)

This seems to work fine in both versions of hdf5.

I still consider this a bug though - probably in the hdf5 library or the netcdf-4 C libraries. I'll try to write a simple C program that triggers it and then report it to unidata.

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on June 23, 2010 04:57:28

It also works with hdf5 1.8.5 if you set the attribute right after the variable is created, before you do anything else to the file, i.e.

attrname = "_FillValue"
var_a = rootgrp.createVariable("A", 'float64', ('x', 'y'))
setattr(var_a, attrname, np.float64(-99999.))
var_b = rootgrp.createVariable("B", 'float64', ('x', 'y'))
setattr(var_b, attrname, np.float64(-99999.))

@dopplershift
Copy link
Member Author

From martin.r...@gmail.com on June 23, 2010 11:40:06

Indeed, it does work the way you describe it.

Thank you very much for the help !

Martin

@dopplershift
Copy link
Member Author

From whitaker.jeffrey@gmail.com on February 25, 2014 18:04:09

Status: Fixed

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

No branches or pull requests

1 participant