niosh-mining / obsplus

A Pandas-Centric ObsPy Expansion Pack
GNU Lesser General Public License v3.0
38 stars 8 forks source link

Some tests fail #210

Closed seisman closed 3 years ago

seisman commented 3 years ago

Description

I'm running the full tests following the instructions in https://niosh-mining.github.io/obsplus/versions/latest/notebooks/contributing.html, but I got some failures.

What I Did

Running pytest tests:

Error messages:

============================================================== FAILURES ===============================================================
_____________________________________ TestGetWaveforms.test_streams_basics[bing_stream_processed] _____________________________________

self = <test_fetcher.TestGetWaveforms object at 0x7fc14d5a4f40>, stream = <obspy.core.stream.Stream object at 0x7fc16c3d7c70>

    def test_streams_basics(self, stream):
        """ ensure a non-empty waveforms was returned """
        assert isinstance(stream, obspy.Stream)
>       assert len(stream)
E       assert 0
E        +  where 0 = len(<obspy.core.stream.Stream object at 0x7fc16c3d7c70>)

tests/test_structures/test_fetcher.py:222: AssertionError
_____________________________________________ TestGetWaveforms.test_timebefore_time_after _____________________________________________

self = <test_fetcher.TestGetWaveforms object at 0x7fc16aec3f10>
bingham_dataset = Dataset: bingham_test with description:
    The Bingham Canyon dataset includes waveforms recorded during and after
 ...ase picks to the events.
    As such, this dataset should be used for testing and demonstration
    purposes only.

    def test_timebefore_time_after(self, bingham_dataset):
        """Ensure using time_before and time_after as ints works. see #168. """
        fetcher = bingham_dataset.get_fetcher(time_before=1, time_after=10)
        for eid, st in fetcher.yield_event_waveforms():
>           assert len(st)
E           assert 0
E            +  where 0 = len(<obspy.core.stream.Stream object at 0x7fc14e976f40>)

tests/test_structures/test_fetcher.py:275: AssertionError
_____________________________________________ TestYieldEventWaveforms.test_stream_length ______________________________________________

