Hi all,
I am curious if there is a convenient way to pop a trace from a stream object by station name.
This would be quite useful for multi channel analysis in case some channel data is missing.
From the documentation it seems stream.pop() works only for an index.
Is there any hidden feature to pop by a certain station name or do I have to loop through all my channels?
Thanks,
Martin
University of Tasmania Electronic Communications Policy (December, 2014).
This email is confidential, and is for the intended recipient only. Access, disclosure, copying, distribution, or reliance on any of it by anyone outside the intended recipient organisation is prohibited and may be a criminal offence. Please delete if obtained in error and email confirmation to the sender. The views expressed in this email are not necessarily the views of the University of Tasmania, unless clearly intended otherwise.
Hi Martin
No such thing, moreover pop generally pop's a single object whilst there might be multiple traces for a given station in the stream object. For a specific trace you can use:
stream.traces.pop([tr.id for tr in Stream.traces].index(trace_id))
If you want something more advanced, you can define a new function, e.g.
def popStation(self,station):
""" """
traces =
for i in range(len(self.traces)-1,-1,-1):
# note, that we traverse the traces list from the back to not mess up index when pop'ing an item
if self.traces[i].id.split('.')[1] == station:
traces.append(self.traces.pop(i))
return traces
and then bind it to the Stream object using:
import types
stream.popStation = types.MethodType(popTraces, stream)
Discalimer, I haven't actually tested the above so it is likely to contain a bug or two...
regP
Hi Martin,
The Stream object has a built-in method called select that should do what you want. It selects traces based on any keyword in the Stats dict and gives you a new stream:
https://docs.obspy.org/packages/autogen/obspy.core.stream.Stream.select.html
Emily
P.S. For example, I have a bunch of sacfiles from stations named SM17, SM18, SM19:
In [16]: st = obspy.read(‘SM1SAC’)
In [17]: st
Out[17]:
18 Trace(s) in Stream:
XI.SM17..BHE | 2011-07-01T00:00:00.000000Z - 2011-07-01T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM17..BHN | 2011-07-01T00:00:00.000000Z - 2011-07-01T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM17..BHZ | 2011-07-01T00:00:00.000000Z - 2011-07-01T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM18..BHE | 2011-07-01T00:00:00.005000Z - 2011-07-01T23:59:59.980000Z | 40.0 Hz, 3456000 samples
XI.SM18..BHN | 2011-07-01T00:00:00.005000Z - 2011-07-01T23:59:59.980000Z | 40.0 Hz, 3456000 samples
XI.SM18..BHZ | 2011-07-01T00:00:00.005000Z - 2011-07-01T23:59:59.980000Z | 40.0 Hz, 3456000 samples
XI.SM19..BHE | 2011-07-01T00:00:00.015000Z - 2011-07-01T23:59:59.990000Z | 40.0 Hz, 3456000 samples
XI.SM19..BHN | 2011-07-01T00:00:00.015000Z - 2011-07-01T23:59:59.990000Z | 40.0 Hz, 3456000 samples
XI.SM19..BHZ | 2011-07-01T00:00:00.015000Z - 2011-07-01T23:59:59.990000Z | 40.0 Hz, 3456000 samples
XI.SM17..BHE | 2011-07-02T00:00:00.000000Z - 2011-07-02T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM17..BHN | 2011-07-02T00:00:00.000000Z - 2011-07-02T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM17..BHZ | 2011-07-02T00:00:00.000000Z - 2011-07-02T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM18..BHE | 2011-07-02T00:00:00.005000Z - 2011-07-02T23:59:59.980000Z | 40.0 Hz, 3456000 samples
XI.SM18..BHN | 2011-07-02T00:00:00.005000Z - 2011-07-02T23:59:59.980000Z | 40.0 Hz, 3456000 samples
XI.SM18..BHZ | 2011-07-02T00:00:00.005000Z - 2011-07-02T23:59:59.980000Z | 40.0 Hz, 3456000 samples
XI.SM19..BHE | 2011-07-02T00:00:00.015000Z - 2011-07-02T23:59:59.990000Z | 40.0 Hz, 3456000 samples
XI.SM19..BHN | 2011-07-02T00:00:00.015000Z - 2011-07-02T23:59:59.990000Z | 40.0 Hz, 3456000 samples
XI.SM19..BHZ | 2011-07-02T00:00:00.015000Z - 2011-07-02T23:59:59.990000Z | 40.0 Hz, 3456000 samples
In [18]: st_small = st.select(station=‘SM17’, channel=‘BHZ’)
In [19]: st_small
Out[19]:
2 Trace(s) in Stream:
XI.SM17..BHZ | 2011-07-01T00:00:00.000000Z - 2011-07-01T23:59:59.975000Z | 40.0 Hz, 3456000 samples
XI.SM17..BHZ | 2011-07-02T00:00:00.000000Z - 2011-07-02T23:59:59.975000Z | 40.0 Hz, 3456000 samples