AttribDict

I was given quakeML files that have blocks like this:

-1.69791750681 AttribDict({'error': 0.06334087421841221})

obspy read_events() complains about the AttribDict:

…/obspy/obspy/io/quakeml/core.py:181: UserWarning: Could not convert AttribDict({‘error’: 0.70882453572021886}) to type <class ‘float’>. Returning None.
warnings.warn(msg % (text, convert_to))

Does anyone know if/how AttribDict is supposed to be used within quakeML ?

Cheers!
-Mike

Hi Mike,

> Does anyone know if/how AttribDict is supposed to be used *within* quakeML ?

short answer: not at all. :wink:

long answer:

Did you write that file yourself?

I was able to reproduce this by misusing obspy like this:

from obspy import read_events
from obspy.core.util import AttribDict
cat = read_events()
mag = cat[0].magnitudes[0]
mag.mag_errors.uncertainty = AttribDict({'error': 0.06334087421841221})
cat.write('/tmp/trash.xml', format='QUAKEML')

But that's not at all what you want to do, instead you probably wanted to do:

from obspy import read_events
from obspy.core.util import AttribDict
cat = read_events()
mag = cat[0].magnitudes[0]
mag.mag_errors.uncertainty = 0.06334087421841221
cat.write('/tmp/trash.xml', format='QUAKEML')

Also, to avoid such issues in the future, you might want to consider to use "cat.write('/tmp/trash.xml', format='QUAKEML', validate=False)" which raises an AssertionError in the first (bad) usage case.

cheers,
Tobias

Did you write that file yourself?

Hey Tobias, are you throwing me shade ? :slight_smile:
No, I didn't write the file, just trying to figure out if it was valid use
of AttribDict.

Also, to avoid such issues in the future, you might want to consider to
use "cat.write('/tmp/trash.xml', format='QUAKEML', validate=False)" which
raises an AssertionError in the first (bad) usage case.

I think you mean 'validate=True' - but that just checks quakeML against the
schema (xsd), no ?
So, it's definitely violating the quakeML schema to use AttribDict this way
?

Cheers!
-Mike

Hi Mike,

    Did you write that file yourself?

Hey Tobias, are you throwing me shade ? :slight_smile:
No, I didn't write the file, just trying to figure out if it was valid
use of AttribDict.

:wink: No, was just curious because whoever wrote that file should be made
aware of the problem if possible.

    Also, to avoid such issues in the future, you might want to consider
    to use "cat.write('/tmp/trash.xml', format='QUAKEML',
    validate=False)" which raises an AssertionError in the first (bad)
    usage case.

I think you mean 'validate=True' - but that just checks quakeML against
the schema (xsd), no ?
So, it's definitely violating the quakeML schema to use AttribDict this
way ?

Yeah, that's right, "validate=True" is what I meant.
And yes, this is definitely violating the schema and also yes, obspy
would've raised an AssertionError when using the validation option
during writing the file.

Like I mentioned it would be good if you could tell the person you got
the QuakeML from of this faulty ObsPy/QuakeML usage.

cheers,
Tobias