get the information from Inventory

Hi All,

I wanna output station information to a file.
however, I stuck in a situation that I am not familiar with getting info from inventory.

I figured out how to get one by one.. however, I don't know how to get station numbers from inventory.

does any one an idea?

thanks!!

Patty

from obspy.fdsn import Client
from obspy import UTCDateTime

client = Client()
t1 = UTCDateTime("2010-01-12:T00:00:00.000")
t2 = UTCDateTime("2010-01-12:T23:59.59.000")

inv = client.get_stations(starttime=t1 , endtime=t2 , network="TA",
                           station="*", location="*", channel="BHZ",
                           level="response")
net = inv[0]
net
sta = net[0]
print(sta.code)
print(sta.latitude)
print(sta.longitude)

Hi Patty,

there are two kinds of coordinates in a StationXML file: Attached to the stations and attached to the channels. The following code snippet extracts both.

station_coordinates = []
channel_coordinates = []

for network in inv:
    for station in network:
        station_coordinates.append((network.code, station.code, station.latitude, station.longitude, station.elevation))
        for channel in station:
            channel_coordinates.append((network.code, station.code, channel.location_code, channel.code, channel.latitude, channel.longitude, channel.elevation, channel.depth))

Cheers!

Lion

Hi All,

thanks for Lion's help.. I am able to print out station information.

here comes another problem.
when obspy downloads data from iris.. even I check the data availability by adding includeavailability=True,
still few stations have no data available. spilling out the error messages from _download (in Private Methods)
"obspy.fdsn.header.FDSNException: No data available for request"

from obspy.fdsn import Client
from obspy import UTCDateTime

for example:

t1 = UTCDateTime("2010-01-12:T00:00:00.000")
t2 = UTCDateTime("2010-01-12:T23:59.59.000")

inv = client.get_stations(starttime=t1 , endtime=t2 , network="TA",
                           station="*", location="*", channel="BHZ", level="station",includerestricted=False,includeavailability=True)

station F04D is listed in inv.
however, if I try to download the data,

st=client.get_waveforms("TA", "F04D","*","BHZ",t1,t2)

it split out "obspy.fdsn.header.FDSNException: No data available for request."

and then Obspy stops downloading rest available data and quit...

is there a way I can keep getting data for rest available station?

Any info will help...

Thanks!!!

Cheers,
Patty

Hey Patty,

in Python you just catch the exception and keep going, e.g.:

for foo in bar:
    try:
       st = client.get_waveforms(…)
    except Exception as e:
       print e
       continue

You might want to be slightly more specific with which exception to catch but this should work in all cases. Note that this example also prints the exception so you see what went wrong.

Cheers!

Lion