eqcorrscan / EQcorrscan

Earthquake detection and analysis in Python.
https://eqcorrscan.readthedocs.io/en/latest/
Other
166 stars 86 forks source link

Subspace tests fail due to h5py related error: AttributeError: 'Dataset' object has no attribute 'value' #437

Closed TomWinder closed 3 years ago

TomWinder commented 4 years ago

What do you need help with?

Hi Calum, I've downloaded and installed eqcorrscan (using conda), and run the test script, but it has produced some errors / failed tests. From a quick look at the log, it seems to be a single error which is causing all the issues, but I'm not familiar enough with the code to know if it is on my end or a bug.

Provide an example so that we can reproduce your problem

Install eqcorrscan via conda install, pip install pytest, run test_eqcorrscan.py

What help would you like?

Let me know whether the issue is caused by my install / environment, or a bug in the code!

What is your setup? (please complete the following information):**

Log file attached. eqcorrscan_test.log

calum-chamberlain commented 4 years ago

Hi Tom, Bugger - it looks like some test-data were not downloaded successfully for some reason! In particular it looks like all the files in this directory were not downloaded/extracted. Your best bet might be to download the files manually and put them in the required place. Otherwise you can remove the whole test-data directory and re-run to force re-downloading.

On the other hand, if you don't care about using subspace then you can ignore these fails.

Sorry about this!

TomWinder commented 4 years ago

Hmm. I've had a look, and in both my downloads (through the conda install and running the test script, and through cloning the git repository) the file (eqcorrscan/tests/test_data/subspace/master_detector_multi.h5) is present, but when I follow the read function it gives this same AttributeError (in both cases):

In [1]: import h5py

In [2]: filename = '/home/tebw2/.miniconda3/envs/eqcorrscan/lib/python3.7/site-packages/eqcorrscan/tests/test_data/subspace/master_detector_multi.h5'

In [3]: f = h5py.File(filename, "r")

In [4]: f["data"].attrs["length"]
Out[4]: 1

In [5]: f["data"]["data_0"]
Out[5]: <HDF5 dataset "data_0": shape (540, 540), type "<f8">

In [6]: a = f["data"]["data_0"]

In [7]: f["data"]["data_0"].value
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-355d0f8731f6> in <module>
----> 1 f["data"]["data_0"].value

AttributeError: 'Dataset' object has no attribute 'value'

I also previously tried re-downloading in case this was the cause, which made no difference (though I encountered the issues with needing to remove the download and .eqcorrscan directories before being able to re-run the tests described in #435 ).

calum-chamberlain commented 4 years ago

The plot thickens! Can you let me know what version of h5py you have installed? I will try to reproduce here, but because this used to work I suspect that it might be a version thing...

TomWinder commented 4 years ago

Yep, classic. I'm on 3.1.0

calum-chamberlain commented 4 years ago

So I tested this locally with h5py 2.10 (from 2019 it appears!) and it ran fine, but on upgrading to 3.1.0 I get the same error.

This appears to be due to a change in the 3.x series noted on this page:

The deprecated Dataset.value property was removed. Use ds[()] to read all data from any dataset.

To get around this we will need to update the codebase a little - @TomWinder if you want to fix this in a small PR that would be greatly appreciated, otherwise, if you want to ignore this for now, then you can probably safely downgrade h5py until I get around to fixing this.

I'm going to update the title of this issue to make it easier to find for anyone else running into this error.

TomWinder commented 3 years ago

I 'downdated' to 2.10 and can confirm this sorts the issue for me, too. I just have one error which is the "1.0" vs "1" comparison.

For the time being I'm just going to run like this. I would be happy to submit a PR when I have a bit more time, but I think it's likely you'll get around to it before me, I'm afraid!