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

get_events() fails on Google Colab (import/plugin problem) #2547

Closed
tclements opened this issue Feb 6, 2020 · 3 comments
Closed

get_events() fails on Google Colab (import/plugin problem) #2547

tclements opened this issue Feb 6, 2020 · 3 comments
Labels
question Questions asked by users. Please use https://discourse.obspy.org for asking new questions

Comments

@tclements
Copy link

OS ubuntu: 18.04
Python version: 3.6
Obspy versions: 1.1.1
Obspy installed using pip

This is on run on Google Colab. We are trying to teach Obspy through Colab so students do not have to deal with Anaconda and local files/python installations.

Reproduction code:

client = Client("IRIS", debug=True) 
t1 = obspy.UTCDateTime("2019-07-06")
t2 = obspy.UTCDateTime("2019-07-07")
cat = client.get_events(starttime=t1, endtime=t2, minmagnitude=7)

The connection to IRIS looks good from the debug:

data_stream = client._download("http://service.iris.edu/fdsnws/event/1/query?starttime=2019-07-06T00%3A00%3A00.000000&endtime=2019-07-07T00%3A00%3A00.000000&minmagnitude=7.0")
data_stream.seek(0, 0)
data_stream

Downloading http://service.iris.edu/fdsnws/event/1/query?starttime=2019-07-06T00%3A00%3A00.000000&endtime=2019-07-07T00%3A00%3A00.000000&minmagnitude=7.0 with requesting gzip compression
Downloaded http://service.iris.edu/fdsnws/event/1/query?starttime=2019-07-06T00%3A00%3A00.000000&endtime=2019-07-07T00%3A00%3A00.000000&minmagnitude=7.0 with HTTP code: 200

<_io.BytesIO at 0x7fe5a7fd4e60>

Error is thrown when trying to read events from io.BytesIO object:

obspy.read_events(data_stream,format="quakeml")

---------------------------------------------------------------------------

KeyError                                  Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/obspy/core/util/base.py in _read_from_plugin(plugin_type, filename, format, **kwargs)
    443         try:
--> 444             format_ep = eps[format]
    445         except (KeyError, IndexError):

KeyError: 'QUAKEML'


During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)

12 frames

</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-165> in _read(filename, format, **kwargs)

TypeError: Format "QUAKEML" is not supported. Supported types: 


During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)

KeyError: 'QUAKEML'


During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)

</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-164> in read_events(pathname_or_url, format, **kwargs)

</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-163> in read_events(pathname_or_url, format, **kwargs)

</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-165> in _read(filename, format, **kwargs)

/usr/local/lib/python3.6/dist-packages/obspy/core/util/base.py in _read_from_plugin(plugin_type, filename, format, **kwargs)
    445         except (KeyError, IndexError):
    446             msg = "Format \"%s\" is not supported. Supported types: %s"
--> 447             raise TypeError(msg % (format, ', '.join(eps)))
    448     # file format should be known by now
    449     try:

TypeError: Format "QUAKEML" is not supported. Supported types: 
@krischer
Copy link
Member

krischer commented Feb 6, 2020

I just tried this and what happens is that the pkg_util entry points are not found. Internally ObsPy uses these as a type of plug-in structure to discover and load all available file formats at startup time. Thus in your case it does not have the QuakeML plugin and consequently cannot read the files from the web service.

Thankfully there is an easy solution - after !pip install obspy just restart the runtime (Runtime -> Restart runtime ...) and then it worked - at least when I just tried it. I'm not sure about the inner working of colab and how often an environment is reset but this is a quick, altough also dirty way to get the whole thing to work.

@tclements
Copy link
Author

Thanks, that worked! Closing

@megies megies changed the title get_events() fails on Google Colab get_events() fails on Google Colab (import/plugin problem) Feb 7, 2020
@megies megies added the question Questions asked by users. Please use https://discourse.obspy.org for asking new questions label Feb 7, 2020
@Elemento24
Copy link

Hey @krischer,
Have you find a workaround for this till now which doesn't involve restarting your Kernel, since this trick fails when you have to save a Kaggle kernel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions asked by users. Please use https://discourse.obspy.org for asking new questions
Projects
None yet
Development

No branches or pull requests

4 participants