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

OSError: NetCDF: HDF error if netCDF4 and h5py installed together #653

Open
eamag opened this issue Apr 29, 2017 · 17 comments
Open

OSError: NetCDF: HDF error if netCDF4 and h5py installed together #653

eamag opened this issue Apr 29, 2017 · 17 comments

Comments

@eamag
Copy link

eamag commented Apr 29, 2017

from netCDF4 import Dataset
import os

data = Dataset(os.path.join(filepath, file), 'r', format='NETCDF4')

File "netCDF4/_netCDF4.pyx", line 1848, in netCDF4._netCDF4.Dataset.init (netCDF4/_netCDF4.c:13983)
OSError: NetCDF: HDF

netCDF4==1.2.7
h5py==2.7.0

@matthew-brett
Copy link
Contributor

How did you install netCDF4, h5py? What system are you on? Which Python are you using?

@matthew-brett
Copy link
Contributor

@eamag - unfortunately, if we don't have any more information from you about your system, it's going to be hard for us to reproduce your problem and fix it.

@eamag
Copy link
Author

eamag commented May 12, 2017

Sorry for late response, @matthew-brett
All packages were installed via pip3, ubuntu 16.04.2, python 3.5.2

@matthew-brett
Copy link
Contributor

No problem about the late response. Here's what I did to try and replicate. I started a fresh Ubuntu 16.04 container:

docker run --rm -ti ubuntu:16.04 /bin/bash

Then I ran these commands in the container, which didn't give me an error:

apt-get update
apt-get install -y wget python3.5 
wget https://bootstrap.pypa.io/get-pip.py
python3.5 get-pip.py --user
~/.local/bin/pip3 install h5py
~/.local/bin/pip3 install netCDF4
wget https://www.unidata.ucar.edu/software/netcdf/examples/test_hgroups.nc
python3.5 -c "import netCDF4; netCDF4.Dataset('test_hgroups.nc', 'r', format='NETCDF4')"

Is there something special about your file that would generate the error? Can you put it somewhere where I can get it to test with?

@matthew-brett
Copy link
Contributor

Also - just to check - could you try uninstalling and installing again:

pip3 uninstall -y h5py netcdf4
pip3 install --user h5py netcdf4

@jennirinker
Copy link

I am getting this issue and can probably help with recreating it.

MWE:

import netCDF4 as nc4
f = nc4.Dataset('sample.nc','w', format='NETCDF4')

Packages:

  • NetCDF4 1.4.0 installed using conda (build py36hfa18eed_1)
  • h5py 2.7.1 installed using pip

I assume this is pip and conda not playing nicely together. I'm going to mess around a bit and see if I can get a workaround.

Pinging @matthew-brett

@jennirinker
Copy link

jennirinker commented May 31, 2018

Solved it: I just uninstalled the version of h5py that was installed with pip.

Interestingly, some other package I have must include h5py as a hidden requirement because it's not shown in pip list or conda list but import h5py works just fine. Magic.

@randallpittman
Copy link
Contributor

Workaround: If netCDF4 is imported first, there is no error and everything works fine!

Any relation to #694?

I need to use h5py and netcdf4-python together. My setup:
OS: Fedora 31
Python: pyenv 3.8.1 virtualenv
netCDF4: 1.5.3
h5py: 2.10.0

Code to cause the problem:

import h5py
import netCDF4

ds = netCDF4.Dataset("my_dataset.nc")

Output:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-6-be938cfa3e55> in <module>
----> 1 ds = netCDF4.Dataset("/data/new/NewportTower_20200227_001106.nc")

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Dataset.__init__()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4._ensure_nc_success()

OSError: [Errno -101] NetCDF: HDF error: b'/data/new/NewportTower_20200227_001106.nc'

@arthur-e
Copy link

arthur-e commented Apr 9, 2020

I can confirm the order in which h5py and netCDF4 are imported makes a difference. Importing netCDF4 first will fix this error.

@randallpittman
Copy link
Contributor

I'd like to just say (with all the love in my heart) that I sure do wish netCDF4-python would be a little less opaque about its errors.

@jswhit
Copy link
Collaborator

jswhit commented Apr 9, 2020

I'm open to suggestions on how to better interpret errors coming from the HDF5 c library.

@randallpittman
Copy link
Contributor

I'm open to suggestions on how to better interpret errors coming from the HDF5 c library.

