# Ppsd.plot\_temporal doesn't work

**URL:** https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846
**Category:** Usage Questions
**Created:** [December 5, 2023, 3:46am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846 "2023-12-05T03:46:27Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![tinyulin0000](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tinyulin0000/32/778_2.png) [@tinyulin0000](https://discourse.obspy.org/u/tinyulin0000)
#### Post date: [December 5, 2023, 3:46am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/1 "2023-12-05T03:46:28Z")

</div>

Here is my code:  
[https://drive.google.com/file/d/137x6BmLilntRax-4w8Depw9653xDaKbh/view?usp=sharing](https://drive.google.com/file/d/137x6BmLilntRax-4w8Depw9653xDaKbh/view?usp=sharing)

Here is my file:  
[https://drive.google.com/file/d/10bp\_I\_Vz6ngSbqZ8WryC\_USGVXUQrDMU/view?usp=sharing](https://drive.google.com/file/d/10bp_I_Vz6ngSbqZ8WryC_USGVXUQrDMU/view?usp=sharing)

My ppsd.plot\_temporal doesn’t work.  
Please help me.  
Thanks.

 ![output](https://discourse.obspy.org/uploads/default/original/1X/7159ef715df984f00d03090a79ad6ce03b73ff12.png)

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 12, 2023, 8:59am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/2 "2023-12-12T08:59:40Z")

</div>

Getting an error downloading that notebook

---

<div class="post-metadata">

### Author: ![tinyulin0000](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tinyulin0000/32/778_2.png) [@tinyulin0000](https://discourse.obspy.org/u/tinyulin0000)
#### Post date: [December 12, 2023, 9:42am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/3 "2023-12-12T09:42:12Z")

</div>

Here is my code.  
Please help me check what problem in my code, thank you.

from obspy import read, Stream  
from obspy.signal import PPSD

paz = {‘gain’: 1.,  
‘poles’: [-21.991+22.435j, -21.991-22.435j],  
‘sensitivity’: 257362500,  
‘zeros’: [0j, 0j]}

ppsd = None  
st = read(‘CL05.2020.199.0717.EHZ.sac’)  
ppsd = PPSD(st[0].stats, metadata=paz)  
ppsd.add(st)

ppsd.plot()  
ppsd.plot\_spectrogram()  
ppsd.plot\_temporal([0.1, 1, 10])

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 15, 2023, 8:57am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/4 "2023-12-15T08:57:15Z")

</div>

I don’t see any obvious problems there. Can you try `ppsd.add(st, verbose=True)` and what is the return value of that command, it should be `True` if data was added and processed properly.

---

<div class="post-metadata">

### Author: ![tinyulin0000](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tinyulin0000/32/778_2.png) [@tinyulin0000](https://discourse.obspy.org/u/tinyulin0000)
#### Post date: [December 18, 2023, 3:21am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/5 "2023-12-18T03:21:13Z")

</div>

![image](https://discourse.obspy.org/uploads/default/original/1X/3714662f379874cdc627504d6fc809acb7f9a404.png)

Yeah,It returned, I think data was added and processed.

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 18, 2023, 8:43am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/6 "2023-12-18T08:43:27Z")

</div>

Maybe the PSD values are just outside of the plotted range there? You can have a look at the underlying PSD data like this:

```python
from obspy.signal.tests.test_spectral_estimation import _get_ppsd
ppsd = _get_ppsd()

print(ppsd.psd_values)

```

---

<div class="post-metadata">

### Author: ![tinyulin0000](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tinyulin0000/32/778_2.png) [@tinyulin0000](https://discourse.obspy.org/u/tinyulin0000)
#### Post date: [December 18, 2023, 9:11am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/7 "2023-12-18T09:11:19Z")

</div>

![image](https://discourse.obspy.org/uploads/default/original/1X/91417c9c3497e0d13e090d8523fc076a003a59da.png)

Yeah, I got the psd values. How I know if the values outside of the plotted range?

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 18, 2023, 9:56am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/8 "2023-12-18T09:56:11Z")

</div>

Hmm they should be in the plot above, judging from the range. Can you upload the data somewhere else? Above links don’t work for me

---

<div class="post-metadata">

### Author: ![tinyulin0000](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tinyulin0000/32/778_2.png) [@tinyulin0000](https://discourse.obspy.org/u/tinyulin0000)
#### Post date: [December 19, 2023, 2:45am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/9 "2023-12-19T02:45:45Z")

</div>

No problem, this is my data file. Thanks.  
[https://drive.google.com/file/d/19aHwc8v65qiVOwYsklzZUeyjH3bcecaQ/view?usp=drive\_link](https://drive.google.com/file/d/19aHwc8v65qiVOwYsklzZUeyjH3bcecaQ/view?usp=drive_link)

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 20, 2023, 8:51pm UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/10 "2023-12-20T20:51:56Z")

</div>

This seems to be a bug, looks like the time step is not properly incremented and then every second time slice isn’t processed, and when plotting the temporal plot it recognises these gaps and the plot probably ends up with single dots plotted that can’t be seen. I’m looking at it..

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 21, 2023, 9:02am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/11 "2023-12-21T09:02:08Z")

</div>

Somehow the sample times in the stream experience some kind of subsample creep, which eventually makes the PPSD processing think that every second slice of the trace should not get processed because it overlaps with the segment before.  
It is pretty easy to fix in PPSD, even though I still need to double check if that fix causes issues elsewhere.

On the other hand, we need to look into how this happens in the first place because that is at the very core of obspy at the Trace level..

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 21, 2023, 9:16am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/12 "2023-12-21T09:16:15Z")

