PPSD not calculated for all files

Dear all,

I have problems to calculate PPSDs for specific files. I tried to process years of data and noticed missing data coverage even though mseed files are there and seem to be all right. It applies to about 2/3 of all my files.

When calculating a ppsd for a single file, it works. But not, if there are several of those 'suspicious' files. Below I've put my script and necessary data to reproduce an example with two days of mseed data.

When calling ppsd.add for the second file, it returns false without giving more information of what is wrong.

Does anyone know, what could be the problem with the mseeds and how to fix it?

Cheers
Tanja

Here's my script:

Hi Tanja,

that's a problem of your data. It has problems with the sampling rate, I
suspect that's coming from buggy data loggers. In one file the sampling
rate is 50.0000114441 and in the other it's 50.0000228882, so looks like
a precision problem to me (at least I hope your data logger

In PPSD the first data added is determining the expected sampling rate
for all following data, otherwise it would get much more complicated
internally.

If you're sure that all of your data is 50 Hz and that this is merely a
bug of the data logger writing wrong sampling rate to miniseed, than you
could do something like..

for tr in st:
    # just correct the wrong sampling rate, this is not doing resampling
    if abs(tr.stats.sampling_rate - 50) < 1e-3:
        tr.stats.sampling_rate = 50
ppsd.add(st)

cheers,
T

P.S.: see also https://github.com/obspy/obspy/pull/1849 for more warning
messages in cases like this one

Hi Tobias,

I've tried your suggestion, but then I got 'Exception: No data accumulated'. Even if I really do a resampling with tr.resample(50)

There seems to be more than just the sampling rate.

Cheers,
Tanja

Works for me..

Make sure to also set 50 as sampling rate for the stats object you use
to initialize the PPSD.. this is what determines the expected sampling
rate later on.

Also, like pointed out in the docs.. you should definitely use the
Parser object itself for the PPSD instead of the static PAZ, otherwise
you might get hurt by an instrument change.

cheers,
T

#!/usr/bin/env python3
import glob
from obspy import read
from obspy.io.xseed import Parser
from obspy.signal import PPSD

# Download files before
# wget -O VNA2.BHZ.2011.303.00.00.00
https://www.dropbox.com/s/4c6ifpowyjco7sm/VNA2.BHZ.2011.303.00.00.00?dl=0
# wget -O VNA2.BHZ.2011.304.00.00.00
https://www.dropbox.com/s/x0a8t4a8owd2n0t/VNA2.BHZ.2011.304.00.00.00?dl=0
# wget -O NM-all.dataless
https://www.dropbox.com/s/0rfeksdypijxp31/NM-all.dataless?dl=0

parser = Parser('NM-all.dataless')

# Read first mseed file
ppsd = None
for file_ in glob.glob('VNA2.BHZ.2011.*'):
    st = read(file_)
    print(st)
    for tr in st:
        if abs(tr.stats.sampling_rate - 50) > 1e-3:
            raise Exception('Sampling rate really difffers significantly
from 50Hz')
        tr.stats.sampling_rate = 50
    try:
        success = ppsd.add(st)
    except AttributeError:
        ppsd = PPSD(st[0].stats, parser)
        success = ppsd.add(st)
    print(success and "OK" or "Error")
ppsd.plot()