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.

  • CONTEXT:

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)

  • ENQUIRY:

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

trcopA=trA.copy()
trcopAtrim=trcopA.trim(endtime=negoriginA) #trimming of the "negative time half". NegoriginA is a UTC time value previously defined 

dataA=trcopAtrim.data
timeA= np.array(trcopAtrim.times()) #definition of X and Y arrays

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

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

fig=plt.figure(figsize=(15,5))
plt.plot(trcopAtrim)
plt.xlim(5001, 0) #reversal of x axis in the plot to get the mirror effect

any ideas?

THANK YOU :blush:
María.

Hello, welcome to the forum,

I think your suggested tr.data = tr.data[::-1] is the most intuitive and simple way to reverse data on the time axis. You could also use tr.data = np.flip(tr.data) 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

nst=read('COR_113A_GOGA.SAC')
ntr=nst[0]
ntr=ntr.copy()
ntrt=ntr.trim(endtime=negoriginA)
flipdata=np.flip(ntrt.data)
pst=Stream([Trace(data=flipdata, header=ntrt.stats)])
pst.write("test.sac", format='SAC')

Thank you,

María.

Glad you found the answer yourself.

1 Like