</div>

@tinyulin0000 see [Ppsd fix processing time info by megies · Pull Request #3387 · obspy/obspy · GitHub](https://github.com/obspy/obspy/pull/3387)

For a temporary solution you could make a new conda environment and install obspy from that branch of the pull request. I am still looking at where this problem is actually coming from, since it seems to come from core functionality

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 21, 2023, 9:43am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/13 "2023-12-21T09:43:16Z")

</div>

So, after chasing this issue for quite some time, turns out, the problem comes from how SAC is storing sampling rate information, it seems. See the linked obspy issue for more details.

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [December 21, 2023, 3:42pm UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/14 "2023-12-21T15:42:45Z")

</div>

@tinyulin0000 what you could do as a quick short term fix is to fix the sampling rate and get rid of the single-precision inaccuracy. Obviously, you need to take care that the sampling rate is what you expect it to be..

```python
st = read("...")
for tr in st:
    assert tr.stats.sampling_rate - 25.0 < 1e-5
    tr.stats.sampling_rate = 25.0
...
ppsd.add(st)

```

---

<div class="post-metadata">

### Author: ![tinyulin0000](https://discourse.obspy.org/user_avatar/discourse.obspy.org/tinyulin0000/32/778_2.png) [@tinyulin0000](https://discourse.obspy.org/u/tinyulin0000)
#### Post date: [December 22, 2023, 1:20am UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/15 "2023-12-22T01:20:15Z")

</div>

Sorry for the late reply and thank you very much !  
I also thought the problem result from my data file, but I didn’t know the detail problem.  
So I really appreciate your help very much!!!

---

<div class="post-metadata">

### Author: ![megies](https://discourse.obspy.org/user_avatar/discourse.obspy.org/megies/32/9_2.png) [@megies](https://discourse.obspy.org/u/megies)
#### Post date: [February 22, 2024, 3:04pm UTC](https://discourse.obspy.org/t/ppsd-plot-temporal-doesnt-work/1846/16 "2024-02-22T15:04:08Z")

</div>

see [SAC: Potential problem with floating point accuracy in sampling rate / sample spacing · Issue #3408 · obspy/obspy · GitHub](https://github.com/obspy/obspy/issues/3408)
