[obspy-users] AttribDict

Tobias Megies megies at geophysik.uni-muenchen.de
Mon Jun 4 10:54:08 CEST 2018


Hi Mike,

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

short answer: not at all. ;-)



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



On 31/05/18 17:23, Mike Hagerty wrote:
> I was given quakeML files that have blocks like this:
> 
>        <magnitude publicID="smi:local/305afa78-34cb-4e82-abe5-ef610b114c80">
>          <mag>
>            <value>-1.69791750681</value>
>            <uncertainty>AttribDict({'error': 
> 0.06334087421841221})</uncertainty>
>          </mag>
> 
> 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
> 
> 
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> https://lists.swapbytes.de/mailman/listinfo/obspy-users
> 



More information about the obspy-users mailing list