Hi Andrew et al.,
I recently wrote a simple subroutine to do what I think you’re asking for; it outputs a sac response textfile from the response information contained within a channel object obtained by an IRIS waveform request through python using client.get_waveforms etc.
You can use the response-file writing tool in two ways: from the command line (slow) or within a python script that loops over channels/stations etc.
Let’s say you requested data within a python script, dowloaded an inventory object and then saved it:
Get the inventory of stations
inv = client.get_stations( network=net_dos,channel=chan_dos,level="response”)
Save IRIS inventory (inc. response files) as MYinventory.xml"
inv.write(dbdir+’MYinventory.xml’, format='STATIONXML’)
- You can run this tool from the command line, by giving the path to the inventory and the indices of the network, station and channel that you want (counting from zero - as a MATLAB person, I still feel like I have to specify this…)
For example, for the third channel for the second station in the first network, the usage from the command line is as follows:
write_sac_response_file.py MYinventory.xml name_of_response_file 0 1 2
where it’s hopefully obvious that the numbers are the indices of the network, station, and channel, respectively (see code for details).
This usage is pretty slow, because (depending on the size) the inventory file takes a long time to load.
- You can also call the subroutine within ipython, which will probably be a lot faster if you want to do this for several channels, because you only have to load the inventory file once, and the rest of the process takes a trivial amount of time. In this case your workflow would be something like:
In [1]: import write_sac_response_file
In [2]: from obspy import read_inventory
In [3]: inv = read_inventory(“MYinventory.xml”)
(here you could loop over networks/stations/channels, replacing the 0,1,2 by the appropriate indices in the line below - the slow loading of the inventory object need only be done once)
In [4]: write_sac_response_file.write_response(inv[0][1][2],”name_of_response_file",inv[0],inv[0][1])
again, see the code for details.
I’m a bit of a novice at both Obspy and python in general, so apologies if any of that is not clear, and I’m hoping that the community will point out any errors in the code (or this description of it!).
write_sac_response_file.py (5.1 KB)