StationXML

Dear all

I am trying to read Inventory XML file, that i downloaded from

http://eida.gfz-potsdam.de/webdc3/

"from obspy import read, read_inventory

inv = read_inventory(“KNDS.xml”)
print inv"

I get this error:

Traceback (most recent call last):
File “remove.py”, line 3, in
inv = read_inventory(“KNDS.xml”)
File “”, line 2, in read_inventory
File “/home/blaz/miniconda2/lib/python2.7/site-packages/obspy/core/util/decorator.py”, line 294, in _map_example_filename
return func(*args, **kwargs)
File “/home/blaz/miniconda2/lib/python2.7/site-packages/obspy/core/inventory/inventory.py”, line 72, in read_inventory
format=format)[0]
File “/home/blaz/miniconda2/lib/python2.7/site-packages/obspy/core/util/base.py”, line 444, in _read_from_plugin
raise TypeError(‘Unknown format for file %s’ % filename)
TypeError: Unknown format for file KNDS.xml

How do I read in XMLs from GFZ? I attached the file used to this email.
Thanks,
Blaž

KNDS.xml (38.2 KB)

Hi Bla�

Sorry to say you can't (afaik). Obspy can read FDSN station XML (see: http://www.fdsn.org/xml/station/), but what you've downloaded from geofon is inventory XML which is a different format (associated with the seiscomp software if I'm not misstaken).

What you can do instead is to down load the meta data in the Dataless SEED format and use obspy.io.xseed to read the file (see:https://docs.obspy.org/packages/obspy.io.xseed.html)

regP

Hi,

ObsPy 1.0.x can actually also read the seiscomp inventory format. Please
make sure you have the latest ObsPy version installed. If it still does
not work, please open an issue on Github with more details like the
exact used file (or send an email to this list if you don't have a
Github account and don't want to create one).

Please not that the GFZ also has a FDSN web service which serves
stationxml files. You can query it from within ObsPy as follows:

from obspy.clients.fdsn import Client
c = Client("GFZ")
inv = c.get_stations(...)

See the documentation of the get_station method for more details:

https://docs.obspy.org/packages/autogen/obspy.clients.fdsn.client.Client.get_stations.html

Cheers!

Lion

Great :slight_smile: ,

but more precisely which function to use, the only one I can find is a private function, _read_sc3ml<http://docs.obspy.org/packages/autogen/obspy.io.seiscomp.sc3ml._read_sc3ml.html#obspy.io.seiscomp.sc3ml._read_sc3ml>, in obspy.io.seiscomp.sc3ml (searching on http://docs.obspy.org). Is there a public function available as well?

Alsp, can obspy also write inventory XML files?

regP

Hi Peter,

Great :slight_smile: ,

but more precisely which function to use, the only one I can find is
a private function, _read_sc3ml [6], in obspy.io.seiscomp.sc3ml
(searching on http://docs.obspy.org [7]). Is there a public function
available as well?

Try:
from obspy import read, read_inventory
inv = read_inventory("sc3.xml", format="sc3ml")
print inv

Alsp, can obspy also write inventory XML files?

Maybe this one:
https://docs.obspy.org/master/packages/autogen/obspy.core.inventory.inventory.Inventory.write.html

So probably you could try the bellow code (I haven't tested it):
from obspy import read, read_inventory
inv = read_inventory("sc3.xml", format="sc3ml")
print inv
inv.write("new_sc3.xml", format="sc3ml")

Best Regards,
Nikos

Hi all,

the read_inventory() function should be able autodetect and parse the
inventory xml files. If not its a bug.

ObsPy currently cannot write Inventory XML files.

Cheers!

Lion

Hi Lion,

I wrote inventory to station xml format file.

inv.write('inventory.xml', format='stationxml')

Are you referring to another format of writing that is not supported yet?

Cu,
Nikos

Hi Nikos,

your example writes the inventory objects to a file in the StationXML
format. The seiscomp 3 Inventory XML is a slightly different format and

inv.write(..., format="inventoryxml")

is currently not implemented.

Cheers!

Lion

Hi Lion

Sorry for being anal, but given that others may look for the info in this thread, should the format be format="inventoryXML" or format="sc3ml" below both alternatives are used

regP

Hi Peter,

you are of course right. It should be format="sc3ml" as that is also
used for the read_inventory() function. As writing is currently not
implemented either will fail :wink:

For future readers: Note that the read_inventory() function should
auto-detect the format so specifying it is not necessary.

Cheers!

Lion

Hi,

AFAICS, (ArcLink) Inventory XML is not supported by read_inventory(). This is surprising for me, because obspy.clients.arclink.client.Client.get_inventory() actually works with this format. I suppose it would not be too difficult to refactor this code.

read_inventory() does seem to support the inventory part of Seiscomp3 XML aka SC3ML, which is the representation of complete SC3 data model (inventory, event parameters, etc) in XML format and is actually not supposed to be used as a universal exchange format (for exchange we have (ArcLink) InventoryXML, FDSN StationXML and QuakeML).

WebDC works on top of ArcLink, so it provides the (ArcLink) InventoryXML and Dataless formats. In SC3, one can convert InventoryXML to SC3ML easily:

$ seiscomp exec sccnv -i arclink:Package_1475048499259-GFZ_73152721_inventory.xml -o Package_1475048499259-GFZ_73152721_inventory.sc3.xml

However, SC3ML support in ObsPy still seems to be buggy:

from obspy import read_inventory
inv = read_inventory("Downloads/Package_1475048499259-GFZ_73152721_inventory.sc3.xml")

/usr/lib64/python2.7/site-packages/obspy-1.0.2.post0+dirty-py2.7-linux-x86_64.egg/obspy/io/seiscomp/sc3ml.py:590: UserWarning: Analogue responsePAZ not in inventory:None, stopping before stage 2
   warnings.warn(msg)

The file seems OK, because I can convert it to dataless without any warnings:

$ seiscomp exec inv2dlsv Package_1475048499259-GFZ_73152721_inventory.sc3.xml Package_1475048499259-GFZ_73152721_inventory.dlsv

BTW, I was going to suggest using Dataless as an alternative (supported by WebDC), but I'm unable to get a usable Inventory object from Dataless:

from obspy import read_inventory
inv = read_inventory("Package_1475048499259-GFZ_73152721_inventory.sc3.xml")
type(inv)

<class 'obspy.core.inventory.inventory.Inventory'>

from obspy.io.xseed import Parser
sp = Parser("Package_1475048499259-GFZ_73152721_inventory.dlsv")
inv = sp.get_inventory()
type(inv)

<type 'dict'>

Regards,
Andres.