sort and plot by distance

Dear Obspy forum,

Is it possible to sort traces by sac header DIST? The goal is to plot
seismograms sorted by source-receiver distance.
The Obspy routine stream.sort does not have option to sort by distance, eg

Sorting can be done with some lines of code but I wonder if there is a
quick function in Obspy.


Hi Rodrigo,

I think the newest obspy supports sorting for arbitrary stats keys
(e.g. stream.sort(['distance']) but not nested inside the sac header.
Therefore, I'd suggest to use the underlying sort method of list (as
done by obspy itself), e.g.:
stream.traces.sort(key=lambda x: x.stats.sac.gcarc)


Hi Tom,

thanks for the suggestion, it works fine.