self = <test_fetcher.TestYieldEventWaveforms object at 0x7fc14d698640>
bingham_stream_dict = {'smi:local/02468992-da3e-407b-b0bf-7b8450a2bbb0': <obspy.core.stream.Stream object at 0x7fc14ed0ce20>, 'smi:local/3e6...14ecd34f0>, 'smi:local/467ae95b-1254-48fa-89c9-0d83440fd90e': <obspy.core.stream.Stream object at 0x7fc14d4746a0>, ...}

    def test_stream_length(self, bingham_stream_dict):
        """All of the events should have waveform data."""
        has_data = [bool(x) for x in bingham_stream_dict.values()]
>       assert all(has_data)
E       assert False
E        +  where False = all([False, False, True, False, False, False, ...])

tests/test_structures/test_fetcher.py:485: AssertionError
_____________________________________________ TestYieldEventWaveforms.test_event_streams ______________________________________________

self = <test_fetcher.TestYieldEventWaveforms object at 0x7fc14d535190>
bingham_dataset = Dataset: bingham_test with description:
    The Bingham Canyon dataset includes waveforms recorded during and after
 ...ase picks to the events.
    As such, this dataset should be used for testing and demonstration
    purposes only.

bingham_stream_dict = {'smi:local/02468992-da3e-407b-b0bf-7b8450a2bbb0': <obspy.core.stream.Stream object at 0x7fc14ed0ce20>, 'smi:local/3e6...14ecd34f0>, 'smi:local/467ae95b-1254-48fa-89c9-0d83440fd90e': <obspy.core.stream.Stream object at 0x7fc14d4746a0>, ...}

    def test_event_streams(self, bingham_dataset, bingham_stream_dict):
        """ Ensure the correct streams are given for ids. """
        cat = bingham_dataset.event_client.get_events()
        evs = {str(ev.resource_id): ev for ev in cat}
        for eve_id, st in bingham_stream_dict.items():
>           assert len(st), f"no data for event:{eve_id}"
E           AssertionError: no data for event:smi:local/02468992-da3e-407b-b0bf-7b8450a2bbb0
E           assert 0
E            +  where 0 = len(<obspy.core.stream.Stream object at 0x7fc14ed0ce20>)

tests/test_structures/test_fetcher.py:492: AssertionError
______________________________________ TestYieldEventWaveforms.test_yield_event_waveforms_no_inv ______________________________________

self = <test_fetcher.TestYieldEventWaveforms object at 0x7fc14d5737f0>
fetcher_no_inv = <obsplus.structures.fetcher.Fetcher object at 0x7fc14d5733a0>

    def test_yield_event_waveforms_no_inv(self, fetcher_no_inv):
        """
        WaveFetchers backed by WaveBanks should be able to pull
        station data from wavebank index df in most cases.
        """
        # ensure the inv_df is not None
        inv_df = fetcher_no_inv.station_df
        assert inv_df is not None
        assert not inv_df.empty
        kwargs = dict(time_after=10, time_before=20, reference="p")
        st_dict = dict(fetcher_no_inv.yield_event_waveforms(**kwargs))
>       self.check_stream_dict(st_dict)

tests/test_structures/test_fetcher.py:510:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <test_fetcher.TestYieldEventWaveforms object at 0x7fc14d5737f0>
st_dict = {'smi:local/02468992-da3e-407b-b0bf-7b8450a2bbb0': <obspy.core.stream.Stream object at 0x7fc14d67cdf0>, 'smi:local/3e6...14d54bf40>, 'smi:local/467ae95b-1254-48fa-89c9-0d83440fd90e': <obspy.core.stream.Stream object at 0x7fc14d5d7c10>, ...}

    def check_stream_dict(self, st_dict):
        """ test waveforms dict """
        assert isinstance(st_dict, dict) and st_dict
        for name, st in st_dict.items():
>           assert isinstance(st, obspy.Stream) and len(st)
E           AssertionError: assert (True and 0)
E            +  where True = isinstance(<obspy.core.stream.Stream object at 0x7fc14d67cdf0>, <class 'obspy.core.stream.Stream'>)
E            +    where <class 'obspy.core.stream.Stream'> = obspy.Stream
E            +  and   0 = len(<obspy.core.stream.Stream object at 0x7fc14d67cdf0>)

tests/test_structures/test_fetcher.py:350: AssertionError
_______________________________________ TestYieldEventWaveforms.test_event_bank_with_one_event ________________________________________

self = <test_fetcher.TestYieldEventWaveforms object at 0x7fc14d567220>
fetcher_one_event = <obsplus.structures.fetcher.Fetcher object at 0x7fc14d5b9370>

    def test_event_bank_with_one_event(self, fetcher_one_event):
        """
        Ensure an event waveform can be retrieved from a bank with only
        one event. See #186.
        """
        kwargs = dict(time_before=1, time_after=1)
        out = dict(fetcher_one_event.yield_event_waveforms(**kwargs))
        assert len(out) == 1
        st = list(out.values())[0]
>       assert len(st)
E       assert 0
E        +  where 0 = len(<obspy.core.stream.Stream object at 0x7fc14ecad520>)

tests/test_structures/test_fetcher.py:569: AssertionError
___________________________________________ TestFetcherDuplicateChannels.test_get_waveforms ___________________________________________

self = <test_fetcher.TestFetcherDuplicateChannels object at 0x7fc14d68aa60>
fetcher_duplicate_channels = <obsplus.structures.fetcher.Fetcher object at 0x7fc14d6a1bb0>

    def test_get_waveforms(self, fetcher_duplicate_channels):
        """Ensure the Fetcher can yield event waveforms."""
        fet = fetcher_duplicate_channels
        # before the fix this would raise; just check the output
        st_dict = dict(fet.yield_event_waveforms(time_after=5, time_before=1))
        for event_id, st in st_dict.items():
            assert isinstance(st, obspy.Stream)
>           assert len(st)
E           assert 0
E            +  where 0 = len(<obspy.core.stream.Stream object at 0x7fc14ec30280>)

xref: https://github.com/openjournals/joss-reviews/issues/2696

d-chambers commented 3 years ago

Hi @seisman,

There might be multiple issues going on here but there looks to be at least one issue with the test datasets. Can you try deleting or renaming the opsdata folder then running the tests again? It should be located at ~/opsdata

I have seen something similar before when 1) I upgraded from a very old version of ObsPlus to a more recent version and 2) when the dataset download failed before it was completed. Did you have an older version of ObsPlus installed on your laptop or is there any reason the internet connection was interrupted the first time you ran the test suite?

seisman commented 3 years ago

After deleting the data in ~/opsdata, the tests now pass. Thanks.