Fair enough--I guess it's more of an upstream problem.

@randallpittman
Copy link
Contributor

randallpittman commented Apr 9, 2020

@jswhit

I'd like to just say (with all the love in my heart) that I sure do wish netCDF4-python would be a little less opaque about its errors.

I'm open to suggestions on how to better interpret errors coming from the HDF5 c library.

This one's a bad example of what I was thinking of. I more meant stuff like "not a valid ID" when really it could say, "You closed the dataset, dummy, so you can't access its contents anymore."

I've been working on (and using in my projects) a subclass of Dataset that does some nice things like keep the dataset's opening arguments stateful, allow it to be reopened, and give tell you nicely if you're trying to work with a closed dataset. https://gitlab.com/osu-nrsg/ncdataset-python/-/blob/master/ncdataset/_ncdataset.py

@LSRathore
Copy link

I am having the same issue while working on the HPC cluster, however it works fine on the local computer.

My setup-
python 3.6.5
netCDF4 1.5.3
h5py 2.10.0

import netCDF4 as nc
import h5py
data=nc.Dataset("ncfile.nc")

Any solutions to this problem?

@hydronow
Copy link

I am having the same issue while working on the HPC cluster, however it works fine on the local computer.

My setup-
python 3.6.5
netCDF4 1.5.3
h5py 2.10.0

import netCDF4 as nc
import h5py
data=nc.Dataset("ncfile.nc")

Any solutions to this problem?

