[obspy-users] writing USGS/NEIC QuakeML files

Hearne, Mike mhearne at usgs.gov
Mon Mar 6 22:21:31 CET 2017


According to a member of our web team at the NEIC, this has been fixed
as of this morning.  Please post here if you see any more issues, and
I'll try to pass those on.

--Mike Hearne

On Mon, Mar 6, 2017 at 12:19 AM, Lion Krischer
<krischer at geophysik.uni-muenchen.de> wrote:
> Hi Alberto,
>
> the resource ids in the file are not valid.
>
> Upon writing ObsPy checks if the URI validates according to the URI regex
> defined in the QuakeML standard. If not it tries to make it validate but
> that is of course only possible for some limited cases. In other cases it
> raises the error you see.
>
> The original QuakeML from the USGS also fails to validate against the
> schema.
>
> The allowed resource URIs are defined in section 3.1 of the QuakeML spec.
>
> You could "fix" this by looping through the file and setting all
> resource_ids to valid identifiers. A proper fix would have to be done by the
> USGS on the server side.
>
> Cheers!
>
> Lion
>
>
>
> On 04/03/2017 20:32, Alberto Michelini wrote:
>
> Dear all,
>
> as you know already USGS/NEIC stepped to https starting March 1st. Since
> then I have been experiencing problems with the event FDSN web service
> script that writes the QuakeML file.
>
> I just  updated to 1.03 but I am still experiencing the same problem as with
> the previous version of obspy 1.02.
>
> In practice, just try to run the following commands  that are nothing else
> than a global search
>
> In [1]: from obspy.clients.fdsn import Client
> In [2]: from obspy.clients.fdsn.header import URL_MAPPINGS
> In [3]: from obspy import UTCDateTime, Catalog
> In [4]: starttime = UTCDateTime("2010-01-01")
> In [5]: endtime = UTCDateTime("2011-01-01")
> In [6]: client = Client("USGS”)
> In [7]: minmag = 7.0
> In [8]: maxmag = 9.9
> In [9]: cat = client.get_events(starttime=starttime,
> endtime=endtime,minmagnitude=minmag, maxmagnitude=maxmag)
> In [10]: len(cat)
> Out[10]: 24
>
> In [11]: cat.write("output_USGS.qml",format="QUAKEML")
> ---------------------------------------------------------------------------
> ValueError                                Traceback (most recent call last)
> <ipython-input-16-9edfe4c285e1> in <module>()
> ----> 1 cat.write("output_USGS.qml",format="QUAKEML")
>
> /Users/michelini/anaconda/lib/python2.7/site-packages/obspy/core/event/catalog.pyc
> in write(self, filename, format, **kwargs)
>     500             msg = "Format \"%s\" is not supported. Supported types:
> %s"
>     501             raise TypeError(msg % (format, ',
> '.join(EVENT_ENTRY_POINTS)))
> --> 502         write_format(self, filename, **kwargs)
>     503
>     504     def plot(self, projection='global', resolution='l',
>
> /Users/michelini/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.pyc
> in _write_quakeml(catalog, filename, validate, nsmap, **kwargs)
>    1813     if nsmap:
>    1814         nsmap_.update(nsmap)
> -> 1815     xml_doc = Pickler(nsmap=nsmap_).dumps(catalog)
>    1816
>    1817     if validate is True and not _validate(io.BytesIO(xml_doc)):
>
> /Users/michelini/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.pyc
> in dumps(self, catalog)
>    1073         :returns: QuakeML formatted string.
>    1074         """
> -> 1075         return self._serialize(catalog)
>    1076
>    1077     def _id(self, obj):
>
> /Users/michelini/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.pyc
> in _serialize(self, catalog, pretty_print)
>    1710             if hasattr(event, "preferred_origin_id"):
>    1711                 self._str(event.preferred_origin_id, event_el,
> -> 1712                           'preferredOriginID')
>    1713             if hasattr(event, "preferred_magnitude_id"):
>    1714                 self._str(event.preferred_magnitude_id, event_el,
>
> /Users/michelini/anaconda/lib/python2.7/site-packages/obspy/io/quakeml/core.pyc
> in _str(self, value, root, tag, always_create, attrib)
>    1083     def _str(self, value, root, tag, always_create=False,
> attrib=None):
>    1084         if isinstance(value, ResourceIdentifier):
> -> 1085             value = value.get_quakeml_uri()
>    1086         if always_create is False and value is None:
>    1087             return
>
> /Users/michelini/anaconda/lib/python2.7/site-packages/obspy/core/event/base.pyc
> in get_quakeml_uri(self, authority_id)
>     702         if result is None:
>     703             msg = "Failed to create a valid QuakeML
> ResourceIdentifier."
> --> 704             raise ValueError(msg)
>     705         return id
>     706
>
> ValueError: Failed to create a valid QuakeML ResourceIdentifier.
>
> In [17]:
>
> It seems that it has problems with the uri but I am not sure what the
> problem is. It is easily possible, however, to obtain the resource_id as
> usual by
>
> In [22]: cat.resource_id
> Out[22]:
> quakeml:https//earthquake.usgs.gov/fdsnws/event/1/query?minmagnitude=7.0&endtime=2011-01-01T00%3A00%3A00.000000&maxmagnitude=9.9&starttime=2010-01-01T00%3A00%3A00.000000
>
> In [23]: cat[0].resource_id
> Out[23]:
> quakeml:https//earthquake.usgs.gov/fdsnws/event/1/query?eventid=usp000hrw0&format=quakeml
>
>
> Can anybody help ?
>
> Ciao,
>
> Alberto
>
>
>
>
>
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> http://lists.swapbytes.de/mailman/listinfo/obspy-users
>
>
>
> _______________________________________________
> obspy-users mailing list
> obspy-users at lists.swapbytes.de
> http://lists.swapbytes.de/mailman/listinfo/obspy-users


More information about the obspy-users mailing list