Reversing time series data of a trace ("Mirror effect"). Seismic noise correlations

Hello Everyone!

It’s María.

  • AIM:

I am trying to process “C3”, that is, correlations of codas of “C1” seismic noise correlations.


C1 correlations (my .SAC input files) are made of 2 halves regarding time concept, one which is causal (positive time serie) and another one which is non causal (negative time serie). The way ObsPy plots these is with an UTC time reference but that is all right.

For my task, I trim/split into two these C1, and I obtain my input codas, so that I have got a positive time coda and a negative time coda. This is now my enquiry: as well as I need to generate/write a .SAC file that contains the positive coda, I need to save the reversed time coda, but now changing the X axis data to a “clockwise” time sequence, that is, reversing the reversed time sequence of this coda (like in a mirror effect concerning the time axis)


Does anyone know if there is any sentence/command to directly reverse these time sequences? I mean, as it can be done, for example, with IRIS SAC software and its REVERSE command… If there is not such command, how could I make this to work out?

  • CODE:

I tried to reverse the time and amplitude arrays by myself, but I do not think this is the easiest way to proceed.

import numpy as np 

stA=read('COR_AMTX_ANMO.SAC') #an example C1 input file
trA=stA[0] #taking the first and only trace in the stream

trcopAtrim=trcopA.trim(endtime=negoriginA) #trimming of the "negative time half". NegoriginA is a UTC time value previously defined
timeA= np.array(trcopAtrim.times()) #definition of X and Y arrays

revdataA=dataA[::-1] #reversal of sequences for both time and amplitude

I also used Matplotlib to reverse the X axis and show how I want my traces to look like (but this is just a plot, my data are not modified so it is not very usefull)

import matplotlib.pyplot as plt

plt.xlim(5001, 0) #reversal of x axis in the plot to get the mirror effect

any ideas?

THANK YOU :blush:

Hello, welcome to the forum,

I think your suggested =[::-1] is the most intuitive and simple way to reverse data on the time axis. You could also use = np.flip( if you prefer. To plot data on a time axis without UTC reference check out the type and reftime options.

1 Like

Good evening, Tom, first: thanks for your time and attention!

Sadly, it seems I was not very clear with my request. I was attempting to save my already-flipped segments as new traces within a .SAC file. And for that I tried two different methods, firstly by reversing the time/amplitude arrays, and secondly by plotting the reversed times and trying to “convert this plot” into real data to keep them within a trace object (this was probably not even possible since matplotlib only represents data) Then, I was looking for a way or any command which could directly convert my sequences into new flipped traces and save them with same header but flipped time sequences instead.

Anyway, I am very glad that you expressed your opinion about the command and methods! Luckily, soon I figured out how to proceed and get what I wanted. It was more than simple.
I post the code here for whoever is interested.
I had a look at this: 18. Anything to MiniSEED — ObsPy Documentation (1.2.0)

import numpy as np
from obspy import Trace, Stream

pst=Stream([Trace(data=flipdata, header=ntrt.stats)])
pst.write("test.sac", format='SAC')

Thank you,


Glad you found the answer yourself.

1 Like