I am having the same issue with data from the ESGF website (https://esgf-node.llnl.gov/search/esgf-llnl/) .

@LSRathore
Copy link

@hydronow I was getting the error because my netcdf file was incomplete when I transferred it to the cluster. My issue got resolved when I transferred the file again.

@hydronow
Copy link

@lokendrarathore I think you right. At this point I am somewhat confident that the file itself is broken and that the netCDF4 library is working fine.

dlilien added a commit to dlilien/ImpDAR that referenced this issue Jun 30, 2020
Very opaque error: import order of h5py and netCDF4 matters.
See comment on Unidata/netcdf4-python#653
by arthur-e
dlilien added a commit to dlilien/ImpDAR that referenced this issue Jul 2, 2020
* Add support for dual axes (TWTT and depth)

* Fix very opaque error: import order of h5py and netCDF4 matters.
See comment on Unidata/netcdf4-python#653
by arthur-e

* Fix syntax error

* Fix bug in variable-rho NMO exposed by update to scipy
dlilien added a commit to dlilien/ImpDAR that referenced this issue Nov 10, 2021
* Dual axes (#14)

* Add support for dual axes (TWTT and depth)

* Fix very opaque error: import order of h5py and netCDF4 matters.
See comment on Unidata/netcdf4-python#653
by arthur-e

* Fix syntax error

* Fix bug in variable-rho NMO exposed by update to scipy

* Allow switches between old StoDeep matrices when picking (#15)

* Give users a string representation of RadarData and Picks objects

Guard against None in t_srs

* Docs go to links, ref. bluesystems documentation

* Prevent file dialation by incorrect type casting for GSSI

* When you delete picks, resuming picking resumes from where you deleted to

* BSI can handle bad GPS data

* Fix missing trace num on bsi

* Sequentialize to reduce peak memory (#18)

* Sequentialize to reduce peak memory

Operations from the command line are now mostly sequential. This
should reduce peak memory usage for most operations. Exceptions are
concatenating and loading gecko or osu files.

* Make the list copy python 2/3 compatible

* Fully test processing, with more options to concatenate profiles with differing picks

* Move Pulse EKKO partitioning into the load() function

As per issue #16, the PE project files were inconsistently handled
because the partitioning was being done in load_and_exit(). Move that
part of the function into load().

Also, change the loop so that the load() function can handle a mix of
project files and standard PE files.

Co-authored-by: Benjamin Hills <bhills@uw.edu>

* Fix order of operations error with W, E with BSI

Had resulted in an error of 0.66666 in longitude

* Minor bug fixes

* Travis forced migration to .com, update badge

* Fix some issues with version-dependent colors, segy

* Fix problem where on some versions strings are already decoded for BSI

* Fix second BSI decode issue

* Try to accept skbuild errors on 2.7

* Try to fix skbuild on 2.7

* Update readme for Python2.7 EOL

* Begin switch to github actions

Travis is not running on .com due to lack of credits--we are not going to pay.

* Install impdar before testing

* Auto Picker  (#19)

* First commit for DeLoRES reader

Still needs more work for GPS info. The NMEA strings written on these
files don't seem to be complete.

* Slight change to Pulse Ekko reader for OSU group.

* Change for Pulse Ekko GPS files with more than only GGA strings.

* Slight change for the GSSI reader for data from the OSU group.

* Add a reader for the OSU HF data

* A few small changes for OSU data, interpolation, plotting

* Add a reader for MALA RAMAC data

* Allow alternative data variable names for Olaf Matlab files.

* Update and test all of the analysis scripts.

This is to finalize the scripts for Hills et al. (2020) to be submitted
to the Radioglaciology Annals volume.
A total of 6 attenuation methods implemented:
Method 2 -- Jacobel et al. (2009)
Method 3 -- Schroeder et al. (2016a, 2016b)
Method 5 -- MacGregor et al. (2014); Matsuoka et al. (2010)
Method 6a -- Depth-resolved (regression similar to method 1)
Method 6b -- Depth-resolved (regression similar to method 3)
Method 7 -- Secondary reflection as in Christianson et al. (2016)

* Change analysis file names.

* Update error in attenuation calculations.

* Update load script for ApRES

Accommodate multiple files and multiple bursts

* Add a range differencing function for ApRES.

Following Brennan et al. (2013) and Nicholls et al. (2015) calculate the
vertical motion using a moving window and correlation coefficient
calculated at subsequent depths in two acquisition profiles. Vertical
ice motion between acquisitions can be seen for both internal
reflections and the bed reflector.

* Add a range differencing function to the ApRES processor.

Uses the correlation coefficient between two ApRES profiles to determine
the relative motion between acquisitions.

* Add option for external depth array in ApRES range differencing.

* Add a warning on interpolation

If the gps data onto which the interpolation will be done has longitude
notation different than the radar longitude, then raise an error. We
were having problems with one being written from 0 - 360 and the other
from -180 - 180.

* Some small fixes for typos in hcrop

* Add error to ApRES coherence calculation.

* Update the ApRES range function to output uncertainty

* Small change in ApRES range differencing function

Center the depth profile with each point now representing the center of
the window rather than the top.

* Some changes to Joshua's spectral density plotting.

There were too many options in the plot command which made it confusing.
I cut some out and hopefully made the help file more clear as to how one
could plot the spectral density for each trace using Joshua's function.

* Update specdense plotting to satisfy Travis.

* Add a function for calculating the phase/range uncertainty.

Following Kingslake et al. (2014) calculate uncertainty with a noise
phasor that has random phase and magnitude equal to the median of the
measured phasor.

* Typo in Pulse EKKO load script.

Line to load the time step from the header file was looking for the time
window as 'WINDOW' when a later line has 'AMPLITUDE WINDOW' so it was
loading that number instead.

* Add a load script for the St Olaf matlab files.

These files are mostly the same as the ImpDAR matlab files but commonly
have the data named as 'filtdata', 'interp_data', 'migdata', etc.

* Changes to naming convention for ApRES uncertainty

There were too many variables named similar things, so I made it a bit
more clear.

* Changes to the crop function for pretrig

* Change some notation in the ApRES scripts.

* Typo in Kirchhoff Migration

Removed 1e6 on the depth vector

* Add an autopicking routine.

This routine asks for some picked points on the left side of the image
and will spit out picks across the image for each.

* Allow auto picks from any point on the image

* Fixed some bugs with the sequence of the autopicker.

The autopicker was not working nicely with the normal picker. That is,
when switching back and forth, the program would break. This was because
of an indexing issue with the pick number. Fixed.

* Some of the CReSIS data products are saved as an alternative version of .mat files, allow these to be loaded into ImpDAR

* Add a try/except line for h5py import so that Travis will be happy.

* Created Issue #20

This is in regard to the adaptive horizontal filter. The scaling
function that is used to keep the filter from changing the deeper data
is much more complicated than what I would have used. Considering
simplifying.

* Simplify the scaling function for ahfilt

This was overly complicated and different from that being used in hfilt.
I just copied from hfilt, and cleaned up some of the code. I also added
optionality for setting the window_size from the command line function.

* Change the adaptive hfilt test to make Travis happy.

* A mess of a PR (mostly ApRES scripts) (#21)

* First commit for DeLoRES reader

Still needs more work for GPS info. The NMEA strings written on these
files don't seem to be complete.

* Slight change to Pulse Ekko reader for OSU group.

* Change for Pulse Ekko GPS files with more than only GGA strings.

* Slight change for the GSSI reader for data from the OSU group.

* Add a reader for the OSU HF data

* A few small changes for OSU data, interpolation, plotting

* Add a reader for MALA RAMAC data

* Allow alternative data variable names for Olaf Matlab files.

* Update and test all of the analysis scripts.

This is to finalize the scripts for Hills et al. (2020) to be submitted
to the Radioglaciology Annals volume.
A total of 6 attenuation methods implemented:
Method 2 -- Jacobel et al. (2009)
Method 3 -- Schroeder et al. (2016a, 2016b)
Method 5 -- MacGregor et al. (2014); Matsuoka et al. (2010)
Method 6a -- Depth-resolved (regression similar to method 1)
Method 6b -- Depth-resolved (regression similar to method 3)
Method 7 -- Secondary reflection as in Christianson et al. (2016)

* Change analysis file names.

* Update error in attenuation calculations.

* Update load script for ApRES

Accommodate multiple files and multiple bursts

* Add a range differencing function for ApRES.

Following Brennan et al. (2013) and Nicholls et al. (2015) calculate the
vertical motion using a moving window and correlation coefficient
calculated at subsequent depths in two acquisition profiles. Vertical
ice motion between acquisitions can be seen for both internal
reflections and the bed reflector.

* Add a range differencing function to the ApRES processor.

Uses the correlation coefficient between two ApRES profiles to determine
the relative motion between acquisitions.

* Add option for external depth array in ApRES range differencing.

* Add a warning on interpolation

If the gps data onto which the interpolation will be done has longitude
notation different than the radar longitude, then raise an error. We
were having problems with one being written from 0 - 360 and the other
from -180 - 180.

* Some small fixes for typos in hcrop

* Add error to ApRES coherence calculation.

* Update the ApRES range function to output uncertainty

* Small change in ApRES range differencing function

Center the depth profile with each point now representing the center of
the window rather than the top.

* Some changes to Joshua's spectral density plotting.

There were too many options in the plot command which made it confusing.
I cut some out and hopefully made the help file more clear as to how one
could plot the spectral density for each trace using Joshua's function.

* Update specdense plotting to satisfy Travis.

* Add a function for calculating the phase/range uncertainty.

Following Kingslake et al. (2014) calculate uncertainty with a noise
phasor that has random phase and magnitude equal to the median of the
measured phasor.

* Cause upload to PyPi (1.0.1 and 1.0.2 are sadly missing)

* Fix the OSU load script

Very minor typo to be fixed on the file name variable.

* fix nan issue in load

* Fix test naming for coveralls

* Again, coveralls

* Switch to codecov

* Learning yml syntax...

* Try testing with tox as recommended

* More bad syntax

* Go back to using pytest

* No really, pytest not unittest

* Try an optional dep

* More syntax

* Try pyqt5 wheel

* Bad qt version?

* Nope, really newer qt

* Try with xvfb

* Syntax again

* Matplotlib deprecated no radius for picker

* h5py and segyio required, qt5, seisunix, gdal optional

* Rebadge

* Use github version of seisunix

* Use github version of seisunix

* Do not let gh check seisunix with flake8

* Yes to install for su

* Try to skip known problems

* Remove bash from yml

* And try again

* Split testing for GUI/non

* Add in GDAL

* Exclude gdal on non-linux

* Try newer gdal

* Try to make Windows work

* Try to make Windows work with overflow

* Start testing PyPi upload

* Jobs need runs-on or uses...

* Just one job.

* Many linux?

* Was entrypoint permissions the issue for manylinux?

* Try to fix twine issues for manylinux

* And try a MacOS build

* Help MacOS find fortran

* 3.10 just is not ready yet

* Fix success checks

* Try to diagnose problem uploading to codecov

* Continue diagnosis

* Try skipping pytest-cov

* reorder args

* Dodge bad gdal on pip for 3.9 and 3.0.4

* Finalizing bug fixes before merge into master

* Try to fix mac build

* Dont fail for codecov

* All set for merge, just skip building tarball extra times

Co-authored-by: Benjamin Hills <bhills@uw.edu>
Co-authored-by: Ben Hills <benjaminhhills@gmail.com>
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

8 participants