How to convert a number of timestamp objects, from PPSD, from a file at a time using ObsPy UTCDatetime() or any other way?

Hi there,

From the ppsd.plot_temporal([ ]) I can extract the PSD values of a central period bin as follows:

psds = ppsd.extract_psd_values(period=10)
I can also save the PSD values as follows:

fname = station + “.” + “txt”
np.savetxt(fname, np.c_[psds[0]])

I have been able to get the corresponding times this as follows:
time = ppsd.times_processed

Then I get the corresponding times as timestamp objects as follow:

fname = “time” + station + “.” + “txt”

And I save them in a file:

np.savetxt(fname, np.c_[psds[0]])

I tried converting these timestamp objects to hours using ObsPy UTCdatetime() as follows:

from obspy.core import UTCDateTime

psd_time = np.genfromtxt(“time_BRDL.txt”)

for i in psd_time:
time = UTCDateTime(i)

time.hour

The problem is that only one object is converted, and a single value is returned in this way. I also tried using Pandas and python datetime() function. All have the same issue that only one object can be processed at a time. Could anybody suggest me anyway for doing this using ObsPy or any other python way?

what do the contents of your output file with timestamps look like?

Hi @megies! thank you so much for your attention. I am copying the contents of the file with timestamps below:

1.395360000003000021e+09
1.395361800003000021e+09
1.395363600003000021e+09
1.395365400003000021e+09
1.395367200003000021e+09
1.395369000003000021e+09
1.395370800003000021e+09
1.395372600003000021e+09
1.395374400003000021e+09
1.395376200003000021e+09
1.395378000003000021e+09
1.395379800003000021e+09
1.395381600003000021e+09
1.395383400003000021e+09
1.395385200003000021e+09
1.395387000003000021e+09
1.395388800003000021e+09
1.395390600003000021e+09
1.395392400003000021e+09
1.395394200003000021e+09
1.395396000003000021e+09
1.395397800003000021e+09
1.395399600003000021e+09
1.395401400003000021e+09
1.395403200003000021e+09
1.395405000003000021e+09
1.395406800003000021e+09
1.395408600003000021e+09
1.395410400003000021e+09
1.395412200003000021e+09
1.395414000003000021e+09
1.395415800003000021e+09
1.395417600003000021e+09
1.395419400003000021e+09
1.395421200003000021e+09
1.395423000003000021e+09
1.395424800003000021e+09
1.395426600003000021e+09
1.395428400003000021e+09
1.395430200003000021e+09
1.395432000003000021e+09
1.395433800003000021e+09
1.395435600003000021e+09
1.395437400003000021e+09
1.395439200003000021e+09
1.395441000003000021e+09
1.395442800003000021e+09

I have done it simply:

from obspy.core import UTCDateTime
import numpy as np

data = np.genfromtxt(“timestamp_DHAK.txt”)

pt = np.array(data)

for t in pt:
t = t+1

time = UTCDateTime(t)

print(time)